示例#1
0
    def testMigrateOldHistory(self):
        old = Path(self.testHomeDir) / '.yokadi_history'
        new = Path(basepaths.getHistoryPath())

        old.touch()

        basepaths.migrateOldHistory()
        self.assertFalse(old.exists())
        self.assertTrue(new.exists())
示例#2
0
    def testMigrateOldHistory(self):
        old = Path(self.testHomeDir) / '.yokadi_history'
        new = Path(basepaths.getHistoryPath())

        old.touch()

        basepaths.migrateOldHistory()
        self.assertFalse(old.exists())
        self.assertTrue(new.exists())
示例#3
0
    def testMigrateOldHistoryOverwriteNew(self):
        old = Path(self.testHomeDir) / '.yokadi_history'
        new = Path(basepaths.getHistoryPath())

        with old.open('w') as f:
            f.write('old')
        new.parent.mkdir(parents=True)
        with new.open('w') as f:
            f.write('new')

        basepaths.migrateOldHistory()
        self.assertFalse(old.exists())
        with new.open() as f:
            newData = f.read()
        self.assertEqual(newData, 'old')
示例#4
0
    def testMigrateOldHistoryOverwriteNew(self):
        old = Path(self.testHomeDir) / '.yokadi_history'
        new = Path(basepaths.getHistoryPath())

        with old.open('w') as f:
            f.write('old')
        new.parent.mkdir(parents=True)
        with new.open('w') as f:
            f.write('new')

        basepaths.migrateOldHistory()
        self.assertFalse(old.exists())
        with new.open() as f:
            newData = f.read()
        self.assertEqual(newData, 'old')
示例#5
0
文件: main.py 项目: kotenev/yokadi
def main():
    locale.setlocale(locale.LC_ALL, os.environ.get("LANG", "C"))
    parser = createArgumentParser()
    args = parser.parse_args()
    dataDir, dbPath = commonargs.processArgs(args)

    basepaths.migrateOldHistory()
    try:
        basepaths.migrateOldDb(dbPath)
    except basepaths.MigrationException as exc:
        print(exc)
        return 1

    if args.update:
        return update.update(dbPath)

    try:
        db.connectDatabase(dbPath)
    except db.DbUserException as exc:
        print(exc)
        return 1

    if args.createOnly:
        return 0
    db.setDefaultConfig()  # Set default config parameters

    cmd = YokadiCmd()

    try:
        if len(args.cmd) > 0:
            print(" ".join(args.cmd))
            cmd.onecmd(" ".join(args.cmd))
        else:
            cmd.cmdloop()
    except KeyboardInterrupt:
        print("\n\tBreak ! (the nice way to quit is 'quit' or 'EOF' (ctrl-d)")
        return 1
    # Save history
    cmd.writeHistory()
    return 0
示例#6
0
文件: main.py 项目: agateau/yokadi
def main():
    locale.setlocale(locale.LC_ALL, os.environ.get("LANG", "C"))
    parser = createArgumentParser()
    args = parser.parse_args()
    dataDir, dbPath = commonargs.processArgs(args)

    basepaths.migrateOldHistory()
    try:
        basepaths.migrateOldDb(dbPath)
    except basepaths.MigrationException as exc:
        print(exc)
        return 1

    if args.update:
        return update.update(dbPath)

    try:
        db.connectDatabase(dbPath)
    except db.DbUserException as exc:
        print(exc)
        return 1

    if args.createOnly:
        return 0
    db.setDefaultConfig()  # Set default config parameters

    cmd = YokadiCmd()

    try:
        if len(args.cmd) > 0:
            print(" ".join(args.cmd))
            cmd.onecmd(" ".join(args.cmd))
        else:
            cmd.cmdloop()
    except KeyboardInterrupt:
        print("\n\tBreak ! (the nice way to quit is 'quit' or 'EOF' (ctrl-d)")
        return 1
    # Save history
    cmd.writeHistory()
    return 0
示例#7
0
 def testMigrateNothingToDo(self):
     newDb = Path(basepaths.getDbPath(basepaths.getDataDir()))
     basepaths.migrateOldDb(str(newDb))
     basepaths.migrateOldHistory()
     self.assertFalse(newDb.exists())
示例#8
0
 def testMigrateNothingToDo(self):
     newDb = Path(basepaths.getDbPath())
     basepaths.migrateOldDb()
     basepaths.migrateOldHistory()
     self.assertFalse(newDb.exists())
示例#9
0
文件: main.py 项目: semtle/yokadi
def main():
    locale.setlocale(locale.LC_ALL, os.environ.get("LANG", "C"))
    parser = ArgumentParser()

    parser.add_argument("-d",
                        "--db",
                        dest="filename",
                        help="TODO database (default: %s)" %
                        basepaths.getDbPath(),
                        metavar="FILE")

    parser.add_argument("-c",
                        "--create-only",
                        dest="createOnly",
                        default=False,
                        action="store_true",
                        help="Just create an empty database")

    parser.add_argument("-u",
                        "--update",
                        dest="update",
                        action="store_true",
                        help="Update database to the latest version")

    parser.add_argument("-v",
                        "--version",
                        dest="version",
                        action="store_true",
                        help="Display Yokadi current version")

    parser.add_argument('cmd', nargs='*')

    args = parser.parse_args()

    if args.version:
        print("Yokadi - %s" % yokadi.__version__)
        return 0

    basepaths.migrateOldHistory()
    try:
        basepaths.migrateOldDb()
    except basepaths.MigrationException as exc:
        print(exc)
        return 1

    if not args.filename:
        args.filename = basepaths.getDbPath()
        fileutils.createParentDirs(args.filename)

    if args.update:
        return update.update(args.filename)

    try:
        db.connectDatabase(args.filename)
    except db.DbUserException as exc:
        print(exc)
        return 1

    if args.createOnly:
        return 0
    db.setDefaultConfig()  # Set default config parameters

    cmd = YokadiCmd()

    try:
        if len(args.cmd) > 0:
            print(" ".join(args.cmd))
            cmd.onecmd(" ".join(args.cmd))
        else:
            cmd.cmdloop()
    except KeyboardInterrupt:
        print("\n\tBreak ! (the nice way to quit is 'quit' or 'EOF' (ctrl-d)")
        return 1
    # Save history
    cmd.writeHistory()
    return 0