Overview
Comment: | import_html.py now outputs Luna LMS 0.1.9 format. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | tools |
Files: | files | file ages | folders |
SHA3-256: |
10de69136798ea02a9955d5d6662981d |
User & Date: | florian 2024-12-03 17:49:11 |
Context
2024-12-06
| ||
18:20 | Merged changes from documentation. check-in: 8571154b02 user: florian tags: tools | |
2024-12-04
| ||
13:43 | Merged changes from tools. check-in: 50f7e23cea user: florian tags: database | |
2024-12-03
| ||
17:49 | import_html.py now outputs Luna LMS 0.1.9 format. check-in: 10de691367 user: florian tags: tools | |
17:17 | Implemented sanitised primary keys in upgrade_db. check-in: 315e28dee5 user: florian tags: tools | |
Changes
Changes to tools/import_html.py.
︙ | ︙ | |||
18 19 20 21 22 23 24 | import idgen MAX_LEVEL = 4 """The maximum heading level that will be parsed as separate content. """ | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import idgen MAX_LEVEL = 4 """The maximum heading level that will be parsed as separate content. """ SUPPORTED_VERSION = "0.1.9" """The Luna LMS version number that the created file will conform to. """ class SQLiteConnect: connection = None cursor = None |
︙ | ︙ | |||
95 96 97 98 99 100 101 | LOGGER.debug("Generating tables") # Copied straight from the Luna LMS documentation result = SQLiteConnect.cursor.execute(''' CREATE TABLE "cache" ( | < | | > < | > > > > > > > > > | | > > > > > > > > > > > > < | | < | | < | | > > < | < < | < < | > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | LOGGER.debug("Generating tables") # Copied straight from the Luna LMS documentation result = SQLiteConnect.cursor.execute(''' CREATE TABLE "cache" ( "path" TEXT NOT NULL, "data" BLOB, "format" TEXT NOT NULL, "description" TEXT, PRIMARY KEY("path") ); ''') result.fetchone() result = SQLiteConnect.cursor.execute(''' CREATE TABLE "course" ( "identifier" TEXT NOT NULL, "title" TEXT NOT NULL, "description" TEXT NOT NULL, "relation" TEXT, "created" TEXT NOT NULL, "modified" TEXT NOT NULL, "dateAccepted" TEXT, "issued" TEXT, "contributor" TEXT NOT NULL, "requires" TEXT NOT NULL, PRIMARY KEY("identifier"), FOREIGN KEY("relation") REFERENCES "cache"("path") ON UPDATE CASCADE ON DELETE RESTRICT ); ''') result.fetchone() result = SQLiteConnect.cursor.execute(''' CREATE TABLE "formats" ( "identifier" TEXT, "sha256" TEXT, "publisher" TEXT NOT NULL, "media_type" TEXT NOT NULL, "language" TEXT, PRIMARY KEY("identifier") ); ''') result.fetchone() result = SQLiteConnect.cursor.execute(''' CREATE TABLE "tags" ( "identifier" TEXT, "title" TEXT NOT NULL, PRIMARY KEY("identifier") ); ''') result.fetchone() result = SQLiteConnect.cursor.execute(''' CREATE TABLE "tagging" ( "format_id" TEXT, "tag_id" TEXT, PRIMARY KEY("format_id", "tag_id"), FOREIGN KEY("tag_id") REFERENCES "tags"("identifier") ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY("format_id") REFERENCES "formats"("identifier") ON UPDATE CASCADE ON DELETE CASCADE ); ''') result.fetchone() result = SQLiteConnect.cursor.execute(''' CREATE TABLE "variants" ( "identifier" TEXT, "filename" TEXT NOT NULL, "isPartOf" TEXT, "data" BLOB, "format" TEXT NOT NULL, PRIMARY KEY("identifier"), FOREIGN KEY("format") REFERENCES "formats"("identifier") ON UPDATE CASCADE ON DELETE RESTRICT ); ''') result.fetchone() result = SQLiteConnect.cursor.execute(''' CREATE TABLE "contents" ( "identifier" TEXT, "title" TEXT NOT NULL, PRIMARY KEY("identifier") ); ''') result.fetchone() result = SQLiteConnect.cursor.execute(''' CREATE TABLE "steps" ( "identifier" TEXT, "content_id" TEXT, "successor" TEXT, "parent" TEXT, PRIMARY KEY("identifier"), FOREIGN KEY("content_id") REFERENCES "contents"("identifier") ON UPDATE CASCADE ON DELETE RESTRICT, FOREIGN KEY("parent") REFERENCES "steps"("identifier") ON UPDATE CASCADE ON DELETE RESTRICT, FOREIGN KEY("successor") REFERENCES "steps"("identifier") ON UPDATE CASCADE ON DELETE SET NULL ); ''') result.fetchone() result = SQLiteConnect.cursor.execute(''' CREATE TABLE "step_titles" ( "step_id" TEXT, "format" TEXT NOT NULL, "title" TEXT NOT NULL, PRIMARY KEY("step_id", "format"), FOREIGN KEY("step_id") REFERENCES "steps"("identifier") ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY("format") REFERENCES "formats"("identifier") ON UPDATE CASCADE ON DELETE RESTRICT ); ''') result.fetchone() result = SQLiteConnect.cursor.execute(''' CREATE TABLE "mapping" ( "content_id" TEXT, "variant_id" TEXT, PRIMARY KEY("content_id", "variant_id"), FOREIGN KEY("variant_id") REFERENCES "variants"("identifier") ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY("content_id") REFERENCES "contents"("identifier") ON UPDATE CASCADE ON DELETE CASCADE ); ''') result.fetchone() def write_formats_table(self): LOGGER.debug("Writing formats table") # Populate table with bare minimum standard values # result = SQLiteConnect.cursor.execute(''' INSERT INTO "formats" ( "identifier", "publisher", "media_type", "language", "sha256" ) VALUES ( 'luna.text.html.en', 'luna', 'text/html', 'en', '82b141764d5ea3957d1969894a15c3904321fcad0a33f1ed75aad78d71e23836' ), ( 'luna.text.html.de', 'luna', 'text/html', 'de', '49b429fc7f07a05e81a66dd215fc72ed9305751baa4ae7d8622eef81769be69b' ); ''') result.fetchone() SQLiteConnect.connection.commit() def write_tag_tables(self): LOGGER.debug("Writing tag tables") # Populate tables with bare minimum standard values result = SQLiteConnect.cursor.execute(''' INSERT INTO "tags" ( "identifier", "title" ) VALUES ( 'kg69qx', 'English' ); ''') result = SQLiteConnect.cursor.execute(''' INSERT INTO "tagging" ( "format_id", "tag_id" ) VALUES ( 'luna.text.html.en', 'kg69qx' ); ''') result.fetchone() SQLiteConnect.connection.commit() def write_course_table(self): |
︙ | ︙ | |||
318 319 320 321 322 323 324 325 326 327 328 329 330 331 | SQLiteConnect.connection = sqlite3.connect(db_filename) SQLiteConnect.cursor = SQLiteConnect.connection.cursor() result = SQLiteConnect.cursor.execute("PRAGMA foreign_keys = ON") self.generate_tables() self.write_formats_table() self.write_course_table() return CollectLevelState(2) return None | > > | 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | SQLiteConnect.connection = sqlite3.connect(db_filename) SQLiteConnect.cursor = SQLiteConnect.connection.cursor() result = SQLiteConnect.cursor.execute("PRAGMA foreign_keys = ON") self.generate_tables() self.write_formats_table() self.write_tag_tables() self.write_course_table() return CollectLevelState(2) return None |
︙ | ︙ |