

def make_database(insert, path=None):
    if (path is not None):
        path = Path(path)
        if PY3:
            conn = sqlite3.connect(str(path))
        else:
            conn = sqlite3.connect(path.path)
    else:
        conn = sqlite3.connect('')
    conn.row_factory = sqlite3.Row
    conn.execute('\n        CREATE TABLE processes(\n            id INTEGER NOT NULL PRIMARY KEY,\n            run_id INTEGER NOT NULL,\n            parent INTEGER,\n            timestamp INTEGER NOT NULL,\n            is_thread BOOLEAN NOT NULL,\n            exitcode INTEGER\n            );\n        ')
    conn.execute('\n        CREATE INDEX proc_parent_idx ON processes(parent);\n        ')
    conn.execute('\n        CREATE TABLE opened_files(\n            id INTEGER NOT NULL PRIMARY KEY,\n            run_id INTEGER NOT NULL,\n            name TEXT NOT NULL,\n            timestamp INTEGER NOT NULL,\n            mode INTEGER NOT NULL,\n            is_directory BOOLEAN NOT NULL,\n            process INTEGER NOT NULL\n            );\n        ')
    conn.execute('\n        CREATE INDEX open_proc_idx ON opened_files(process);\n        ')
    conn.execute('\n        CREATE TABLE executed_files(\n            id INTEGER NOT NULL PRIMARY KEY,\n            name TEXT NOT NULL,\n            run_id INTEGER NOT NULL,\n            timestamp INTEGER NOT NULL,\n            process INTEGER NOT NULL,\n            argv TEXT NOT NULL,\n            envp TEXT NOT NULL,\n            workingdir TEXT NOT NULL\n            );\n        ')
    conn.execute('\n        CREATE INDEX exec_proc_idx ON executed_files(process);\n        ')
    for (timestamp, l) in enumerate(insert):
        if (l[0] == 'proc'):
            (ident, parent, is_thread) = l[1:]
            conn.execute('\n                INSERT INTO processes(id, run_id, parent, timestamp,\n                                      is_thread, exitcode)\n                VALUES(?, 0, ?, ?, ?, 0);\n                ', (ident, parent, timestamp, is_thread))
        elif (l[0] == 'open'):
            (process, name, is_dir, mode) = l[1:]
            conn.execute('\n                INSERT INTO opened_files(run_id, name, timestamp, mode,\n                                         is_directory, process)\n                VALUES(0, ?, ?, ?, ?, ?);\n                ', (name, timestamp, mode, is_dir, process))
        elif (l[0] == 'exec'):
            (process, name, wdir, argv) = l[1:]
            conn.execute('\n                INSERT INTO executed_files(run_id, name, timestamp,\n                                           process, argv, envp,\n                                           workingdir)\n                VALUES(0, ?, ?, ?, ?, "", ?);\n                ', (name, timestamp, process, argv, wdir))
        else:
            assert False
    conn.commit()
    return conn

dataset/ETHPy150Open ViDA-NYU/reprozip/tests/common.py make_database/original