本文整理汇总了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())
#.........这里部分代码省略.........