Beispiel #1
0
 def execute(self, arg=None):
     if arg is None: raise InvalidArgumentException()
     upload_file = arg if arg.startswith('/') else '%s%s' % (context.get_lwd(), arg)
     if os.path.exists(upload_file) and os.path.isfile(upload_file):
         context.client.upload_curl(context.get_rwd(), upload_file)
     else:
         raise InvalidArgumentException()
Beispiel #2
0
 def upload_one_file(self, fn):
     upload_file = fn if fn.startswith('/') else '%s%s' % (context.get_lwd(), fn)
     if os.path.exists(upload_file) and os.path.isfile(upload_file):
         print 'upload file: %s ...' % upload_file
         result = context.client.upload_curl(context.get_rwd(), upload_file)
         print 'file saved to: %s !' % result.get('path')
     else:
         print 'no such file!'
Beispiel #3
0
 def get_completer_words(self, target_dir):
     if not tree.local_isabspath(target_dir):
         target_dir = os.path.join(context.get_lwd(), target_dir)
     parent_dir, prefix = tree.local_splitpath(target_dir)
     sub_dirs = filter(lambda x:len(prefix) == 0 or x.startswith(prefix),
                       tree.local_listdir(parent_dir))
     _logger.debug(sub_dirs)
     return map(lambda x:'%s%s' % (x,os.sep), sub_dirs)
Beispiel #4
0
 def execute(self, args=[]):
     target_dir = args[0] if len(args) > 0 else ''
     lwd = context.get_lwd()
     if tree.local_isabspath(target_dir):
         lwd = target_dir
     else:
         lwd = os.path.join(lwd, target_dir)
     lwd = tree.local_abspath(lwd)
     if not lwd.endswith(os.sep):
         lwd += os.sep
     context.set_lwd(lwd)
Beispiel #5
0
 def execute(self, file_id=None):
     if file_id is None:
         raise InvalidArgumentException()
     file_id = int(file_id)
     # 获取文件信息
     file_obj = context.get_file_from_cache(file_id)
     if file_obj is None:
         raise NoSuchRemoteFileException()
     # 获取保存路径
     save_path = os.path.join(context.get_lwd(), file_obj['server_filename'])
     file_req = context.client.get_download_request(file_id)
     curl.download(file_req, save_path)
Beispiel #6
0
 def upload_one_file(self, fn):
     upload_file = fn if fn.startswith(
         '/') else '%s%s' % (context.get_lwd(), fn)
     if os.path.exists(upload_file) and os.path.isfile(upload_file):
         print 'upload file: %s ...' % upload_file
         result = context.client.upload_curl(context.get_rwd(), upload_file)
         if result.get('error_code') > 0:
             print 'upload failed! error code: %d' % result['error_code']
         else:
             print 'file saved to: %s !' % result.get('path')
     else:
         print 'no such file!'
Beispiel #7
0
 def _download_torrent(self, torrent_file, mask=False):
     save_path = context.get_rwd()
     source_path = None
     # 查找种子文件
     torrent_file = os.path.join(context.get_lwd(), torrent_file)
     if os.path.exists(torrent_file):
         if not mask:
             # 上传种子文件
             print 'upload torrent file: %s ...' % torrent_file
             result = context.client.upload(context.get_rwd(), torrent_file)
             source_path = result['path']
         else:
             print 'mask torrent file ...'
             # 混淆bt文件
             torrent_data, name_dict = bt.mask_file(torrent_file)
             # 创建一层目录,作为下载存储目录
             save_path = '%s%s/' % (save_path, name_dict['prefix'])
             _logger.debug('save path: %s' % save_path)
             context.client.create_dir(save_path)
             # 上传混淆后的种子文件
             print 'upload masked torrent ...'
             result = context.client.upload_data(save_path, 'tmp.torrent', torrent_data)
             source_path = result['path']
             # 上传文件名字典
             print 'upload name dictionary ...'
             dict_data = json.dumps(name_dict)
             context.client.upload_data(save_path, 'dictionary.txt', dict_data)
     else:
         print 'no such torrent file!'
         return None
     # 获取种子文件信息
     try:
         print 'query torrent info ...'
         result = context.client.cloud_dl_query_bt_info(source_path)
         bt_info = result.get('torrent_info')
         # 创建bt任务
         task_id = None
         if bt_info is None:
             print 'can\'t get torrent info!'
         else:
             print 'create download for bt ...'
             # 选择种子中的全部文件
             selected_idx = map(lambda x:str(x+1), xrange(0, bt_info['file_count']))
             selected_idx = ','.join(selected_idx)
             # 创建离线下载任务
             result = context.client.cloud_dl_add_bt_task(source_path, selected_idx, bt_info['sha1'], save_path)
             task_id = result['task_id'] if result.has_key('task_id') else None
     except:
         print 'create download task failed ...'
     # 删除种子文件
     print 'delete torrent file ...'
     context.client.delete(json.dumps([source_path]))
     return task_id
Beispiel #8
0
 def execute(self, args):
     save_path = context.get_lwd()
     for file_id in args:
         # 获取文件信息
         file_obj = context.remote_tree.get_file_by_id(file_id)
         if file_obj is None:
             print 'no such file: %s' % file_id
             continue
         if file_obj['isdir'] == 0:
             print 'pull file: %s ...' % file_obj['server_filename']
             self._download_file(file_obj, save_path)
         else:
             print 'pull dir: %s ...' % file_obj['server_filename']
             self._download_dir(file_obj, save_path)
Beispiel #9
0
 def execute(self, arg=None):
     if not arg: arg = '/'
     lwd = context.get_lwd()
     if arg.startswith('/'):
         lwd = arg
     else:
         lwd = '%s%s' % (lwd, arg)
         lwd = os.path.abspath(lwd)
     if not lwd.endswith('/'):
         lwd += '/'
     # 设置本地工作目录
     if os.path.exists(lwd):
         context.set_lwd(lwd)
     else:
         print 'No such path!'
Beispiel #10
0
 def _download_file(self, file_obj):
     # 获取保存路径
     save_path = os.path.join(context.get_lwd(), file_obj['server_filename'])
     download_req = context.client.get_download_request(file_obj['fs_id'])
     # 调用用户配置的下载器进行下载
     dler = config.get_downloader()
     if dler in ['aria', 'aria2c']:
         from baidupan.downloader import aria2c
         aria2c.download(download_req, save_path)
     elif dler == 'wget':
         from baidupan.downloader import wget
         wget.download(download_req, save_path)
     else:
         # 默认情况下使用curl
         from baidupan.downloader import curl
         curl.download(download_req, save_path)
Beispiel #11
0
 def get_completer_words(self, prefix):
     # 获取要寻址的路径
     if prefix.startswith('/'):
         lwd = prefix
     else:
         if prefix is None: prefix = ''
         lwd = '%s%s' % (context.get_lwd(), prefix)
     # 处理路径中的相对路径
     if lwd.endswith('/'):
         lwd = os.path.abspath(lwd) + '/'
     else:
         lwd = os.path.abspath(lwd)
     # 拆分出父目录和子目录前缀
     parent_dir, sub_prefix = os.path.split(lwd)
     # 列出父目录下所有目录
     sub_dirs = os.listdir(parent_dir)
     # 列出所有符合前缀的子目录
     sub_dirs = filter(lambda x:x.startswith(sub_prefix), sub_dirs)
     return map(lambda x:'%s/' % x, sub_dirs)
Beispiel #12
0
 def execute(self, arg=None):
     print 'remote: %s' % context.get_rwd()
     print 'local : %s' % context.get_lwd()
Beispiel #13
0
 def execute(self, args):
     print 'remote: %s' % context.get_rwd()
     print 'local : %s' % context.get_lwd()