def __init__(self, config: Dict): '''config should be a Python dictionary containing the API key for the Alma Users API as well as the endpoint for looking up a user by Primary ID. ''' self.logger = logging.getLogger('lcpp.alma_requests') check_config(config=config, top_level_key='Alma', config_keys=['apikeys', 'users_endpt'], obj=self) # Initialize throttler for Alma's rate limit self.throttler = Throttler(rate_limit=25)
def main(): logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s # %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') config = parse_options() SERVER = config['server'] PORT = config['server_port'] KEY = config['password'] config['method'] = config.get('method', None) METHOD = config.get('method') config['port_password'] = config.get('port_password', None) PORTPASSWORD = config.get('port_password') config['timeout'] = config.get('timeout', 600) if not KEY and not config_path: sys.exit('config not specified, please read https://github.com/clowwindy/shadowsocks') utils.check_config(config) global G_CONFIG G_CONFIG = config if PORTPASSWORD: if PORT or KEY: logging.warn('warning: port_password should not be used with server_port and password. server_port and password will be ignored') else: PORTPASSWORD = {} PORTPASSWORD[str(PORT)] = KEY encrypt.init_table(KEY, METHOD) io = ioloop.IOLoop() import socket sock = socket.socket() sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setblocking(0) sock.bind((SERVER, PORT)) logging.info("listing on %s", str(sock.getsockname())) sock.listen(1024) io.add_handler(sock.fileno(), MyAcceptHandler(io, sock), m_read=True) timeout = 0.1 min_looptime = 0.01 while True: _start = time.time() io.wait_events(timeout) sleep_time = min_looptime - (time.time()-_start) if sleep_time > 0: time.sleep(sleep_time)
def __init__(self, config: Dict): '''config should contain the client id and client secret for the LibCal API, as well as the authentication and bookings endpoints, all nested under a "LibCal" key. ''' self.logger = logging.getLogger('lcpp.libcal_requests') check_config(config=config, top_level_key='LibCal', config_keys=[ 'client_id', 'client_secret', 'credentials_endpt', 'bookings_endpt', 'locations', 'primary_id_field' ], obj=self) # Pattern to test for the presence of a valid primary identifier self.id_match = re.compile(r'[Gg]\d{8}') self.fetch_token()
def produce_consume(): real_path, word_path, config_path = paths() check_paths(word_path, config_path) config = get_config(config_path) try: error = check_config(config) except Exception as e: print(type(e).__name__, e) exit(1) else: if error is not None: print(error) exit(1) q = Queue() consumer = Consumer(q) for i in range(16): t = Thread(target=consumer.consume_domains) t.daemon = True t.start() Producer(q, config, word_path).get_doms() q.join() if config['write_to_file']: print_red('writing to domains.json') p = Process(target=add_data, args=(real_path, consumer.get_domains())) p.start() print_red('sleeping zzzzz...') sleep(config['interval'])
def main(): parser = argparse.ArgumentParser(description='Proxyless-NAS augment') parser.add_argument('-n', '--name', type=str, required=True, help="name of the model") parser.add_argument('-c', '--config', type=str, default='./config/default.yaml', help="yaml config file") parser.add_argument('-p', '--chkpt', type=str, default=None, help="path of checkpoint pt file") parser.add_argument('-d', '--device', type=str, default="all", help="override device ids") parser.add_argument('-g', '--genotype', type=str, default=None, help="override genotype file") args = parser.parse_args() hp = HParam(args.config) pt_path = os.path.join('.', hp.log.chkpt_dir) out_dir = os.path.join(pt_path, args.name) os.makedirs(out_dir, exist_ok=True) log_dir = os.path.join('.', hp.log.log_dir) log_dir = os.path.join(log_dir, args.name) os.makedirs(log_dir, exist_ok=True) logger = utils.get_logger(log_dir, args.name) if utils.check_config(hp, args.name): raise Exception("Config error.") writer = utils.get_writer(log_dir, hp.log.writer) dev, dev_list = utils.init_device(hp.device, args.device) trn_loader = load_data(hp.augment.data, validation=False) val_loader = load_data(hp.augment.data, validation=True) gt.set_primitives(hp.genotypes) # load genotype genotype = utils.get_genotype(hp.augment, args.genotype) model, arch = get_model(hp.model, dev, dev_list, genotype) augment(out_dir, args.chkpt, trn_loader, val_loader, model, writer, logger, dev, hp.augment)
def mini_spider(args): """ Mini-spider main function """ try: configs = utils.check_config(args) except Exception as err: logging.error(err) logging.info("Mini-spider Exit!") return thread_num = configs['thread_count'] url_queue = Queue.Queue() # queue of urls that waiting to be crawled """Add seed url to url_queue""" with open(configs['url_list_file'], 'r') as fin: for line in fin.readlines(): url = line.strip() url_queue.put(objects.Url(url, 0), block=False) """Start-up Spider process""" logging.info("Mini-spider process Begin!") spider_manager = SpiderManager(url_queue, thread_num, configs) spider_manager.wait_all_complete() logging.info("Mini-spider process Done!")
def main(): if len(sys.argv) == 1: utils.install() report = Report(sys.argv[1]) utils.check_config() info = utils.get_task_info(report.data) target = utils.get_deliver_dir(info) msg = "\nDo you want to deliver test result to \n{0}".format(target) utils.confirm(msg) report.update_issue(info) report.deliver_result(target) report.xlsx_update() utils.tmp_print_info(report)
def create_loggers(config: Dict): '''config should contain a key called Emails''' email_config = check_config(config=config, top_level_key='Emails', config_keys=['from_email', 'from_username', 'from_password', 'smtp_host', 'to_email']) # For ERROR output to email smtphandler = SMTPHandler(mailhost=(email_config["smtp_host"], 587), fromaddr=email_config["from_email"], toaddrs=email_config["to_email"], subject="LibCal-PP App ERROR", credentials=(email_config["from_username"], email_config["from_password"]), secure=()) smtphandler.setLevel("ERROR") # For output to terminal handler = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s:%(message)s') handler.setFormatter(formatter) smtphandler.setFormatter(formatter) logger = logging.getLogger('lcpp') logger.addHandler(smtphandler) logger.addHandler(handler) return logger
def main(): global config_server, config_server_port, config_method, config_fast_open, \ config_timeout logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version config_path = utils.find_config() try: optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:t:', ['fast-open', 'workers:']) for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: config = json.load(f) except ValueError as e: logging.error('found an error in config.json: %s', e.message) sys.exit(1) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:t:', ['fast-open', 'workers=']) for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-t': config['timeout'] = value elif key == '--fast-open': config['fast_open'] = True elif key == '--workers': config['workers'] = value except getopt.GetoptError: utils.print_server_help() sys.exit(2) config_server = config['server'] config_server_port = config['server_port'] config_key = config['password'] config_method = config.get('method', None) config_port_password = config.get('port_password', None) config_timeout = int(config.get('timeout', 300)) config_fast_open = config.get('fast_open', False) config_workers = config.get('workers', 1) if not config_key and not config_path: sys.exit('config not specified, please read ' 'https://github.com/clowwindy/shadowsocks') utils.check_config(config) if config_port_password: if config_server_port or config_key: logging.warn('warning: port_password should not be used with ' 'server_port and password. server_port and password ' 'will be ignored') else: config_port_password = {} config_port_password[str(config_server_port)] = config_key encrypt.init_table(config_key, config_method) addrs = socket.getaddrinfo(config_server, int(8387)) if not addrs: logging.error('cant resolve listen address') sys.exit(1) ThreadingTCPServer.address_family = addrs[0][0] tcp_servers = [] udp_servers = [] for port, key in config_port_password.items(): tcp_server = ThreadingTCPServer((config_server, int(port)), Socks5Server) tcp_server.key = key tcp_server.method = config_method tcp_server.timeout = int(config_timeout) logging.info("starting server at %s:%d" % tuple(tcp_server.server_address[:2])) tcp_servers.append(tcp_server) udp_server = udprelay.UDPRelay(config_server, int(port), None, None, key, config_method, int(config_timeout), False) udp_servers.append(udp_server) def run_server(): for tcp_server in tcp_servers: threading.Thread(target=tcp_server.serve_forever).start() for udp_server in udp_servers: udp_server.start() if int(config_workers) > 1: if os.name == 'posix': children = [] is_child = False for i in xrange(0, int(config_workers)): r = os.fork() if r == 0: logging.info('worker started') is_child = True run_server() break else: children.append(r) if not is_child: def handler(signum, frame): for pid in children: os.kill(pid, signum) os.waitpid(pid, 0) sys.exit() import signal signal.signal(signal.SIGTERM, handler) # master for tcp_server in tcp_servers: tcp_server.server_close() for udp_server in udp_servers: udp_server.close() for child in children: os.waitpid(child, 0) else: logging.warn('worker is only available on Unix/Linux') run_server() else: run_server()
def main(): global config_server, config_server_port, config_method, config_fast_open logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version config_path = utils.find_config() try: optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:', ['fast-open']) for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: config = json.load(f) except ValueError as e: logging.error('found an error in config.json: %s', e.message) sys.exit(1) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:', ['fast-open']) for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '--fast-open': config['fast_open'] = True except getopt.GetoptError: utils.print_server_help() sys.exit(2) config_server = config['server'] config_server_port = config['server_port'] config_key = config['password'] config_method = config.get('method', None) config_port_password = config.get('port_password', None) config_timeout = config.get('timeout', 600) config_fast_open = config.get('fast_open', False) if not config_key and not config_path: sys.exit('config not specified, please read ' 'https://github.com/clowwindy/shadowsocks') utils.check_config(config) if config_port_password: if config_server_port or config_key: logging.warn('warning: port_password should not be used with ' 'server_port and password. server_port and password ' 'will be ignored') else: config_port_password = {} config_port_password[str(config_server_port)] = config_key encrypt.init_table(config_key, config_method) addrs = socket.getaddrinfo(config_server, int(8387)) if not addrs: logging.error('cant resolve listen address') sys.exit(1) ThreadingTCPServer.address_family = addrs[0][0] for port, key in config_port_password.items(): server = ThreadingTCPServer((config_server, int(port)), Socks5Server) server.key, server.method, server.timeout = key, config_method,\ int(config_timeout) logging.info("starting server at %s:%d" % tuple(server.server_address[:2])) threading.Thread(target=server.serve_forever).start() udprelay.UDPRelay(config_server, int(port), None, None, key, config_method, int(config_timeout), False).start()
#!/usr/bin/env python import server import utils if __name__ == '__main__': utils.check_config() server.run()
def main(): logging.basicConfig( level=logging.DEBUG, format="%(asctime)s %(levelname)-8s %(message)s", datefmt="%Y-%m-%d %H:%M:%S", filemode="a+", ) version = "" try: import pkg_resources version = pkg_resources.get_distribution("shadowsocks").version except: pass print "shadowsocks %s" % version KEY = None METHOD = None IPv6 = False config_path = utils.find_config() optlist, args = getopt.getopt(sys.argv[1:], "s:p:k:m:c:6") for key, value in optlist: if key == "-c": config_path = value if config_path: with open(config_path, "rb") as f: config = json.load(f) logging.info("loading config from %s" % config_path) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], "s:p:k:m:c:6") for key, value in optlist: if key == "-p": config["server_port"] = int(value) elif key == "-k": config["password"] = value elif key == "-s": config["server"] = value elif key == "-m": config["method"] = value elif key == "-6": IPv6 = True SERVER = config["server"] PORT = config["server_port"] KEY = config["password"] METHOD = config.get("method", None) PORTPASSWORD = config.get("port_password", None) TIMEOUT = config.get("timeout", 600) if not KEY and not config_path: sys.exit("config not specified, please read https://github.com/clowwindy/shadowsocks") utils.check_config(config) if PORTPASSWORD: if PORT or KEY: logging.warn( "warning: port_password should not be used with server_port and password. server_port and password will be ignored" ) else: PORTPASSWORD = {} PORTPASSWORD[str(PORT)] = KEY encrypt.init_table(KEY, METHOD) if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 for port, key in PORTPASSWORD.items(): server = ThreadingTCPServer((SERVER, int(port)), Socks5Server) server.key, server.method, server.timeout = key, METHOD, int(TIMEOUT) logging.info("starting server at %s:%d" % tuple(server.server_address[:2])) threading.Thread(target=server.serve_forever).start()
def main(): global SERVER, REMOTE_PORT, PORT, KEY, METHOD, LOCAL, IPv6 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') # fix py2exe if hasattr(sys, "frozen") and sys.frozen in \ ("windows_exe", "console_exe"): p = os.path.dirname(os.path.abspath(sys.executable)) os.chdir(p) version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version KEY = None METHOD = None LOCAL = '' IPv6 = False config_path = utils.find_config() optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: config = json.load(f) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-l': config['local_port'] = int(value) elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-b': config['local'] = value elif key == '-6': IPv6 = True SERVER = config['server'] REMOTE_PORT = config['server_port'] PORT = config['local_port'] KEY = config['password'] METHOD = config.get('method', None) LOCAL = config.get('local', '') if not KEY and not config_path: sys.exit( 'config not specified, please read https://github.com/clowwindy/shadowsocks' ) utils.check_config(config) encrypt.init_table(KEY, METHOD) try: if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 server = ThreadingTCPServer((LOCAL, PORT), Socks5Server) logging.info("starting local at %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
def main(): global SERVER, PORT, KEY, METHOD, IPv6 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version KEY = None METHOD = None IPv6 = False config_path = utils.find_config() optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:6') for key, value in optlist: if key == '-c': config_path = value if config_path: with open(config_path, 'rb') as f: config = json.load(f) logging.info('loading config from %s' % config_path) optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:6') for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-6': IPv6 = True SERVER = config['server'] PORT = config['server_port'] KEY = config['password'] METHOD = config.get('method', None) if not KEY and not config_path: sys.exit('config not specified, please read https://github.com/clowwindy/shadowsocks') utils.check_config(config) encrypt.init_table(KEY, METHOD) if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 try: server = ThreadingTCPServer((SERVER, PORT), Socks5Server) logging.info("starting server at %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
def create_score_map(test_target, data_name, config, ratio, model_path=None, save_score_map=False, save_image=False): MODEL_DIR = '.\\logs' # check config utils.check_config(config) # create model model_inference = modellib.MaskRCNN(mode="inference", config=config, model_dir=MODEL_DIR) if model_path is None: model_path = model_inference.find_last() print("Loading weights from ", model_path) model_inference.load_weights(model_path, by_name=True) # generate dataset # 检查data是否包含small if 'pad' in data_name: _start, _end = re.search('pad', data_name).span() data_pad = int(data_name[:_start].split('_')[-1]) else: data_pad = 0 print('test_target: %s, data_pad: %s' % (test_target, data_pad)) dataset_test = utils.generate_dataset(test_target, data_name) image_shape = utils.get_image_shape(test_target) idsNum = len(dataset_test.image_ids) # generate score_map_total score_map_total = np.zeros( (image_shape[1] // ratio, image_shape[0] // ratio, config.NUM_CLASSES - 1), dtype=np.float32) for image_id in dataset_test.image_ids[:]: if image_id % 50 == 0: print('%s/%s' % (image_id, idsNum)) # generate image image_path = dataset_test.image_info[image_id]['path'] image = skimage.io.imread(image_path) # generate LMB LMB_path = dataset_test.image_info[image_id]['LMB_path'] LMB = skimage.io.imread(LMB_path) # generate x1,y1,interval x1, y1, interval = image_path.split('\\')[-1].split('.')[-2].split( '_')[2:5] def _ratio(x): return int(x) // ratio x1_ratio, y1_ratio, interval_ratio = list( map(_ratio, [x1, y1, interval])) x1_ratio -= data_pad // ratio y1_ratio -= data_pad // ratio score_map_total_x1, score_map_total_y1 = x1_ratio, y1_ratio score_map_total_x2 = score_map_total_x1 + interval_ratio score_map_total_y2 = score_map_total_y1 + interval_ratio score_map_x1, score_map_y1 = 0, 0 if x1_ratio < 0: score_map_total_x1 = 0 score_map_x1 = -x1_ratio if y1_ratio < 0: score_map_total_y1 = 0 score_map_y1 = -y1_ratio # predict results results = model_inference.detect([image], verbose=0) r = results[0] for n, class_id in enumerate(r['class_ids']): # generate mask_n mask_n = r['masks'][:, :, n].astype(np.float32) mask_n = mask_n * LMB if ratio != 1: mask_n = cv2.resize(mask_n, (interval_ratio, interval_ratio), interpolation=cv2.INTER_NEAREST) # generate score_map score_n = r['scores'][n] score_map = mask_n * score_n # 取score_map_total和score_map对应pixel的较大值赋值到score_map_total score_map_total[score_map_total_y1:score_map_total_y2, score_map_total_x1:score_map_total_x2, class_id - 1] = np.maximum( score_map[score_map_y1:, score_map_x1:], score_map_total[ score_map_total_y1:score_map_total_y2, score_map_total_x1:score_map_total_x2, class_id - 1]) # save phase save_dir = '.\\merge_submit' if not os.path.exists(save_dir): os.mkdir(save_dir) model_stamp = utils.create_model_stamp(model_path) image_name = '%s_%ssmall_%spad' % (test_target, ratio, data_pad) # save score_map_total as npy if save_score_map: npy_save_path = os.path.join( save_dir, '%s_scoremap_%s.npy' % (image_name, model_stamp)) np.save(npy_save_path, score_map_total) print(npy_save_path, 'has been saved succefully.') # save and show score_map as png by class if save_image: rows = config.NUM_CLASSES - 1 fig, axs = plt.subplots(rows, 1, figsize=(16, 16 * rows)) if ratio == 1: image_path = ".\\offical_data\\jingwei_round1_test_a_20190619\\%s.png" % test_target else: image_path = ".\\overview\\%s_%ssmall.png" % (test_target, ratio) Image.MAX_IMAGE_PIXELS = None image_frame_oringin = skimage.io.imread(image_path) for class_id in range(1, config.NUM_CLASSES): score_map = score_map_total[:, :, class_id - 1] image_frame = image_frame_oringin.copy() color = utils.COLOR_MAP[class_id] for c in range(3): image_frame[:, :, c] = image_frame[:, :, c] * ( 1 - score_map) + score_map * color[c] axs[class_id - 1].imshow(image_frame) image_save_path = os.path.join( save_dir, '%s_class%d_%s.png' % (image_name, class_id, model_stamp)) skimage.io.imsave(image_save_path, image_frame) print(image_save_path, 'has been saved succefully.') return score_map_total, model_path
def main(): global SERVER, PORT, KEY, METHOD, IPv6 logging.basicConfig( level=logging.CRITICAL, format="%(asctime)s %(levelname)-8s %(message)s", datefmt="%Y-%m-%d %H:%M:%S", filemode="a+", ) version = "" try: import pkg_resources version = pkg_resources.get_distribution("shadowsocks").version except: pass print "shadowsocks %s" % version KEY = None METHOD = None IPv6 = False config_path = utils.find_config() optlist, args = getopt.getopt(sys.argv[1:], "s:p:k:m:c:6") for key, value in optlist: if key == "-c": config_path = value if config_path: with open(config_path, "rb") as f: config = json.load(f) logging.info("loading config from %s" % config_path) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], "s:p:k:m:c:6") for key, value in optlist: if key == "-p": config["server_port"] = int(value) elif key == "-k": config["password"] = value elif key == "-s": config["server"] = value elif key == "-m": config["method"] = value elif key == "-6": IPv6 = True SERVER = config["server"] PORT = config["server_port"] KEY = config["password"] METHOD = config.get("method", None) if not KEY and not config_path: sys.exit("config not specified, please read https://github.com/clowwindy/shadowsocks") utils.check_config(config) encrypt.init_table(KEY, METHOD) if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 try: server = ThreadingTCPServer((SERVER, PORT), Socks5Server) logging.info("starting server at %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
from process_plan import case_rr, case_fcfs from page_swap import case_fifo, case_lru import time from utils import check_config from config import config as cfg timestamp = time.strftime("%Y-%m-%d_%H-%M-%S") if __name__ == '__main__': check_config(cfg) if cfg["EXE"]["RR"]: case_rr(timestamp) if cfg["EXE"]["FCFS"]: case_fcfs(timestamp) if cfg["EXE"]["FIFO"]: case_fifo(timestamp) if cfg["EXE"]["LRU"]: case_lru(timestamp)
while True: print print("Search for most similar publication venues and years. Press enter with no input to continue.") query_venue = raw_input("Venue: ") if query_venue == '': return query_year = raw_input("Year: ") results = svy.query_venue_year(venue=query_venue, year=query_year, top_k=top_k) if results is not None: print print("Results:") for i, res in enumerate(results): print("%d) %s (%.4f)") % (i+1, res[0] + " " + str(res[1]), res[2]) if __name__ == '__main__': with open(CONFIG_DIR) as f: config = json.load(f, encoding='ascii') config = check_config(config) lucene.initVM() # start JVM for Lucene title_analyzer = CustomAnalyzer(config['titleAnalyzer']) per_field = HashMap() per_field.put("title", title_analyzer) analyzer = PerFieldAnalyzerWrapper( StandardAnalyzer(Version.LUCENE_CURRENT), per_field) run_app1(top_k=10) run_app2(n_topics=10, n_iter=100, top_k=10)
def _config_loader(file): config = yaml_loader(file) assert check_config(config) return config
self.on_update(True) if __name__ == '__main__': if not plugin.get_setting('player_id', str): plugin.set_setting('player_id', str(uuid.uuid4())) monitor = xbmc.Monitor() tp = TrackingPlayer() tt = TidalTracker(tp) last_config = None no_player_found = None while True: if check_config(): if tt.usable and serialize_config() != last_config: plugin.log.info('Config was changed, lets kill old websocket connection') tt.disconnect_player() no_player_found = None time.sleep(3) if not tt.usable and (no_player_found is None or no_player_found < time.time()): plugin.log.info('Seems like websocket is not running, lets try to rectify that') tsc = get_client() player_id = plugin.get_setting('player_id') name = xbmc.getInfoLabel('System.FriendlyName') try: player = tsc.register_player(player_id, name)
def main(): global config_server, config_server_port, config_password, config_method,\ config_fast_open, config_timeout logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') # fix py2exe if hasattr(sys, "frozen") and sys.frozen in \ ("windows_exe", "console_exe"): p = os.path.dirname(os.path.abspath(sys.executable)) os.chdir(p) version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version config_password = None config_method = None config_path = utils.find_config() try: optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:t:', ['fast-open']) for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: config = json.load(f) except ValueError as e: logging.error('found an error in config.json: %s', e.message) sys.exit(1) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:t:', ['fast-open']) for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-l': config['local_port'] = int(value) elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-b': config['local_address'] = value elif key == '--fast-open': config['fast_open'] = True except getopt.GetoptError as e: logging.error(e) utils.print_local_help() sys.exit(2) config_server = config['server'] config_server_port = config['server_port'] config_local_port = config['local_port'] config_password = config['password'] config_method = config.get('method', None) config_local_address = config.get('local_address', '127.0.0.1') config_timeout = int(config.get('timeout', 300)) config_fast_open = config.get('fast_open', False) if not config_password and not config_path: sys.exit('config not specified, please read ' 'https://github.com/clowwindy/shadowsocks') utils.check_config(config) encrypt.init_table(config_password, config_method) addrs = socket.getaddrinfo(config_local_address, config_local_port) if not addrs: logging.error('cant resolve listen address') sys.exit(1) ThreadingTCPServer.address_family = addrs[0][0] try: udprelay.UDPRelay(config_local_address, int(config_local_port), config_server, config_server_port, config_password, config_method, int(config_timeout), True).start() server = ThreadingTCPServer((config_local_address, config_local_port), Socks5Server) server.timeout = int(config_timeout) logging.info("starting local at %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
def main(): from version import __version__ import circ import pipeline from logger import get_logger from utils import check_file, check_dir, check_config, get_thread_num from utils import CIRCparser, TOOLS # Init argparser parser = argparse.ArgumentParser(prog='CIRIquant') # required arguments parser.add_argument( '--config', dest='config_file', metavar='FILE', help='Config file in YAML format', ) parser.add_argument( '-1', '--read1', dest='mate1', metavar='MATE1', help='Input mate1 reads (for paired-end data)', ) parser.add_argument( '-2', '--read2', dest='mate2', metavar='MATE2', help='Input mate2 reads (for paired-end data)', ) # optional arguments parser.add_argument( '-o', '--out', dest='output', metavar='DIR', default=None, help='Output directory, default: ./', ) parser.add_argument( '-p', '--prefix', dest='prefix', metavar='PREFIX', default=None, help='Output sample prefix, default: input sample name', ) parser.add_argument( '-t', '--threads', dest='cpu_threads', default=4, metavar='INT', help='Number of CPU threads, default: 4', ) parser.add_argument( '-a', '--anchor', dest='anchor', default=5, metavar='INT', help='Minimum anchor length for junction alignment, default: 5', ) parser.add_argument( '-l', '--libary-type', dest='library_type', metavar='INT', default=0, help='Library type, 0: unstranded, 1: read1 match the sense strand,' '2: read1 match the antisense strand, default: 0', ) parser.add_argument( '-v', '--verbose', dest='verbosity', default=False, action='store_true', help='Run in debugging mode', ) parser.add_argument( '--version', action='version', version='%(prog)s {version}'.format(version=__version__)) parser.add_argument( '-e', '--log', dest='log_file', default=None, metavar='LOG', help='Log file, default: out_dir/prefix.log', ) # provide pre-defined list of circRNAs parser.add_argument( '--bed', dest='bed', metavar='FILE', default=None, help='bed file for putative circRNAs (optional)', ) parser.add_argument( '--circ', dest='circ', metavar='FILE', default=None, help='circRNA prediction results from other softwares', ) parser.add_argument( '--tool', dest='tool', metavar='TOOL', default=None, help='circRNA prediction tool, required if --circ is provided', ) # when provide RNase R result, do RNase R correction parser.add_argument( '--RNaseR', dest='rnaser', metavar='FILE', default=None, help='CIRIquant result of RNase R sample', ) # skip hisat2 alignment for RNA-seq data parser.add_argument( '--bam', dest='bam', metavar='BAM', default=None, help='hisat2 alignment to reference genome', ) # skip stringtie prediction parser.add_argument( '--no-gene', dest='gene_exp', default=False, action='store_true', help='Skip stringtie estimation for gene abundance', ) args = parser.parse_args() """Check required parameters""" # check input reads if args.mate1 and args.mate2: reads = [check_file(args.mate1), check_file(args.mate2)] else: sys.exit( 'No input files specified, please see manual for detailed information' ) try: lib_type = int(args.library_type) except ValueError: sys.exit( 'Wrong library type, please check your command.\nSupported types:\n0 - unstranded;\n' '1 - read1 match the sense strand;\n2 - read1 match the antisense strand;' ) if lib_type not in [0, 1, 2]: sys.exit( 'Wrong library type, please check your command.\nSupported types:\n0 - unstranded;\n' '1 - read1 match the sense strand;\n2 - read1 match the antisense strand;' ) # check configuration if args.config_file: config = check_config(check_file(args.config_file)) else: sys.exit( 'A config file is needed, please see manual for detailed information.' ) """Check optional parameters""" # use circRNA bed file if provided bed_file = check_file(args.bed) if args.bed else None circ_file = check_file(args.circ) if args.circ else None circ_tool = args.tool # user provided RNase R CIRIquant results rnaser_file = check_file(args.rnaser) if args.rnaser else None # pre aligned hisat2 bam hisat_bam = check_file(args.bam) if args.bam else None # Output prefix if args.prefix is None: try: prefix = re.search(r'(\S+)[_/-][12]', os.path.basename(reads[0])).group(1) except AttributeError: sys.exit( 'Ambiguous sample name, please manually select output prefix') else: prefix = args.prefix # check output dir outdir = './' + prefix if args.output is None else args.output outdir = check_dir(outdir) # Parse arguments log_file = os.path.abspath( args.log_file) if args.log_file else '{}/{}.log'.format( outdir, prefix) verbosity = args.verbosity logger = get_logger('CIRIquant', log_file, verbosity) # Add lib to PATH lib_path = os.path.dirname(os.path.split( os.path.realpath(__file__))[0]) + '/libs' os.environ['PATH'] = lib_path + ':' + os.environ['PATH'] os.chmod(lib_path + '/CIRI2.pl', 0o755) """Start Running""" os.chdir(outdir) logger.info( 'Input reads: ' + ','.join([os.path.basename(args.mate1), os.path.basename(args.mate2)])) if lib_type == 0: lib_name = 'unstranded' elif lib_type == 1: lib_name = 'ScriptSeq' elif lib_type == 2: lib_name = 'TAKARA SMARTer' else: sys.exit( 'Unsupported library type, please check the manual for instructions.' ) logger.info('Library type: {}'.format(lib_name)) logger.info('Output directory: {}, Output prefix: {}'.format( outdir, prefix)) logger.info('Config: {} Loaded'.format(config)) thread = get_thread_num(int(args.cpu_threads)) anchor = int(args.anchor) # Step1: Data Preparation # Step1.1: HISAT2 mapping if hisat_bam is None: logger.info('Align RNA-seq reads to reference genome ..') hisat_bam = pipeline.align_genome(log_file, thread, reads, outdir, prefix) else: logger.info( 'HISAT2 alignment bam provided, skipping alignment step ..') logger.debug('HISAT2 bam: {}'.format(os.path.basename(hisat_bam))) # Step1.2: Estimate Gene Abundance if args.gene_exp: logger.info('Skipping gene abundance estimation') else: pipeline.gene_abundance(log_file, thread, outdir, prefix, hisat_bam) # Step3: run CIRI2 if bed_file: logger.info( 'Using user-provided circRNA bed file: {}'.format(bed_file)) else: if circ_file or circ_tool: if circ_file and circ_tool: logger.info( 'Using predicted circRNA results from {}: {}'.format( circ_tool, circ_file)) circ_parser = CIRCparser(circ_file, circ_tool) else: sys.exit( '--circ and --tool must be provided in the same time!') else: logger.info( 'No circRNA information provided, run CIRI2 for junction site prediction ..' ) bwa_sam = pipeline.run_bwa(log_file, thread, reads, outdir, prefix) ciri_file = pipeline.run_ciri(log_file, thread, bwa_sam, outdir, prefix) circ_parser = CIRCparser(ciri_file, 'CIRI2') bed_file = '{}/{}.bed'.format(outdir, prefix) circ_parser.convert(bed_file) # Step4: estimate circRNA expression level out_file = circ.proc(log_file, thread, bed_file, hisat_bam, rnaser_file, reads, outdir, prefix, anchor, lib_type) # Remove temporary files pipeline.clean_tmp(outdir, prefix) logger.info('circRNA Expression profile: {}'.format( os.path.basename(out_file))) logger.info('Finished!')
def main(): logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version KEY = None METHOD = None IPv6 = False config_path = utils.find_config() optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:6') for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: config = json.load(f) except ValueError as e: logging.error('found an error in config.json: %s', e.message) sys.exit(1) logging.info('loading config from %s' % config_path) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:6') for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-6': IPv6 = True SERVER = config['server'] PORT = config['server_port'] KEY = config['password'] METHOD = config.get('method', None) PORTPASSWORD = config.get('port_password', None) TIMEOUT = config.get('timeout', 600) if not KEY and not config_path: sys.exit( 'config not specified, please read https://github.com/clowwindy/shadowsocks' ) utils.check_config(config) if PORTPASSWORD: if PORT or KEY: logging.warn( 'warning: port_password should not be used with server_port and password. server_port and password will be ignored' ) else: PORTPASSWORD = {} PORTPASSWORD[str(PORT)] = KEY encrypt.init_table(KEY, METHOD) if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 for port, key in PORTPASSWORD.items(): server = ThreadingTCPServer((SERVER, int(port)), Socks5Server) server.key, server.method, server.timeout = key, METHOD, int(TIMEOUT) logging.info("starting server at %s:%d" % tuple(server.server_address[:2])) threading.Thread(target=server.serve_forever).start()
from __future__ import print_function import os import time import datetime import argparse from utils import check_config check_config() import models, datasets import keras from keras import backend as K from keras.metrics import categorical_accuracy from keras.utils.multi_gpu_utils import multi_gpu_model from keras.utils.vis_utils import plot_model ap = argparse.ArgumentParser() ap.add_argument("-b", "--batch_size", type=int, default=3, help="# of images per batch") ap.add_argument("-p", "--parallel", default=False, help="Enable multi GPUs", action='store_true') ap.add_argument("-e", "--epochs", type=int, default=12, help="# of training epochs")
def main(): global SERVER, REMOTE_PORT, PORT, KEY, METHOD, LOCAL, IPv6 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') # fix py2exe if hasattr(sys, "frozen") and sys.frozen in \ ("windows_exe", "console_exe"): p = os.path.dirname(os.path.abspath(sys.executable)) os.chdir(p) version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version KEY = None METHOD = None LOCAL = '' IPv6 = False config_path = utils.find_config() optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: config = json.load(f) optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-l': config['local_port'] = int(value) elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-b': config['local'] = value elif key == '-6': IPv6 = True SERVER = config['server'] REMOTE_PORT = config['server_port'] PORT = config['local_port'] KEY = config['password'] METHOD = config.get('method', None) LOCAL = config.get('local', '') if not KEY and not config_path: sys.exit('config not specified, please read https://github.com/clowwindy/shadowsocks') utils.check_config(config) encrypt.init_table(KEY, METHOD) Connection.shared().spawn() try: if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 server = ThreadingTCPServer((LOCAL, PORT), Socks5Server) logging.info("starting local at %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
def main(): global config_server, config_server_port, config_password, config_method,\ config_fast_open logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') # fix py2exe if hasattr(sys, "frozen") and sys.frozen in \ ("windows_exe", "console_exe"): p = os.path.dirname(os.path.abspath(sys.executable)) os.chdir(p) version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version config_password = None config_method = None config_path = utils.find_config() try: optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:', ['fast-open']) for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: config = json.load(f) except ValueError as e: logging.error('found an error in config.json: %s', e.message) sys.exit(1) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:', ['fast-open']) for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-l': config['local_port'] = int(value) elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-b': config['local_address'] = value elif key == '--fast-open': config['fast_open'] = True except getopt.GetoptError as e: logging.error(e) utils.print_local_help() sys.exit(2) config_server = config['server'] config_server_port = config['server_port'] config_local_port = config['local_port'] config_password = config['password'] config_method = config.get('method', None) config_local_address = config.get('local_address', '127.0.0.1') config_timeout = config.get('timeout', 600) config_fast_open = config.get('fast_open', False) if not config_password and not config_path: sys.exit('config not specified, please read ' 'https://github.com/clowwindy/shadowsocks') utils.check_config(config) encrypt.init_table(config_password, config_method) addrs = socket.getaddrinfo(config_local_address, config_local_port) if not addrs: logging.error('cant resolve listen address') sys.exit(1) ThreadingTCPServer.address_family = addrs[0][0] try: udprelay.UDPRelay(config_local_address, int(config_local_port), config_server, config_server_port, config_password, config_method, int(config_timeout), True).start() server = ThreadingTCPServer((config_local_address, config_local_port), Socks5Server) logging.info("starting local at %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
def main(): print('欢迎使用Time-Machine Shadowsocks多链接客户端') global SERVER, REMOTE_PORT, PORT, KEY, METHOD, LOCAL, IPv6 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') # py2exe 修复 if hasattr(sys, "frozen") and sys.frozen in \ ("windows_exe", "console_exe"): p = os.path.dirname(os.path.abspath(sys.executable)) os.chdir(p) version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version KEY = None METHOD = None LOCAL = '' IPv6 = False config_path = utils.find_config() optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('Loading Config From %s' % config_path) with open(config_path, 'rb') as f: config = json.load(f) #判断config.json中是否包含了"server_password"来确定是否启用了多端口 if config.has_key("server_password") == True: #获得"server_password"的长度,得到服务器端口记录 number = len(config["server_password"]) #通过random来随机分配用哪一条服务器端口密码记录 orientation = random.randint(0, number - 1) server_dict = {} server_dict[u"server"] = config["server_password"][ orientation][0] server_dict[u"server_port"] = config["server_password"][ orientation][1] server_dict[u"password"] = config["server_password"][ orientation][2] server_dict[u"local_port"] = config["local_port"] server_dict[u"method"] = config["method"] server_dict[u"timeout"] = config["timeout"] config = server_dict #print config #else: # print config optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-l': config['local_port'] = int(value) elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-b': config['local'] = value elif key == '-6': IPv6 = True SERVER = config['server'] REMOTE_PORT = config['server_port'] PORT = config['local_port'] KEY = config['password'] METHOD = config.get('method', None) LOCAL = config.get('local', '') if not KEY and not config_path: sys.exit('定义失败') utils.check_config(config) encrypt.init_table(KEY, METHOD) try: if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 server = ThreadingTCPServer((LOCAL, PORT), Socks5Server) logging.info("存在的远端服务器 %s:%d" % (SERVER, REMOTE_PORT)) logging.info("套接字启动链接 %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
def main(): logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version KEY = None METHOD = None IPv6 = False config_path = utils.find_config() optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:6') for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('loading config from %s' % config_path) with open(config_path, 'rb') as f: try: config = json.load(f) except ValueError as e: logging.error('found an error in config.json: %s', e.message) sys.exit(1) logging.info('loading config from %s' % config_path) else: config = {} optlist, args = getopt.getopt(sys.argv[1:], 's:p:k:m:c:6') for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-6': IPv6 = True SERVER = config['server'] PORT = config['server_port'] KEY = config['password'] METHOD = config.get('method', None) PORTPASSWORD = config.get('port_password', None) TIMEOUT = config.get('timeout', 600) if not KEY and not config_path: sys.exit('config not specified, please read https://github.com/clowwindy/shadowsocks') utils.check_config(config) if PORTPASSWORD: if PORT or KEY: logging.warn('warning: port_password should not be used with server_port and password. server_port and password will be ignored') else: PORTPASSWORD = {} PORTPASSWORD[str(PORT)] = KEY encrypt.init_table(KEY, METHOD) if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 for port, key in PORTPASSWORD.items(): server = ThreadingTCPServer((SERVER, int(port)), Socks5Server) server.key, server.method, server.timeout = key, METHOD, int(TIMEOUT) logging.info("starting server at %s:%d" % tuple(server.server_address[:2])) threading.Thread(target=server.serve_forever).start()
NUM_CORES = psutil.cpu_count() COMPUTER_NAME = platform.node() parser = argparse.ArgumentParser(description='') parser.add_argument('-a', '--active', dest='active', type=int, required=False, help='Do not use it!') args = parser.parse_args() ACTIVE_JOBS = args.active if args.active else 0 CONFIG = utils.read_config() utils.check_config( CONFIG=CONFIG, NUM_CORES=NUM_CORES if CONFIG['POLICY'] == 'LOCAL' else None) set_config() LOCK_ACTIVE_JOBS = threading.Lock() print() print('--> Version {}'.format(VERSION)) print('--> Configuration of {}:'.format(COMPUTER_NAME)) for conf in CONFIG: print('\t', conf, '=', CONFIG[conf]) print(end='') while True: checkUpdate() print_status()
from flask import Flask, request, jsonify import utils import logger_module import sys import dblib import libencryption logger = logger_module.setup_logger("secret") if utils.check_config(): print("Starting my super App") logger.debug('Starting my super App') else: print('Cannot start Server as key is not found') logger.debug('Cannot start Server as key is not found') sys.exit("Key is not found ") config = utils.get_config() libencryption.set_key(config["key"]) dblib.set_db_credentials(config["dbconnection"]) app = Flask(__name__) app.config['JSON_SORT_KEYS'] = False app.config['APPLICATION_ROOT'] = '/api' print("\n\n\n") @app.route('/') def index(): logger.debug("Request for testing connection invoked") return 'Cool API is online :)'
def main(): global SERVER, REMOTE_PORT, PORT, KEY, METHOD, LOCAL, IPv6 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') # fix py2exe if hasattr(sys, "frozen") and sys.frozen in \ ("windows_exe", "console_exe"): p = os.path.dirname(os.path.abspath(sys.executable)) os.chdir(p) version = '' try: import pkg_resources version = pkg_resources.get_distribution('shadowsocks').version except: pass print 'shadowsocks %s' % version KEY = None METHOD = None LOCAL = '' IPv6 = False config_path = utils.find_config() optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-c': config_path = value if config_path: logging.info('Loading Config From %s' % config_path) with open(config_path, 'rb') as f: config = json.load(f) #通过判断config.json中是否包含了"server_password"来确定是否启用了多端口 if config.has_key("server_password") == True: #获得"server_password"的长度,得到服务器多端口记录数据 number = len(config["server_password"]) #通过random取一个随机数、来随机分配用哪一条服务器端口密码记录 orientation = random.randint(0, number - 1) server_dict = {} server_dict[u"server"]= config["server_password"][orientation][0] server_dict[u"server_port"] = config["server_password"][orientation][1] server_dict[u"password"] = config["server_password"][orientation][2] server_dict[u"local_port"] = config["local_port"] server_dict[u"method"] = config["method"] server_dict[u"timeout"] = config["timeout"] config = server_dict #print config #else: # print config optlist, args = getopt.getopt(sys.argv[1:], 's:b:p:k:l:m:c:6') for key, value in optlist: if key == '-p': config['server_port'] = int(value) elif key == '-k': config['password'] = value elif key == '-l': config['local_port'] = int(value) elif key == '-s': config['server'] = value elif key == '-m': config['method'] = value elif key == '-b': config['local'] = value elif key == '-6': IPv6 = True SERVER = config['server'] REMOTE_PORT = config['server_port'] PORT = config['local_port'] KEY = config['password'] METHOD = config.get('method', None) LOCAL = config.get('local', '') if not KEY and not config_path: sys.exit('config not specified, please read https://github.com/huaisha1224/ShadowSocks-Client') utils.check_config(config) encrypt.init_table(KEY, METHOD) try: if IPv6: ThreadingTCPServer.address_family = socket.AF_INET6 server = ThreadingTCPServer((LOCAL, PORT), Socks5Server) logging.info("Available Remoto Server %s:%d" %(SERVER, REMOTE_PORT)) logging.info("Starting Local Socks5 Server At %s:%d" % tuple(server.server_address[:2])) server.serve_forever() except socket.error, e: logging.error(e)
items.append(list_item) url = doc.links.get('next') if not url: break plugin.log.debug('Fetching next page') plugin.finish(items, sort_methods=['title', 'dateadded']) @plugin.route('/file') def play_file(): tsc = get_client() url = json.loads(plugin.request.args.get('url')[0]) doc = tsc.stream_url(url) for item in doc.data: if item.type == 'stream_http': return plugin.set_resolved_url({ 'label': item.id, 'path': item.media_url, }) if __name__ == '__main__': if not check_config(): plugin.open_settings() else: plugin.run()