Beispiel #1
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()
Beispiel #2
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()
Beispiel #3
0
 def onecmd(self, line):
     """This method is subclassed just to be
     able to encapsulate it with a try/except bloc"""
     try:
         # Decode user input
         line = line
         return Cmd.onecmd(self, line)
     except YokadiOptionParserNormalExitException:
         pass
     except UnicodeDecodeError as e:
         tui.error("Unicode decoding error. Please check you locale and terminal settings (%s)." % e)
     except UnicodeEncodeError as e:
         tui.error("Unicode encoding error. Please check you locale and terminal settings (%s)." % e)
     except BadUsageException as e:
         tui.error("*** Bad usage ***\n\t%s" % e)
         cmd = line.split(' ')[0]
         self.do_help(cmd)
     except YokadiException as e:
         tui.error("*** Yokadi error ***\n\t%s" % e)
     except IOError as e:
         # We can get I/O errors when yokadi is piped onto another shell commands
         # that breaks.
         print("*** I/O error ***\n\t%s" % e, file=sys.stderr)
     except KeyboardInterrupt:
         print("*** Break ***")
     except Exception as e:
         tui.error("Unhandled exception (oups)\n\t%s" % e)
         print("This is a bug of Yokadi, sorry.")
         print("Send the above message by email to Yokadi developers ([email protected]) to help them make Yokadi better.")
         cut = "---------------------8<----------------------------------------------"
         print(cut)
         traceback.print_exc()
         print("--")
         print("Python: %s" % sys.version.replace("\n", " "))
         print("SQL Alchemy: %s" % sqlalchemy.__version__)
         print("OS: %s (%s)" % os.uname()[0:3:2])
         print("Yokadi: %s" % utils.currentVersion())
         print(cut)
         print()
Beispiel #4
0
            # that breaks.
            print >> sys.stderr, "*** I/O error ***\n\t%s" % e
        except KeyboardInterrupt:
            print "*** Break ***"
        except Exception, e:
            tui.error("Unhandled exception (oups)\n\t%s" % e)
            print "This is a bug of Yokadi, sorry."
            print "Send the above message by email to Yokadi developers ([email protected]) to help them make Yokadi better."
            cut = "---------------------8<----------------------------------------------"
            print cut
            traceback.print_exc()
            print "--"
            print "Python: %s" % sys.version.replace("\n", " ")
            print "SQLObject: %s" % sqlobjectVersion.replace("\n", " ")
            print "OS: %s (%s)" % os.uname()[0:3:2]
            print "Yokadi: %s" % utils.currentVersion()
            print cut
            print

    def loadHistory(self):
        """Tries to load previous history list from disk"""
        try:
            readline.read_history_file(self.historyPath)
        except Exception:
            # Cannot load any previous history. Start from a clear one
            pass

    def writeHistory(self):
        """Writes shell history to disk"""
        try:
            # Open r/w and close file to create one if needed
Beispiel #5
0
            # that breaks.
            print >> sys.stderr, "*** I/O error ***\n\t%s" % e
        except KeyboardInterrupt:
            print "*** Break ***"
        except Exception, e:
            tui.error("Unhandled exception (oups)\n\t%s" % e)
            print "This is a bug of Yokadi, sorry."
            print "Send the above message by email to Yokadi developers ([email protected]) to help them make Yokadi better."
            cut = "---------------------8<----------------------------------------------"
            print cut
            traceback.print_exc()
            print "--"
            print "Python: %s" % sys.version.replace("\n", " ")
            print "SQLObject: %s" % sqlobjectVersion.replace("\n", " ")
            print "OS: %s (%s)" % os.uname()[0:3:2]
            print "Yokadi: %s" % utils.currentVersion()
            print cut
            print

    def loadHistory(self):
        """Tries to load previous history list from disk"""
        try:
            readline.read_history_file(self.historyPath)
        except Exception:
            # Cannot load any previous history. Start from a clear one
            pass

    def writeHistory(self):
        """Writes shell history to disk"""
        try:
            # Open r/w and close file to create one if needed