Ejemplo n.º 1
0
Archivo: main.py Proyecto: bport/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",
                        metavar="FILE")

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

    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" % utils.currentVersion()
        return

    if not args.filename:
        # Look if user define an env VAR for yokadi db
        args.filename = os.getenv("YOKADI_DB")
        if args.filename:
            print "Using env defined database (%s)" % args.filename
        else:
            args.filename = os.path.normcase(
                os.path.expanduser("~/.yokadi.db"))
            print "Using default database (%s)" % args.filename

    db.connectDatabase(args.filename)

    if args.createOnly:
        return

    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)"
        sys.exit(1)
    # Save history
    cmd.writeHistory()
Ejemplo n.º 2
0
def clearDatabase():
    """
    Clear all tables of the database. Should be called in the setUp() method of
    the testcase. Useful to ensure unit-tests start from a blank state.
    """
    print "Cleaning database"
    for table in db.TABLE_LIST:
        table.dropTable()
    # Recreate database and default parameters
    db.connectDatabase("", memoryDatabase=True)
    db.setDefaultConfig()
Ejemplo n.º 3
0
def clearDatabase():
    """
    Clear all tables of the database. Should be called in the setUp() method of
    the testcase. Useful to ensure unit-tests start from a blank state.
    """
    print "Cleaning database"
    for table in db.TABLE_LIST:
        table.dropTable()
    # Recreate database and default parameters
    db.connectDatabase("", memoryDatabase=True)
    db.setDefaultConfig()
Ejemplo n.º 4
0
def main():
    locale.setlocale(locale.LC_ALL, os.environ.get("LANG", "C"))
    parser = ArgumentParser()

    parser.add_argument("-d", "--db", dest="filename",
                      help="TODO database", metavar="FILE")

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

    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" % utils.currentVersion())
        return

    if not args.filename:
        # Look if user define an env VAR for yokadi db
        args.filename = os.getenv("YOKADI_DB")
        if args.filename:
            print("Using env defined database (%s)" % args.filename)
        else:
            args.filename = os.path.normcase(os.path.expanduser("~/.yokadi.db"))
            print("Using default database (%s)" % args.filename)

    db.connectDatabase(args.filename)

    if args.createOnly:
        return
    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)")
        sys.exit(1)
    # Save history
    cmd.writeHistory()
Ejemplo n.º 5
0
def main():
    parser = ArgumentParser()
    parser.add_argument('db', metavar='<db>')
    args = parser.parse_args()

    dbname = args.db
    if os.path.exists(dbname):
        os.unlink(dbname)

    db.connectDatabase(dbname)
    db.setDefaultConfig()
    session = db.getSession()

    for name in PROJECTS:
        session.add(db.Project(name=name))

    for name in KEYWORDS:
        dbutils.getOrCreateKeyword(name, interactive=False)

    dbutils.addTask("birthday", "Buy food", {"grocery": None})
    dbutils.addTask("birthday", "Buy drinks", {"grocery": None})
    dbutils.addTask("birthday", "Invite Bob", {"phone": None})
    dbutils.addTask("birthday", "Invite Wendy", {"phone": None})
    dbutils.addTask("birthday", "Bake a yummy cake")
    dbutils.addTask("birthday", "Decorate living-room")

    task = dbutils.addTask("home", "Fix leak in the roof")
    task.dueDate = ydateutils.parseHumaneDateTime("-2d")

    dbutils.addTask("home", "Buy AAA batteries for kid toys",
                    {"grocery": None})

    task = dbutils.addTask("home", "Bring the car to the garage")
    task.dueDate = ydateutils.parseHumaneDateTime("-1d")
    task.status = "done"

    task = dbutils.addTask("work", "Finish weekly report")
    task.dueDate = ydateutils.parseHumaneDateTime("+4d")
    task.description = """Include results from Acme department: http://acme.intranet/results.
    Don't forget to CC [email protected].
    """

    session.commit()

    return 0
Ejemplo n.º 6
0
def main():
    parser = ArgumentParser()
    parser.add_argument('db', metavar='<db>')
    args = parser.parse_args()

    dbname = args.db
    if os.path.exists(dbname):
        os.unlink(dbname)

    db.connectDatabase(dbname)
    db.setDefaultConfig()
    session = db.getSession()

    for name in PROJECTS:
        session.add(db.Project(name=name))

    for name in KEYWORDS:
        dbutils.getOrCreateKeyword(name, interactive=False)

    dbutils.addTask("birthday", "Buy food", {"grocery": None})
    dbutils.addTask("birthday", "Buy drinks", {"grocery": None})
    dbutils.addTask("birthday", "Invite Bob", {"phone": None})
    dbutils.addTask("birthday", "Invite Wendy", {"phone": None})
    dbutils.addTask("birthday", "Bake a yummy cake")
    dbutils.addTask("birthday", "Decorate living-room")

    task = dbutils.addTask("home", "Fix leak in the roof")
    task.dueDate = ydateutils.parseHumaneDateTime("-2d")

    dbutils.addTask("home", "Buy AAA batteries for kid toys", {"grocery": None})

    task = dbutils.addTask("home", "Bring the car to the garage")
    task.dueDate = ydateutils.parseHumaneDateTime("-1d")
    task.status = "done"

    task = dbutils.addTask("work", "Finish weekly report")
    task.dueDate = ydateutils.parseHumaneDateTime("+4d")
    task.description = """Include results from Acme department: http://acme.intranet/results.
    Don't forget to CC [email protected].
    """

    session.commit()

    return 0
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
 def setUp(self):
     # Some help commands look into the db for default values
     db.connectDatabase("", memoryDatabase=True)
     db.setDefaultConfig()
Ejemplo n.º 10
0
 def setUp(self):
     db.connectDatabase("", memoryDatabase=True)
     setDefaultConfig()
     self.session = db.getSession()
Ejemplo n.º 11
0
 def setUp(self):
     db.connectDatabase("", memoryDatabase=True)
     setDefaultConfig()
     self.session = db.getSession()
     tui.clearInputAnswers()
Ejemplo n.º 12
0
 def setUp(self):
     # Some help commands look into the db for default values
     db.connectDatabase("", memoryDatabase=True)
     db.setDefaultConfig()
Ejemplo n.º 13
0
def main():
    db.connectDatabase("", memoryDatabase=True)
    db.setDefaultConfig()

    unittest.main()
Ejemplo n.º 14
0
def main():
    db.connectDatabase("", memoryDatabase=True)
    db.setDefaultConfig()

    unittest.main()
Ejemplo n.º 15
0
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