def init(): # 解析运行参数 args = util.parser_arguments(sys.argv[1:]) log_level = logging.DEBUG if args.get('debug') else logging.ERROR # 设置日志级别 logging.basicConfig(level=log_level, stream=sys.stdout, format='%(levelname)s %(name)s - %(message)s') _data[_RWD] = '/' _data[_LWD] = config.get_localhome() # 标记为活动 global alive alive = True # 初始化client import cookielib from baidupan import api global cookie_file, cookie_jar, client cookie_file = util.get_data_file('.baidupan.cookie') cookie_jar = cookielib.MozillaCookieJar(cookie_file) if os.path.exists(cookie_file): cookie_jar.load() client = api.BaiduPanClient(cookie_jar, util.vcode_handler)
def init(args): # 设置日志级别 debug_mode = args.debug log_file = file(os.path.join(os.getcwd(), 'debug.log'), 'w') if debug_mode else sys.stderr log_level = logging.DEBUG if debug_mode else logging.ERROR logging.basicConfig( level=log_level, stream=log_file, format='%(asctime)s %(levelname)s %(name)s - %(message)s') # 初始化数据 _data['alive'] = True _data[_RWD] = '/' # 本地工作目录 lwd = args.local_dir if lwd and os.path.exists(lwd): lwd = os.path.abspath(lwd) else: lwd = config.get_localhome() if not lwd.endswith(os.sep): lwd += os.sep _data[_LWD] = lwd # cookie文件 global cookie_file # cookie_file = args.get('cookie') # if cookie_file: # cookie_file = os.path.abspath(cookie_file) # else: cookie_file = util.get_data_file('.baidupan.cookie') # 初始化client import cookielib from baidupan import api, tree global cookie_jar, client cookie_jar = cookielib.MozillaCookieJar(cookie_file) if os.path.exists(cookie_file): cookie_jar.load() client = api.BaiduPanClient(cookie_jar, util.ascii_vcode_handler) # 初始化远程文件树 global remote_tree remote_tree = tree.RemoteTree(client)
def init(args): # 设置日志级别 debug_mode = args.debug log_file = file(os.path.join(os.getcwd(), 'debug.log'), 'w') if debug_mode else sys.stderr log_level = logging.DEBUG if debug_mode else logging.ERROR logging.basicConfig(level=log_level, stream=log_file, format='%(asctime)s %(levelname)s %(name)s - %(message)s') # 初始化数据 _data['alive'] = True _data[_RWD] = '/' # 本地工作目录 lwd = args.local_dir if lwd and os.path.exists(lwd): lwd = os.path.abspath(lwd) else: lwd = config.get_localhome() if not lwd.endswith(os.sep): lwd += os.sep _data[_LWD] = lwd # cookie文件 global cookie_file # cookie_file = args.get('cookie') # if cookie_file: # cookie_file = os.path.abspath(cookie_file) # else: cookie_file = util.get_data_file('.baidupan.cookie') # 初始化client import cookielib from baidupan import api, tree global cookie_jar, client cookie_jar = cookielib.MozillaCookieJar(cookie_file) if os.path.exists(cookie_file): cookie_jar.load() client = api.BaiduPanClient(cookie_jar, util.ascii_vcode_handler) # 初始化远程文件树 global remote_tree remote_tree = tree.RemoteTree(client)
''' Created on 2014/07/13 @author: deadblue ''' import os from baidupan import util import pickle _DOWNLOADER = 'downloader' _DOWNLOADER_DEFAULT = 'curl' _LOCALHOME = 'localhome' _LOCALHOME_DEFAULT = '%s%s' % (os.getcwd(), os.sep) _config_file = util.get_data_file('.baidupan.config') class _Config(): def __init__(self): self._data = {} def load(self): if os.path.exists(_config_file): fp = open(_config_file, 'r') self._data = pickle.load(fp) fp.close() def save(self): fp = open(_config_file, 'w') pickle.dump(self._data, fp) fp.close() def get(self, name, def_value=None): return self._data.get(name, def_value)
''' Created on 2014/07/13 @author: deadblue ''' import os from baidupan import util import pickle _DOWNLOADER = 'downloader' _DOWNLOADER_DEFAULT = 'curl' _LOCALHOME = 'localhome' _LOCALHOME_DEFAULT = '%s%s' % (os.getcwd(), os.sep) _config_file = util.get_data_file('.baidupan.config') class _Config(): def __init__(self): self._data = {} def load(self): if os.path.exists(_config_file): fp = open(_config_file, 'r') self._data = pickle.load(fp) fp.close() def save(self): fp = open(_config_file, 'w') pickle.dump(self._data, fp)