當前位置: 首頁>>代碼示例>>Python>>正文


Python Course.execute方法代碼示例

本文整理匯總了Python中course.Course.execute方法的典型用法代碼示例。如果您正苦於以下問題:Python Course.execute方法的具體用法?Python Course.execute怎麽用?Python Course.execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在course.Course的用法示例。


在下文中一共展示了Course.execute方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from course import Course [as 別名]
# 或者: from course.Course 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


注:本文中的course.Course.execute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。