Get an sqlite3 connection, and initialize the package database if necessary
()
| 16 | |
| 17 | |
| 18 | def init(): |
| 19 | """ |
| 20 | Get an sqlite3 connection, and initialize the package database if necessary |
| 21 | """ |
| 22 | if not os.path.exists(__opts__["spm_cache_dir"]): |
| 23 | log.debug("Creating SPM cache directory at %s", __opts__["spm_db"]) |
| 24 | os.makedirs(__opts__["spm_cache_dir"]) |
| 25 | |
| 26 | if not os.path.exists(__opts__["spm_db"]): |
| 27 | log.debug("Creating new package database at %s", __opts__["spm_db"]) |
| 28 | |
| 29 | sqlite3.enable_callback_tracebacks(True) |
| 30 | conn = sqlite3.connect(__opts__["spm_db"], isolation_level=None) |
| 31 | |
| 32 | try: |
| 33 | conn.execute("SELECT count(*) FROM packages") |
| 34 | except OperationalError: |
| 35 | conn.execute( |
| 36 | """CREATE TABLE packages ( |
| 37 | package text, |
| 38 | version text, |
| 39 | release text, |
| 40 | installed text, |
| 41 | os text, |
| 42 | os_family text, |
| 43 | dependencies text, |
| 44 | os_dependencies text, |
| 45 | os_family_dependencies text, |
| 46 | summary text, |
| 47 | description text |
| 48 | )""" |
| 49 | ) |
| 50 | |
| 51 | try: |
| 52 | conn.execute("SELECT count(*) FROM files") |
| 53 | except OperationalError: |
| 54 | conn.execute( |
| 55 | """CREATE TABLE files ( |
| 56 | package text, |
| 57 | path text, |
| 58 | size real, |
| 59 | mode text, |
| 60 | sum text, |
| 61 | major text, |
| 62 | minor text, |
| 63 | linkname text, |
| 64 | linkpath text, |
| 65 | uname text, |
| 66 | gname text, |
| 67 | mtime text |
| 68 | )""" |
| 69 | ) |
| 70 | |
| 71 | return conn |
| 72 | |
| 73 | |
| 74 | def info(package, conn=None): |
no test coverage detected