def get_search_options(): driver = utils.start_driver('chrome') home_dir = str(pathlib.Path.home()) session.login(driver, home_dir + '/plst.credential.json') utils.wait(3) filt_name_dict = { 'level': 'SKILL LEVELS', 'role': 'ROLES', 'subject': 'SUBJECTS TO LEARN', 'tool': 'TOOLS', 'cert': 'CERTIFICATIONS', 'author': 'AUTHORS', } try: for filt, filt_name in sorted(filt_name_dict.items()): opt_url_dict = search.get_filter_options_url(driver, filt_name) utils.save_json(opt_url_dict, 'search/filt_{}_urls.json'.format(filt)) utils.wait(10) finally: session.logout(driver) utils.wait(3) utils.close_driver(driver)
def get_course_videos(course_list, ncourse_max): cache_dir = 'cache' driver = utils.start_driver('chrome', download_dir=cache_dir) home_dir = str(pathlib.Path.home()) session.login(driver, home_dir + '/plst.credential.json') utils.wait(3) try: ncourse = 0 for line in open(course_list): if line.startswith('#'): continue course_id = line.rstrip() video_list, nmodule, nclip = load_course_video_list(course_id) nvideo = len(video_list) out_dir = 'courses/{}/videos'.format(course_id) os.makedirs(out_dir, exist_ok=True) if count_videos(out_dir) == nvideo: continue utils.print_message('get video of "{}" ({}/{}): {} modules and ' '{} clips'.format(course_id, ncourse + 1, ncourse_max, nmodule, nclip)) for module_id, clip_id, clip_url in video_list: video_url = course.get_video_url(driver, clip_url) video_basename = video_url.split('?')[0].split('/')[-1] video_name = '{}/{}.{}.{}'.format(out_dir, module_id, clip_id, video_basename) utils.download_file(video_url, video_name, verbose=True) ndownload = count_videos(out_dir) if ndownload != nvideo: utils.print_message('*ERROR*: course "{}", expected {} clips, ' 'downloaded {}'.format( course_id, nvideo, ndownload)) raise ncourse += 1 utils.print_message( '----------------------------------------------') utils.wait(3) if ncourse == ncourse_max: break finally: session.logout(driver) utils.wait(3) utils.close_driver(driver)
def test_login(): session.clear() clear_test_user() user = ctrl_user_manager.register("ycat","passwtest",sex_type.Male,23) utility.check_log(user.user_id,"注册成功",1,0) utility.check_log(user.user_id,"登陆成功",1,1) user = ctrl_user_manager.register("ycat2","passwtest",sex_type.Female,35) utility.check_log(user.user_id,"注册成功",1,0) utility.check_log(user.user_id,"登陆成功",1,1) assert 2 == len(session.g_session_data) assert not session.login("noexit","passwtest") utility.check_log(-1,"noexit登陆失败",0) user = session.login("ycat","passwtest") #utility.check_log(user.user_id,"登陆成功",1) ycatID = user.session_id utility.set_session_id(user.session_id) assert user assert user == session.get() assert user.sex == 1 assert user.nickname == "ycat" assert user.user_id != 0 assert 23 == user.age assert user.certf_state == 0 #session.clear() user = session.login("ycat2","passwtest") utility.set_session_id(user.session_id) assert user assert user.sex == 0 assert user.nickname == "ycat2" assert user.user_id != 0 assert user.certf_state == 0 assert user == session.get() assert 2 == len(session.g_session_data) session.logout() assert not session.get() assert 1 == len(session.g_session_data) assert session.g_session_data[ycatID].session_id == ycatID assert 35 == user.age for i in range(10): assert session._is_repeat_login("ycat","passwtest") assert not session._is_repeat_login("ycat","passwtest_wrong") assert session.login("ycat","passwtest") #repeat login but session keep same assert 1 == len(session.g_session_data) session.clear(); clear_test_user()
def get_search_option_courses(): driver = utils.start_driver('chrome') home_dir = str(pathlib.Path.home()) session.login(driver, home_dir + '/plst.credential.json') utils.wait(3) filt_name_dict = { 'role': 'ROLES', 'subject': 'SUBJECTS TO LEARN', 'tool': 'TOOLS', 'cert': 'CERTIFICATIONS', # 'level': 'SKILL LEVELS', # 'author': 'AUTHORS', } try: for filt, filt_name in sorted(filt_name_dict.items()): opt_url_dict = utils.load_json( 'search/filt_{}_urls.json'.format(filt)) out_dir = 'search/filt_{}_courses'.format(filt) os.makedirs(out_dir, exist_ok=True) opt_index = 0 nopt = len(opt_url_dict) for opt, url in sorted(opt_url_dict.items()): opt_index += 1 fname_json = '{}/{}.json'.format(out_dir, opt_index) if os.path.isfile(fname_json): continue # if opt_index >= 10: # break utils.print_message( 'get all courses with filt={}, option={} ({}/{})'.format( filt, opt, opt_index, nopt)) course_id_list = search.get_all_courses_per_option( driver, url, wait_time=10) opt_courses_dict = {opt: course_id_list} utils.save_json(opt_courses_dict, fname_json) utils.wait(20) finally: session.logout(driver) utils.wait(3) utils.close_driver(driver)
def test_user_age(): test_user_manager.clear_test_user() now = datetime.datetime(2014,5,27,12,50,43) utility.set_now(now) assert utility.now() == now s = web_register.ctrl_user_manager.register("ycattest","123test",web_register.sex_type.Male,35) utility.set_session_id(s.session_id) assert session.get().age == 35 session.logout() utility.set_now(datetime.datetime(2015,5,27,12,50,43)) s = session.login("ycattest","123test") assert s.age == 36 test_user_manager.clear_test_user() utility.set_now(None)
def run(self): # login each session for session in self.sessions.itervalues(): session.login() self.userQueue.get() self.userQueue.task_done() # loop for sessions to keep connect while not self.threadStop: time.sleep(1) self.intCnt += 1 if self.intCnt == self.interval: self.intCnt = 0 for session in self.sessions.itervalues(): session.keep_connect() # stop and logout for session in self.sessions.itervalues(): session.logout() self.sessions.clear()
def logoutpage(): """ logoutpage() Calls the logout() function in functions.py and then redirects to the login page. In case of failure it must redirect the user on the mainpage with an error message (not implemented yet) """ if logout() == 0: mappa = {"msg" : "Logout successfully"} template = env.get_template("login.html") return template.render(mappa) template = env.get_template("login.html") mappa["msg"] = "There was a problem during the logout process. Try login and logout again (if necessary)." mappa["error"] = "TRUE" return template.render(mappa)
def main(argv): if len(argv) < 1 or len(argv) > 2: usage() sys.exit(2) dataconn_path = argv[0] obj_id = dataconn_path[len(settings.get_setting('DATACONN_URL')):] rem_obj = "/" in obj_id if len(argv) == 2: if rem_obj: usage() sys.exit(2) query = '?query=' + argv[1] else: if rem_obj: query = '' else: query = '?query=' session_id = session.login() print url = settings.get_setting('BASE_URL') + dataconn_path + query response = requests.get(url, headers=session.get_session_hdr(session_id)) if response.status_code == 404: print "object not found" else: if rem_obj: print_objinfo([response.json()]) else: query_results = response.json()["_embedded"]["query_results"] if "matching_objects" in query_results: print_objinfo(query_results["matching_objects"]) else: print "errors:" for error in query_results["access_errors"]: print " %s" % (error) if json_debug: print "debug:" print " %s" % (response.json()) session.logout(session_id)
def logoutpage(): """ logoutpage() Calls the logout() function in functions.py and then redirects to the login page. In case of failure it must redirect the user on the mainpage with an error message (not implemented yet) """ if logout() == 0: mappa = {"msg": "Logout successfully"} template = env.get_template("login.html") return template.render(mappa) template = env.get_template("login.html") mappa[ "msg"] = "There was a problem during the logout process. Try login and logout again (if necessary)." mappa["error"] = "TRUE" return template.render(mappa)
def GET(self): session.logout() raise web.seeother('/')
def url_logout(): session.logout() bottle.response.delete_cookie("uname") bottle.response.delete_cookie("pwd") bottle.response.delete_cookie("session") bottle.redirect("/index")
def logout( access_token): try: session.logout( access_token) except Exception as e: return errtmpl( '{0}:{1}'.format( type(e), e)) return oktmpl()
if __name__ == '__main__': import session import sys driver = utils.start_driver('chrome') home_dir = str(pathlib.Path.home()) session.login(driver, home_dir + '/cma.credential.json') composer_id, work_id, page_id, track_id = [ int(x) for x in sys.argv[1].split(',') ] out_dir = 'midi/{}'.format(composer_id) job = Download(driver, composer_id, work_id, page_id, track_id) job.order() utils.wait(3) success = False fname = job.pickup(out_dir) if fname: success = job.cleanup() if success: utils.print_message('successfully downloaded {}'.format( job.track.title)) utils.print_message('output file: {}'.format(fname)) utils.wait(3) session.logout(driver) utils.wait(3) utils.close_driver(driver)
def logout(self): session.logout(self._console_url, self._session)
def main(argv): global url try: opts, args = getopt.getopt(argv, "hn:p:t:s:v:o:a:c:u:k:e:m:", [ "help", "name=", "path=", "type=", "server=", "volume=", "port=", "account=", "container=", "secure", "username="******"key=", "export=", "mount=", "test=" ]) except getopt.GetoptError: usage() sys.exit(2) conn_name = None conn_path = None conn_type = None host = None backup_host = None port = None gluster_volume = None swift_account = None swift_container = None swift_secure = False swift_username = None swift_key = None nfs_export = None mount = None test = False for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit() elif opt in ("-n", "--name"): conn_name = arg elif opt in ("-p", "--path"): conn_path = arg elif opt in ("-t", "--type"): conn_type = arg elif opt in ("-s", "--server"): host = arg elif opt in ("-b", "--backup_server"): backup_host = arg elif opt in ("-v", "--volume"): gluster_volume = arg elif opt in ("-o", "--port"): port = int(arg) elif opt in ("-a", "--account"): swift_account = arg elif opt in ("-c", "--container"): swift_container = arg elif opt in ("--secure"): swift_secure = True elif opt in ("-u", "--username"): swift_username = arg elif opt in ("-k", "--key"): swift_key = arg elif opt in ("-e", "--export"): nfs_export = arg elif opt in ("-m", "--mount"): mount = arg elif opt in ("--test"): test = True url = settings.get_setting('BASE_URL') + settings.get_setting( 'TESTDATACONN_URL') + '?query=' + arg if conn_name is None: if not test: usage() sys.exit(2) else: conn_name = "" if conn_type not in ("file", "gluster", "hdfs", "swift", "nfs"): usage() sys.exit(2) # Current set of endpoint args: host, gluster_volume, port, swift_account, # swift_container, swift_secure, swift_username, swift_key, nfs_export, mount has_swift_only_args = swift_account is not None or swift_container is not None or swift_secure or swift_username is not None or swift_key is not None has_required_args = {} has_required_args["file"] = True has_required_args[ "gluster"] = host is not None and gluster_volume is not None has_required_args["hdfs"] = host is not None has_required_args[ "swift"] = host is not None and swift_account is not None and swift_container is not None has_required_args["nfs"] = host is not None and nfs_export is not None has_wrong_args = {} has_wrong_args[ "file"] = host is not None or gluster_volume is not None or port is not None or has_swift_only_args or nfs_export is not None has_wrong_args[ "gluster"] = has_swift_only_args or nfs_export is not None or mount is not None has_wrong_args[ "hdfs"] = gluster_volume is not None or has_swift_only_args or nfs_export is not None or mount is not None has_wrong_args[ "swift"] = gluster_volume is not None or port is not None or nfs_export is not None or mount is not None has_wrong_args[ "nfs"] = gluster_volume is not None or port is not None or has_swift_only_args if has_wrong_args[conn_type] or not has_required_args[conn_type]: usage() sys.exit(2) session_id = session.login(user='******') if conn_type == "file": response = post_file_dataconn(session_id, conn_path, conn_name, mount) elif conn_type == "gluster": response = post_gluster_dataconn(session_id, conn_path, conn_name, host, gluster_volume, port) elif conn_type == "hdfs": response = post_hdfs_dataconn(session_id, conn_path, conn_name, host, backup_host, port) elif conn_type == "swift": response = post_swift_dataconn(session_id, conn_path, conn_name, host, swift_account, swift_container, swift_secure, swift_username, swift_key) elif conn_type == "nfs": response = post_nfs_dataconn(session_id, conn_path, conn_name, host, nfs_export, mount) print if not test: if response.status_code != 201: print "Data connector creation failed!" print response.text sys.exit() print "Created: %s" % (response.headers["location"]) print else: if response.status_code != 200: print "Data connector test failed!" print response.text sys.exit() query_results = response.json()["query_results"] if "matching_objects" in query_results: query_dataconn.print_objinfo(query_results["matching_objects"]) else: print "errors:" for error in query_results["access_errors"]: print " %s" % (error) if json_debug: print "debug:" print " %s" % (response.json()) session.logout(session_id)
def logout(self): self._session = session.logout(self._session)