Esempio n. 1
0
    def test_serialization(self):
        obj = Database("/tmp/foo", DatabaseVersion(), Schema(), [])
        self.assertEqual(obj.serialization(),
                         DatabaseVersion(0).serialization())

        obj = Database("/tmp/foo", DatabaseVersion.preferred(), Schema(), [])
        self.assertEqual(obj.serialization(),
                         DatabaseVersion.preferred().serialization())
Esempio n. 2
0
 def test_version(self):
     tdb = TemporaryDatabase()
     self.assertEqual(Database.read_version(tdb.ddir.name),
                      DatabaseVersion())
     tdb.db.store()
     tdb.db.upgrade()
     self.assertEqual(Database.read_version(tdb.ddir.name),
                      DatabaseVersion.preferred())
Esempio n. 3
0
def parse_args(args):
    confhome = os.environ.get('XDG_CONFIG_HOME',
                              os.path.expanduser('~/.config'))
    conf = '%s/newfol/defaults' % confhome
    parser = argparse.ArgumentParser(description=_("store and manipulate fol"))
    parser.add_argument("--import", dest="cmd", action="store_const",
                        const="import", help=_("import a table"))
    parser.add_argument("--test", dest="cmd", action="store_const",
                        const="test", help=_("test this program"))
    parser.add_argument("--version", dest="cmd", action="store_const",
                        const="version",
                        help=_("print newfol and database versions"))
    parser.add_argument("--validate", dest="cmd", action="store_const",
                        const="validate", help=_("validate the database"))
    parser.add_argument("--repair", dest="cmd", action="store_const",
                        const="repair",
                        help=_("repair the database automatically"))
    parser.add_argument("--export", "--extract", dest="cmd",
                        action="store_const", const="export",
                        help=_("export a table"))
    parser.add_argument("--dbname", dest="dbname", action="store",
                        help=_("table name (obsolescent)"))
    parser.add_argument("--table", dest="table", action="store",
                        help=_("table name"))
    parser.add_argument("--upgrade", dest="cmd", action="store_const",
                        const="upgrade", help=_("upgrade data files"))
    parser.add_argument("--strict", dest="strict", action="store_true",
                        help=_("enable strict checking"))
    parser.add_argument("--identity", dest="identity", action="store_true",
                        help=_("use identity mapping when importing"))
    parser.add_argument("--curses", dest="cmd", action="store_const",
                        const="curses", help=_("start the curses interface"))
    parser.add_argument("--homedir", dest="homedir", action="store",
                        default=os.path.expanduser("~/.newfol"),
                        help=_("specify the location of database files"))
    parser.add_argument("--minfields", dest="minfields", action="store",
                        type=int, default=0,
                        help=_("minimum number of fields per record"))
    parser.add_argument("--txntype", dest="txntype", action="append",
                        default=None, help=_("type of transactional helper"))
    parser.add_argument("--from-txntype", dest="from_txntype", action="append",
                        default=None,
                        help=_("current type of transactional helper"))
    parser.add_argument("--dbtype", dest="dbtype", action="store",
                        default="csv", help="type of data for import/export")
    parser.add_argument('--no-config', dest='config', action='store_const',
                        const=[], default=[conf],
                        help=_('do not load the configuration file %s') % conf)
    parser.add_argument("--upgrade-version", dest="upgrade_version",
                        action="store", default=DatabaseVersion.preferred(),
                        type=int,
                        help=_("version of database to upgrade to (advanced)"))
    argobj = parser.parse_args(args)
    if argobj.cmd is None:
        argobj.cmd = "curses"
    return argobj
Esempio n. 4
0
def print_version(db):
    print("newfol " + __version__)
    if db is None:
        print("No database loaded.")
    else:
        txntypes = db.schema().transaction_types()
        ver = db.version()
        dump_database_information(txntypes, ver)

    default_txns = filemanip.FileStorage.DEFAULT_TRANSACTION_TYPES
    dump_database_information(default_txns, DatabaseVersion.preferred(),
                              "Default ")
    print()
    print("Supported Serialization Types: " + ", ".
          join(DatabaseVersion.serialization_types()))
    print("Supported Compression Types: " + ", ".
          join([str(x) for x in DatabaseVersion.compression_types()]))
    print('Supported Transaction Types: ' + ', '.
          join(newfol.filemanip.FileStorage.transaction_types()))
Esempio n. 5
0
    def test_version(self):
        obj = Database("/tmp/foo", DatabaseVersion(), Schema(), [])
        self.assertEqual(obj.version(), 0)

        obj = Database("/tmp/foo", DatabaseVersion.preferred(), Schema(), [])
        self.assertEqual(obj.version(), DatabaseVersion.preferred())
Esempio n. 6
0
 def test_preferred_version_version(self):
     self.assertEqual(DatabaseVersion.preferred().version_version(), 0)
Esempio n. 7
0
 def test_preferred_record_version(self):
     self.assertEqual(DatabaseVersion.preferred().record_version(), 3)
Esempio n. 8
0
 def test_preferred_compression(self):
     self.assertEqual(DatabaseVersion.preferred().compression(), None)
Esempio n. 9
0
 def test_preferred_serialization_version(self):
     self.assertEqual(DatabaseVersion.preferred().serialization_version(),
                      2)
Esempio n. 10
0
 def test_upgrade_to_pickle(self):
     version = (DatabaseVersion.preferred() & ~0x0000ff00) | 0x00000100
     self.do_upgrade_test(version, b"(lp0\n")
Esempio n. 11
0
 def test_upgrade_to_json(self):
     version = (DatabaseVersion.preferred() & ~0x0000ff00) | 0x00000200
     self.do_upgrade_test(version, b"[")
Esempio n. 12
0
 def test_upgrade_to_xz(self):
     version = (DatabaseVersion.preferred() & ~0x00ff0000) | 0x00010000
     self.do_upgrade_test(version, b"\xfd7zXZ\x00")
Esempio n. 13
0
def ensure_db_dir(path):
    if not os.path.exists(path):
        os.mkdir(path, 0o700)
        with open(path + "/version", "w") as fp:
            fp.write("%d\n" % int(DatabaseVersion.preferred()))