コード例 #1
0
def main(argv):
    """ Main command line prog for pod """
    try:
        opts, _ = getopt.getopt(argv[1:], "hvs:l:",
                                ["help", "version", "source=", "load="])
    except getopt.GetoptError as error:
        print(error)
        usage()
        sys.exit(2)
    options = [arg[0] for arg in opts]

    if "help" in options or "-h" in options:
        usage()
        sys.exit(0)

    if "version" in options or "-v" in options:
        print("Peripherals On Demand version " + VERSION)
        sys.exit(0)

    cli = ProjectCli()
    SETTINGS.projectpath = sy.pwd()
    SETTINGS.version = VERSION

    # load command file if in command params
    if "--source" in options or "-s" in options:
        for opt, arg in opts:
            if opt == "--source" or opt == "-s":
                argument = arg
                break
        if not os.path.exists(argument):
            print("[ERROR] script " + argument + " doesn't exist")
            usage()
            return
        cli.do_source(argument)
    elif "--load" in options or "-l" in options:
        for opt, arg in opts:
            if opt == "--load" or opt == "-l":
                argument = arg.strip('/')
                break
            if not os.path.exists(argument):
                print("[ERROR] project " + argument + " doesn't exist")
                usage()
                return

        tmpfile = open(TMPFILENAME, "w")
        tmpfile.write("load " + argument)
        tmpfile.close()
        print("Loading project " + argument + " :\n")
        cli.do_source(TMPFILENAME)

    # infinite command loop
    cli.cmdloop()
コード例 #2
0
ファイル: pod.py プロジェクト: Martoni/periphondemand
def main(argv):
    """ Main command line prog for pod """
    try:
        opts, _ = getopt.getopt(argv[1:], "hvs:l:", ["help",
                                                     "version",
                                                     "source=",
                                                     "load="])
    except getopt.GetoptError as error:
        print(error)
        usage()
        sys.exit(2)
    options = [arg[0] for arg in opts]

    if "help" in options or "-h" in options:
        usage()
        sys.exit(0)

    if "version" in options or "-v" in options:
        print("Peripherals On Demand version " + VERSION)
        sys.exit(0)

    cli = ProjectCli()
    SETTINGS.projectpath = sy.pwd()
    SETTINGS.version = VERSION

    # load command file if in command params
    if "--source" in options or "-s" in options:
        for opt, arg in opts:
            if opt == "--source" or opt == "-s":
                argument = arg
                break
        if not os.path.exists(argument):
            print("[ERROR] script " + argument + " doesn't exist")
            usage()
            return
        cli.do_source(argument)
    elif "--load" in options or "-l" in options:
        for opt, arg in opts:
            if opt == "--load" or opt == "-l":
                argument = arg.strip('/')
                break
            if not os.path.exists(argument):
                print("[ERROR] project " + argument +
                      " doesn't exist")
                usage()
                return

        tmpfile = open(TMPFILENAME, "w")
        tmpfile.write("load " + argument)
        tmpfile.close()
        print("Loading project " + argument + " :\n")
        cli.do_source(TMPFILENAME)

    # infinite command loop
    cli.cmdloop()
コード例 #3
0
ファイル: cli.py プロジェクト: xcthulhu/periphondemand
    def do_project(self,arg):
       """\
Usage : project
Project management commands
       """
       cli = ProjectCli(self)
       if not settings.active_project.isVoid():
           cli.setPrompt("project:"+settings.active_project.getName())
       else:
           cli.setPrompt("project")
       arg = str(arg)
       if len(arg) > 0:
           line = cli.precmd(arg)
           cli.onecmd(line)
           cli.postcmd(True, line)
       else:
           cli.cmdloop()
           self.stdout.write("\n")