当前位置: 首页>>代码示例>>Python>>正文


Python Term.execute方法代码示例

本文整理汇总了Python中term.Term.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Term.execute方法的具体用法?Python Term.execute怎么用?Python Term.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在term.Term的用法示例。


在下文中一共展示了Term.execute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from term import Term [as 别名]
# 或者: from term.Term import execute [as 别名]
def main(argv):
    target_url = ''
    COMMAND = ''
    ALL = False
    AUTH = False
    DATASOURCE = False
    TERM = False
    COURSE = False
    USER = False
    MEMBERSHIP = False
    CLEANUP = False

    datasource_PK1 = None

    usageStr = "\nrestdemo.py -t|--target <target root URL> -c|--command <command>\n"
    usageStr += "e.g restdemo.py -t www.myschool.edu -c create_course\n"
    usageStr += "command: <command>_<object> where <command> is one of the following:\n"
    usageStr += "\tcreate, read, read_all, update, delete\n"
    usageStr += "and <object> is one of the following:\n"
    usageStr += "\tdatasource, term, course, user, membership\n"
    usageStr += "-t is required; No -c args will run demo in predetermined order.\n"
    usageStr += "'-c authorize' demomonstrates the authorization process and does not create objects."
    usageStr += "-c commands require a valid datasource PK1 - \n"
    usageStr += "\ta datasource get will be run in these cases, defaulting to create\n"
    usageStr += "\tif the demo datasource does not exist."

    if len(sys.argv) > 1: #there are command line arguments
        try:
            opts, args = getopt.getopt(argv,"ht:c:",["target=","command="])
        except getopt.GetoptError:
            print (usageStr)
            sys.exit(2)
        for opt, arg in opts:
            if opt == '-h':
                print (usageStr)
                sys.exit()
            elif opt == '-d':
                print ("Deleting at end of run.")
                CLEANUP = True
            elif opt in ("-t", "--target"):
                target_url = arg.lstrip()
            elif opt in ("-c", "--command"):
                COMMAND = arg
            else:
                COMMAND = "Run All"
        print ('[main] Target is:', target_url)
        print ('[main] Command is:', COMMAND)


    else:
        print(usageStr)
        sys.exit(2)


    #Set up some booleans for processing flags and order of processing
    if "course" in COMMAND:
        print("[main] Run course command")
        COURSE = True
    elif "user" in COMMAND:
        print("[main] Run user command")
        USER = True
    elif "membership" in COMMAND:
        print("[main] Run membership command")
        MEMBERSHIP = True
    elif "term" in COMMAND:
        print("[main] Run term command")
        TERM = True
    elif "datasource" in COMMAND:
        print("[main] Run datasource command")
        DATASOURCE = True
    elif "authorize" in COMMAND:
        print("[main] Run authorization command")
        AUTH = True
    else:
        print("[main] Empty Command: Run All\n")
        ALL = True


    print ('\n[main] Acquiring auth token...\n')
    authorized_session = AuthToken(target_url)
    authorized_session.setToken()
    print ('\n[main] Returned token: ' + authorized_session.getToken() + '\n')

    if not AUTH:
        #run commands in required order if running ALL
        if DATASOURCE or ALL:
            #process Datasource command
            print("\n[main] Run datasource command: " + ('ALL' if ALL else COMMAND) + '...')
            datasource_session = DataSource(target_url, authorized_session.getToken())
            if 'datasource' in COMMAND:
                datasource_session.execute(COMMAND, authorized_session.getToken())
            else:
                #datasource_session.getDataSources(authorized_session.getToken())
                datasource_session.createDataSource(authorized_session.getToken())
                datasource_PK1 = datasource_session.datasource_PK1
                print("[main] datasource_PK1: " + datasource_PK1)
                datasource_session.getDataSource(authorized_session.getToken())
                datasource_session.updateDataSource(authorized_session.getToken())


#.........这里部分代码省略.........
开发者ID:hanleybrand,项目名称:BBDN-REST-DEMO_Python,代码行数:103,代码来源:restdemo.py


注:本文中的term.Term.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。