示例#1
0
        def on_list_task(info, error=None):
            self.loading_spin.stop()
            self.loading_spin.hide()
            if not info:
                self.app.toast(_('Network error, info is empty'))
            if error or not info:
                logger.error('CloudPage.load: %s, %s' % (info, error))
                return
            tasks = info['task_info']
            for task in tasks:
                self.liststore.append([
                    task['task_id'],
                    task['task_name'],
                    task['save_path'],
                    task['source_url'],
                    0,
                    0,
                    int(task['status']),
                    0,
                    '0',
                    gutil.escape(task['save_path'])
                ])
            self.scan_tasks()

            nonlocal start
            start = start + len(tasks)
            if info['total'] > start:
                gutil.async_call(pcs.cloud_list_task, self.app.cookie,
                                 self.app.tokens, start, callback=on_list_task)
示例#2
0
 def add_file_task(self, source_path, dir_name):
     '''创建新的上传任务'''
     row = self.get_task_db(source_path)
     if row:
         print('Task is already in uploading schedule, do nothing.')
         return
     source_dir, filename = os.path.split(source_path)
     
     path = os.path.join(dir_name, filename)
     size = os.path.getsize(source_path)
     total_size = util.get_human_size(size)[0]
     task = [
         filename,
         source_path,
         path,
         size,
         0,
         State.WAITING,
         StateNames[State.WAITING],
         '0 / {0}'.format(total_size),
         0,
         gutil.escape(path)
         ]
     row_id = self.add_task_db(task)
     task.insert(0, row_id)
     self.liststore.append(task)
示例#3
0
        def on_list_task(info, error=None):
            print('on list task() --', info)
            if error or not info:
                print('Error: failed to list cloud tasks')
                return
            if 'error_code' in info and info['error_code'] != 0:
                print('Error: ', info['error_msg'])
                print(info)
                return
            tasks = info['task_info']
            for task in tasks:
                self.liststore.append([
                    task['task_id'],
                    task['task_name'],
                    task['save_path'],
                    task['source_url'],
                    0,
                    0,
                    int(task['status']),
                    0,
                    '0',
                    gutil.escape(
                        os.path.join(task['save_path'], task['task_name'])),
                    ])
            self.scan_tasks()

            nonlocal start
            start = start + len(tasks)
            if info['total'] > start:
                gutil.async_call(
                    pcs.cloud_list_task, self.app.cookie, self.app.tokens,
                    start, callback=on_list_task)
示例#4
0
 def add_file_task(self, source_path, dir_name):
     '''创建新的上传任务'''
     row = self.get_task_db(source_path)
     source_dir, filename = os.path.split(source_path)
     
     path = os.path.join(dir_name, filename)
     size = os.path.getsize(source_path)
     total_size = util.get_human_size(size)[0]
     tooltip = gutil.escape(_('From {0}\nTo {1}').format(source_path, path))
     if size < 2 ** 27:           # 128M 
         threshold = 2 ** 17      # 128K
     elif size < 2 ** 29:         # 512M
         threshold =  2 ** 19     # 512K
     elif size < 10 * (2 ** 30):  # 10G
         threshold = math.ceil(size / 1000)
     else:
         self.app.toast(_('{0} is too large to upload (>10G).').format(path))
         return
     task = [
         filename,
         source_path,
         path,
         size,
         0,
         State.WAITING,
         StateNames[State.WAITING],
         '0 / {0}'.format(total_size),
         0,
         tooltip,
         threshold,
     ]
     row_id = self.add_task_db(task)
     task.insert(0, row_id)
     self.liststore.append(task)
示例#5
0
    def display_files(self, pcs_files):
        '''重新格式化一下文件列表, 去除不需要的信息

        这一操作主要是为了便于接下来的查找工作.
        文件的path都被提取出来, 然后放到了一个list中.
        '''
        tree_iters = []
        for pcs_file in pcs_files:
            path = pcs_file['path']
            pixbuf, type_ = self.app.mime.get(path, pcs_file['isdir'],
                                              icon_size=self.ICON_SIZE)
            name = os.path.split(path)[NAME_COL]
            tooltip = gutil.escape(name)
            size = pcs_file.get('size', 0)
            if pcs_file['isdir']:
                human_size = '--'
            else:
                human_size = util.get_human_size(pcs_file['size'])[0]
            mtime = pcs_file.get('server_mtime', 0)
            human_mtime = time.ctime(mtime)
            tree_iter = self.liststore.append([
                pixbuf, name, path, tooltip, size, human_size,
                pcs_file['isdir'], mtime, human_mtime, type_,
                json.dumps(pcs_file)
            ])
            tree_iters.append(tree_iter)
        cache_path = Config.get_cache_path(self.app.profile['username'])
        gutil.async_call(gutil.update_liststore_image, self.liststore,
                         tree_iters, PIXBUF_COL, pcs_files, cache_path,
                         self.ICON_SIZE)
示例#6
0
    def display_files(self, pcs_files):
        '''重新格式化一下文件列表, 去除不需要的信息

        这一操作主要是为了便于接下来的查找工作.
        文件的path都被提取出来, 然后放到了一个list中.
        '''
        tree_iters = []
        for pcs_file in pcs_files:
            path = pcs_file['path']
            pixbuf, type_ = self.app.mime.get(path,
                                              pcs_file['isdir'],
                                              icon_size=self.ICON_SIZE)
            name = os.path.split(path)[NAME_COL]
            tooltip = gutil.escape(name)
            size = pcs_file.get('size', 0)
            if pcs_file['isdir']:
                human_size = '--'
            else:
                human_size = util.get_human_size(pcs_file['size'])[0]
            mtime = pcs_file.get('server_mtime', 0)
            human_mtime = time.ctime(mtime)
            tree_iter = self.liststore.append([
                pixbuf, name, path, tooltip, size, human_size,
                pcs_file['isdir'], mtime, human_mtime, type_,
                json.dumps(pcs_file)
            ])
            tree_iters.append(tree_iter)
        cache_path = Config.get_cache_path(self.app.profile['username'])
        gutil.async_call(gutil.update_liststore_image, self.liststore,
                         tree_iters, PIXBUF_COL, pcs_files, cache_path,
                         self.ICON_SIZE)
示例#7
0
        def on_list_task(info, error=None):
            self.loading_spin.stop()
            self.loading_spin.hide()
            if error or not info:
                return
            if 'error_code' in info and info['error_code'] != 0:
                return
            tasks = info['task_info']
            for task in tasks:
                self.liststore.append([
                    task['task_id'],
                    task['task_name'],
                    task['save_path'],
                    task['source_url'],
                    0,
                    0,
                    int(task['status']),
                    0,
                    '0',
                    gutil.escape(task['save_path'])
                    ])
            self.scan_tasks()

            nonlocal start
            start = start + len(tasks)
            if info['total'] > start:
                gutil.async_call(
                    pcs.cloud_list_task, self.app.cookie, self.app.tokens,
                    start, callback=on_list_task)
示例#8
0
    def append_filelist(self, infos, error=None):
        self.loading_spin.stop()
        self.loading_spin.hide()
        if error or not infos or infos['errno'] != 0:
            return
        for pcs_file in infos['list']:
            self.filelist.append(pcs_file)
            path = pcs_file['path']

            icon_name = self.app.mime.get_icon_name(path, pcs_file['isdir'])
            tooltip = gutil.escape(path)
            if pcs_file['isdir'] or 'size' not in pcs_file:
                size = 0
                humansize = ''
            else:
                size = pcs_file['size']
                humansize = util.get_human_size(size)[0]
            remaining_days = util.get_delta_days(
                    int(pcs_file['server_mtime']), time.time())
            remaining_days = str(MAX_DAYS - remaining_days) + ' days'
            self.liststore.append([
                icon_name,
                pcs_file['server_filename'],
                path,
                str(pcs_file['fs_id']),
                tooltip,
                size,
                humansize,
                time.ctime(pcs_file['server_mtime']),
                remaining_days,
                ])
示例#9
0
        def on_list_task(info, error=None):
            self.loading_spin.stop()
            self.loading_spin.hide()
            if error or not info:
                return
            if "error_code" in info and info["error_code"] != 0:
                return
            tasks = info["task_info"]
            for task in tasks:
                self.liststore.append(
                    [
                        task["task_id"],
                        task["task_name"],
                        task["save_path"],
                        task["source_url"],
                        0,
                        0,
                        int(task["status"]),
                        0,
                        "0",
                        gutil.escape(os.path.join(task["save_path"], task["task_name"])),
                    ]
                )
            self.scan_tasks()

            nonlocal start
            start = start + len(tasks)
            if info["total"] > start:
                gutil.async_call(pcs.cloud_list_task, self.app.cookie, self.app.tokens, start, callback=on_list_task)
示例#10
0
 def upload_file(self, source_path, dir_name):
     '''上传一个文件'''
     row = self.get_task_db(source_path)
     source_dir, filename = os.path.split(source_path)
     
     path = os.path.join(dir_name, filename)
     size = os.path.getsize(source_path)
     total_size = util.get_human_size(size)[0]
     tooltip = gutil.escape(_('From {0}\nTo {1}').format(source_path, path))
     if size < 2 ** 27:           # 128M 
         threshold = 2 ** 17      # 128K
     elif size < 2 ** 29:         # 512M
         threshold =  2 ** 19     # 512K
     elif size < 10 * (2 ** 30):  # 10G
         threshold = math.ceil(size / 1000)
     else:
         self.app.toast(_('{0} is too large to upload (>10G).').format(path))
         return
     task = [
         filename,
         source_path,
         path,
         size,
         0,
         State.WAITING,
         StateNames[State.WAITING],
         '0 / {0}'.format(total_size),
         0,
         tooltip,
         threshold,
     ]
     row_id = self.add_task_db(task)
     task.insert(0, row_id)
     self.liststore.append(task)
示例#11
0
        def on_list_task(info, error=None):
            self.loading_spin.stop()
            self.loading_spin.hide()
            if not info:
                self.app.toast(_('Network error, info is empty'))
            if error or not info:
                logger.error('CloudPage.load: %s, %s' % (info, error))
                return
            tasks = info['task_info']
            for task in tasks:
                self.liststore.append([
                    task['task_id'], task['task_name'], task['save_path'],
                    task['source_url'], 0, 0,
                    int(task['status']), 0, '0',
                    gutil.escape(task['save_path'])
                ])
            self.scan_tasks()

            nonlocal start
            start = start + len(tasks)
            if info['total'] > start:
                gutil.async_call(pcs.cloud_list_task,
                                 self.app.cookie,
                                 self.app.tokens,
                                 start,
                                 callback=on_list_task)
示例#12
0
    def append_filelist(self, infos, error=None):
        self.loading_spin.stop()
        self.loading_spin.hide()
        if error or not infos or infos['errno'] != 0:
            return
        for pcs_file in infos['list']:
            self.filelist.append(pcs_file)
            path = pcs_file['path']

            icon_name = self.app.mime.get_icon_name(path, pcs_file['isdir'])
            tooltip = gutil.escape(path)
            if pcs_file['isdir'] or 'size' not in pcs_file:
                size = 0
                humansize = ''
            else:
                size = pcs_file['size']
                humansize = util.get_human_size(size)[0]
            remaining_days = util.get_delta_days(int(pcs_file['server_mtime']),
                                                 time.time())
            remaining_days = str(MAX_DAYS - remaining_days) + ' days'
            self.liststore.append([
                icon_name,
                pcs_file['server_filename'],
                path,
                str(pcs_file['fs_id']),
                tooltip,
                size,
                humansize,
                time.ctime(pcs_file['server_mtime']),
                remaining_days,
            ])
示例#13
0
    def display_files(self, pcs_files):
        '''重新格式化一下文件列表, 去除不需要的信息

        这一操作主要是为了便于接下来的查找工作.
        文件的path都被提取出来, 然后放到了一个list中.
        '''
        tree_iters = []

        md5Dict = {}
        for pcs_file in pcs_files:
            md5 = pcs_file.get('md5', "")
            if md5 in md5Dict:
                md5Dict[md5] += 1
            else:
                md5Dict[md5] = 1

        for pcs_file in pcs_files:
            path = pcs_file['path']
            pixbuf, type_ = self.app.mime.get(path, pcs_file['isdir'],
                                              icon_size=self.ICON_SIZE)
            name = os.path.split(path)[NAME_COL]
            tooltip = gutil.escape(name)
            size = pcs_file.get('size', 0)
            md5 = pcs_file.get('md5', "")

            if pcs_file['isdir']:
                human_size = '--'
                foregroundColor = "#3a5d96"
                count = 0
            else:
                human_size = util.get_human_size(pcs_file['size'])[0]
                count = md5Dict[md5]
                if count > 1:
                    foregroundColor = "#ff5050"
                else:
                    foregroundColor = "#2e2e2e"
            mtime = pcs_file.get('server_mtime', 0)
            human_mtime = time.ctime(mtime)
            fid = pcs_file.get('fs_id', 0)

            tree_iter = self.liststore.append([
                pixbuf, name, path, tooltip, size, human_size,
                pcs_file['isdir'], mtime, human_mtime, type_,
                json.dumps(pcs_file), fid, md5, foregroundColor, count
            ])
            tree_iters.append(tree_iter)

        cache_path = Config.get_cache_path(self.app.profile['username'])
        gutil.async_call(gutil.update_liststore_image, self.liststore,
                         tree_iters, PIXBUF_COL, pcs_files, cache_path,
                         self.ICON_SIZE)
示例#14
0
 def add_task(self, pcs_file, dirname=''):
     '''加入新的下载任务'''
     if pcs_file['isdir']:
         return
     fs_id = str(pcs_file['fs_id'])
     row = self.get_row_by_fsid(fs_id)
     if row:
         self.app.toast(_('Task exists: {0}').format(
                        pcs_file['server_filename']))
         # 如果文件已下载完成, 就直接尝试用本地程序打开
         if row[STATE_COL] == State.FINISHED:
             self.launch_app(fs_id)
         return
     if not dirname:
         dirname = self.app.profile['save-dir']
     save_dir = os.path.dirname(
             os.path.join(dirname, pcs_file['path'][1:]))
     save_name = pcs_file['server_filename']
     human_size = util.get_human_size(pcs_file['size'])[0]
     tooltip = gutil.escape(_('From {0}\nTo {1}').format(pcs_file['path'],
                                                         save_dir))
     task = (
         pcs_file['server_filename'],
         pcs_file['path'],
         fs_id,
         pcs_file['size'],
         0,
         '',  # pcs['dlink' removed in new version.
         pcs_file['isdir'],
         save_name,
         save_dir,
         State.WAITING,
         StateNames[State.WAITING],
         human_size,
         0,
         tooltip,
     )
     self.liststore.append(task)
     self.add_task_db(task)
     self.scan_tasks()
示例#15
0
 def add_task(self, pcs_file):
     '''加入新的下载任务'''
     if pcs_file['isdir']:
         return
     # 如果已经存在于下载列表中, 就忽略.
     fs_id = str(pcs_file['fs_id'])
     row = self.get_row_by_fsid(fs_id)
     if row:
         if row[STATE_COL] == State.FINISHED:
             self.launch_app(fs_id)
         elif row[STATE_COL] not in RUNNING_STATES:
             row[STATE_COL] = State.WAITING
         self.scan_tasks()
         return
     saveDir = os.path.split(
             self.app.profile['save-dir'] + pcs_file['path'])[0]
     saveName = pcs_file['server_filename']
     human_size = util.get_human_size(pcs_file['size'])[0]
     tooltip = gutil.escape(
             _('From {0}\nTo {1}').format(pcs_file['path'], saveDir))
     task = (
         pcs_file['server_filename'],
         pcs_file['path'],
         fs_id,
         pcs_file['size'],
         0,
         '',  # pcs['dlink' removed in new version.
         pcs_file['isdir'],
         saveName,
         saveDir,
         State.WAITING,
         StateNames[State.WAITING],
         human_size,
         0,
         tooltip,
         )
     self.liststore.append(task)
     self.add_task_db(task)
     self.scan_tasks()
示例#16
0
 def add_task(self, pcs_file, dirname=''):
     '''加入新的下载任务'''
     if pcs_file['isdir']:
         return
     fs_id = str(pcs_file['fs_id'])
     row = self.get_row_by_fsid(fs_id)
     if row:
         self.app.toast(
             _('Task exists: {0}').format(pcs_file['server_filename']))
         # 如果文件已下载完成, 就直接尝试用本地程序打开
         if row[STATE_COL] == State.FINISHED:
             self.launch_app(fs_id)
         return
     if not dirname:
         dirname = self.app.profile['save-dir']
     save_dir = os.path.dirname(os.path.join(dirname, pcs_file['path'][1:]))
     save_name = pcs_file['server_filename']
     human_size = util.get_human_size(pcs_file['size'])[0]
     tooltip = gutil.escape(
         _('From {0}\nTo {1}').format(pcs_file['path'], save_dir))
     task = (
         pcs_file['server_filename'],
         pcs_file['path'],
         fs_id,
         pcs_file['size'],
         0,
         '',  # pcs['dlink' removed in new version.
         pcs_file['isdir'],
         save_name,
         save_dir,
         State.WAITING,
         StateNames[State.WAITING],
         human_size,
         0,
         tooltip,
     )
     self.liststore.append(task)
     self.add_task_db(task)
     self.scan_tasks()
示例#17
0
 def add_task(self, pcs_file):
     '''加入新的下载任务'''
     if pcs_file['isdir']:
         return
     # 如果已经存在于下载列表中, 就忽略.
     fs_id = str(pcs_file['fs_id'])
     row = self.get_row_by_fsid(fs_id)
     if row:
         if row[STATE_COL] == State.FINISHED:
             self.launch_app(fs_id)
         elif row[STATE_COL] not in RUNNING_STATES:
             row[STATE_COL] = State.WAITING
         self.scan_tasks()
         return
     saveDir = os.path.split(
             self.app.profile['save-dir'] + pcs_file['path'])[0]
     saveName = pcs_file['server_filename']
     human_size = util.get_human_size(pcs_file['size'])[0]
     tooltip = gutil.escape(
             _('From {0}\nTo {1}').format(pcs_file['path'], saveDir))
     task = (
         pcs_file['server_filename'],
         pcs_file['path'],
         fs_id,
         pcs_file['size'],
         0,
         pcs_file['dlink'],
         pcs_file['isdir'],
         saveName,
         saveDir,
         State.WAITING,
         StateNames[State.WAITING],
         human_size,
         0,
         tooltip,
         )
     self.liststore.append(task)
     self.add_task_db(task)
     self.scan_tasks()
示例#18
0
    def append_filelist(self, info, error=None):
        self.loading_spin.stop()
        self.loading_spin.hide()
        if not info:
            self.app.toast(_('Network error'))
        elif info.get('errno', -1) != 0 and info.get('errno', -1) != 31034:
            self.app.toast(info.get('error_msg', _('Network error')))

        if error or not info or info.get('errno', -1) != 0:
            if error or not info or info.get('errno', -1) != 31034:
                logger.error('TrashPage.append_filelist: %s, %s' %
                             (info, error))
            return
        for pcs_file in info['list']:
            self.filelist.append(pcs_file)
            path = pcs_file['path']

            icon_name = self.app.mime.get_icon_name(path, pcs_file['isdir'])
            tooltip = gutil.escape(path)
            if pcs_file['isdir'] or 'size' not in pcs_file:
                size = 0
                humansize = ''
            else:
                size = pcs_file['size']
                humansize = util.get_human_size(size)[0]
            remaining_days = util.get_delta_days(int(pcs_file['server_mtime']),
                                                 time.time())
            remaining_days = str(MAX_DAYS - remaining_days) + ' days'
            self.liststore.append([
                icon_name,
                pcs_file['server_filename'],
                path,
                str(pcs_file['fs_id']),
                tooltip,
                size,
                humansize,
                time.ctime(pcs_file['server_mtime']),
                remaining_days,
            ])
示例#19
0
    def append_filelist(self, info, error=None):
        self.loading_spin.stop()
        self.loading_spin.hide()
        if not info:
            self.app.toast(_('Network error'))
        elif info.get('errno', -1) != 0:
            self.app.toast(info.get('error_msg', _('Network error')))
        if error or not info or info.get('errno', -1) != 0:
            logger.error('TrashPage.append_filelist: %s, %s' % (info, error))
            return
        for pcs_file in info['list']:
            self.filelist.append(pcs_file)
            path = pcs_file['path']

            icon_name = self.app.mime.get_icon_name(path, pcs_file['isdir'])
            tooltip = gutil.escape(path)
            if pcs_file['isdir'] or 'size' not in pcs_file:
                size = 0
                humansize = ''
            else:
                size = pcs_file['size']
                humansize = util.get_human_size(size)[0]
            remaining_days = util.get_delta_days(int(pcs_file['server_mtime']),
                                                 time.time())
            remaining_days = str(MAX_DAYS - remaining_days) + ' days'
            self.liststore.append([
                icon_name,
                pcs_file['server_filename'],
                path,
                str(pcs_file['fs_id']),
                tooltip,
                size,
                humansize,
                time.ctime(pcs_file['server_mtime']),
                remaining_days,
            ])
示例#20
0
 def load_tasks_from_db(self):
     sql = 'SELECT * FROM tasks'
     req = self.cursor.execute(sql)
     for task in req:
         self.liststore.append(task + (gutil.escape(task[PATH_COL]), ))