コード例 #1
0
 def __init__(self, src_path, dst_path, filename=None, size=(300, 200)):
     super().__init__()
     self.thumb_name = None
     self.thumb_name = thumb_name(src_path)
     self.src_path = src_path
     self.size = size
     self.cache_path = pure_windows_path(cache_path, dst_path.strip('/'), thumb_dir)
     self.thumb_path = pure_windows_path(self.cache_path, self.thumb_name)
     self.ok = False
コード例 #2
0
    def thumbnail_drop(self, _, src_path):
        src_path = src_path.decode(encoding='UTF-8', errors='strict')
        self.thumbnail = path.split(src_path)[1]
        self.pic_name = f'{self.filename}.jpg'
        cache_pic = pure_windows_path(cache_path, self.thumbnail)
        try:
            if path.exists(cache_pic):
                remove(cache_pic)
            if not path.exists(cache_path):
                makedirs(cache_path)
            copyfile(src_path, cache_pic)

        except Exception as ex:
            self.popup.title = f'Failed to generate thumbnail {ex}'
            return

        th = ThumbnailGenerator(src_path=cache_pic, dst_path='')
        th.start()
        th.join()
        if th.ok:
            self.popup.title = 'Thumbnail generated'
            cache_pic = pure_windows_path(cache_path,
                                          self.destination.strip('/'),
                                          thumb_dir, self.pic_name)
            print('CACHE PIC', th.thumb_path, cache_pic)
            try:
                if not path.exists(dst_path(cache_pic)):
                    makedirs(dst_path(cache_pic))

                if path.exists(cache_pic):
                    remove(cache_pic)

                copyfile(th.thumb_path, cache_pic)
                self.sftp.put(cache_pic,
                              pure_posix_path(self.destination, thumb_dir,
                                              self.pic_name),
                              preserve_mtime=True)
            except Exception as ex:
                self.popup.title = f'Failed to upload thumbnail for {self.filename} {type(ex)}'
                ex_log(f'Failed to upload thumbnail for {self.filename} {ex}')
            else:
                self.popup.title = 'Thumbnail uploaded succesfully'
                self.originator.bind_external_drop()

                def dismiss_popup(_):
                    self.popup.dismiss()
                    self.originator.refresh_thumbnail(self.filename)

                Clock.schedule_once(dismiss_popup, .8)
                Window.unbind(on_dropfile=self.thumbnail_drop)
        else:
            self.popup.title = 'Failed to upload thumbnail'
コード例 #3
0
 def __init__(self, manager, sftp, data):
     super().__init__()
     self.manager = manager
     self.src_path = data['src_path']
     self.dst_path = pure_windows_path(cache_path,
                                       data['dst_path'].strip('/'),
                                       thumb_dir)
     self.thumbnails = data['thumbnails']
     self.callback = data['callback']
     self.sftp = sftp
コード例 #4
0
    def local_walk(self, task):
        src_path = task['src_path']
        dst_path = task['dst_path']
        local_base, dir_to_walk = os.path.split(src_path)

        for root, dirs, files in os.walk(src_path):
            relative_path = root.replace(local_base, '')[1:]
            relative_path = pure_posix_path(dst_path,
                                            *relative_path.split('\\'))

            for file in files:
                self.put_transfer({
                    'type': 'upload',
                    'dir': False,
                    'src_path': pure_windows_path(root, file),
                    'dst_path': relative_path,
                    'thumbnails': task['thumbnails'],
                    'settings': self.upload_settings
                })
            if dirs:
                empty_dirs = []
                for _dir in dirs:
                    if not len(os.listdir(pure_windows_path(root, _dir))):
                        empty_dirs.append(_dir)
                if empty_dirs:
                    self.put_transfer({
                        'type': 'upload',
                        'dir': True,
                        'dst_path': relative_path,
                        'name': empty_dirs,
                        'thumbnails': task['thumbnails'],
                        'settings': self.upload_settings
                    })

        self.put_transfer({
            'type': 'upload',
            'dir': True,
            'dst_path': dst_path,
            'name': [dir_to_walk],
            'thumbnails': task['thumbnails'],
            'settings': self.upload_settings
        })
コード例 #5
0
ファイル: open.py プロジェクト: Patryk-Foryszewski/RemoteDir
    def __init__(self, data, manager, sftp):
        super().__init__()
        self.cache_path = cache_path
        self.data = data
        self.src_path = data['src_path']
        self.file_name = os.path.split(self.src_path)[1]
        self.dst_path = pure_windows_path(cache_path, self.file_name)
        self.data['dst_path'] = os.path.join(cache_path, self.file_name)
        self.manager = manager
        self.sftp = sftp
        self.m_time = None
        self.check_event = None
        self.file = None
        self.bar = None

        self.thumbnails = thumbnails()
        self.popup = None
        self.bar_popup = None
コード例 #6
0
    def run(self):
        for thumbnail in self.thumbnails:
            try:
                src = pure_posix_path(self.src_path, thumbnail)
                if not local_path_exists(self.dst_path):
                    makedirs(self.dst_path)
                self.sftp.get(src,
                              pure_windows_path(self.dst_path, thumbnail),
                              preserve_mtime=True)

            except FileNotFoundError:
                pass

            except Exception as ex:
                ex_log(f'Failed to download thumbnail {str(ex)}')

        self.manager.thread_queue.put('.')
        self.manager.sftp_queue.put(self.sftp)
        self.manager.next_transfer()
        self.callback()
コード例 #7
0
 def test_pure_windows_path(self):
     seeds = ('C:/', 'Users', 'User', 'AppData', 'RemoteDir', 'my remote',
              'config.ini')
     result = common.pure_windows_path(*seeds)
     self.assertEqual(
         result, r'C:\Users\User\AppData\RemoteDir\my remote\config.ini')