Beispiel #1
0
def main():
    # TODO: check that yokadid is not already running for this database ? Not very harmful...
    # Set process name to "yokadid"
    setproctitle.setproctitle("yokadid")

    # Make the event list global to allow communication with main event loop
    global event

    defaultPidFile = os.path.join(basepaths.getRuntimeDir(), "yokadid.pid")
    defaultLogFile = os.path.join(basepaths.getLogDir(), "yokadid.log")
    args = parseOptions(defaultPidFile, defaultLogFile)

    if args.kill:
        killYokadid(args.pidFile)
        sys.exit(0)

    if args.pidFile == defaultPidFile:
        fileutils.createParentDirs(args.pidFile, mode=0o700)

    if args.logFile == defaultLogFile:
        fileutils.createParentDirs(args.logFile, mode=0o700)

    signal(SIGTERM, sigTermHandler)
    signal(SIGHUP, sigHupHandler)

    if args.restart:
        daemon = YokadiDaemon(args)
        daemon.restart()

    daemon = YokadiDaemon(args)
    if args.foreground:
        daemon.run()
    else:
        daemon.start()
Beispiel #2
0
def main():
    # TODO: check that yokadid is not already running for this database ? Not very harmful...
    # Set process name to "yokadid"
    setproctitle.setproctitle("yokadid")

    # Make the event list global to allow communication with main event loop
    global event

    defaultPidFile = os.path.join(basepaths.getRuntimeDir(), "yokadid.pid")
    defaultLogFile = os.path.join(basepaths.getLogDir(), "yokadid.log")
    args = parseOptions(defaultPidFile, defaultLogFile)

    if args.kill:
        killYokadid(args.pidFile)
        sys.exit(0)

    if args.pidFile == defaultPidFile:
        fileutils.createParentDirs(args.pidFile, mode=0o700)

    if args.logFile == defaultLogFile:
        fileutils.createParentDirs(args.logFile, mode=0o700)

    signal(SIGTERM, sigTermHandler)
    signal(SIGHUP, sigHupHandler)

    if args.restart:
        daemon = YokadiDaemon(args)
        daemon.restart()

    daemon = YokadiDaemon(args)
    if args.foreground:
        daemon.run()
    else:
        daemon.start()
Beispiel #3
0
def migrateOldDb(newDbPath):
    oldDbPath = os.path.normcase(os.path.expandvars("$HOME/.yokadi.db"))
    if not os.path.exists(oldDbPath):
        return

    if os.path.exists(newDbPath):
        raise MigrationException("Tried to move %s to %s, but %s already exists."
                                 " You must remove one of the two files." % (oldDbPath, newDbPath, newDbPath))
    fileutils.createParentDirs(newDbPath)
    shutil.move(oldDbPath, newDbPath)
    print("Moved %s to %s" % (oldDbPath, newDbPath))
Beispiel #4
0
 def writeHistory(self):
     """Writes shell history to disk"""
     try:
         fileutils.createParentDirs(self.historyPath)
         # Open r/w and close file to create one if needed
         historyFile = open(self.historyPath, "w", encoding='utf-8')
         historyFile.close()
         readline.set_history_length(1000)
         readline.write_history_file(self.historyPath)
     except Exception as e:
         tui.warning("Fail to save history to %s. Error was:\n\t%s" %
                     (self.historyPath, e))
Beispiel #5
0
def migrateOldHistory():
    oldHistoryPath = _getOldHistoryPath()
    if not os.path.exists(oldHistoryPath):
        return

    newHistoryPath = getHistoryPath()
    if os.path.exists(newHistoryPath):
        # History is not critical, just overwrite the new file
        os.unlink(newHistoryPath)
    fileutils.createParentDirs(newHistoryPath)
    shutil.move(oldHistoryPath, newHistoryPath)
    print("Moved %s to %s" % (oldHistoryPath, newHistoryPath))
Beispiel #6
0
def migrateOldHistory():
    oldHistoryPath = _getOldHistoryPath()
    if not os.path.exists(oldHistoryPath):
        return

    newHistoryPath = getHistoryPath()
    if os.path.exists(newHistoryPath):
        # History is not critical, just overwrite the new file
        os.unlink(newHistoryPath)
    fileutils.createParentDirs(newHistoryPath)
    shutil.move(oldHistoryPath, newHistoryPath)
    print("Moved %s to %s" % (oldHistoryPath, newHistoryPath))
Beispiel #7
0
 def writeHistory(self):
     """Writes shell history to disk"""
     try:
         fileutils.createParentDirs(self.historyPath)
         # Open r/w and close file to create one if needed
         historyFile = open(self.historyPath, "w", encoding='utf-8')
         historyFile.close()
         readline.set_history_length(1000)
         readline.write_history_file(self.historyPath)
     except Exception as e:
         tui.warning("Fail to save history to %s. Error was:\n\t%s"
                     % (self.historyPath, e))
Beispiel #8
0
def migrateOldDb():
    oldDbPath = os.path.normcase(os.path.expandvars("$HOME/.yokadi.db"))
    if not os.path.exists(oldDbPath):
        return

    newDbPath = getDbPath()
    if os.path.exists(newDbPath):
        raise MigrationException(
            "Tried to move %s to %s, but %s already exists. You must remove one of the two files."
            % (oldDbPath, newDbPath, newDbPath)
        )
    fileutils.createParentDirs(newDbPath)
    shutil.move(oldDbPath, newDbPath)
    print("Moved %s to %s" % (oldDbPath, newDbPath))
Beispiel #9
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