Exemplo n.º 1
0
    def get_local_files (self, channels):
        downloads_dir = self.config.config['downloads']

        files = []
        for channel in channels:
            if '..' in channel:
                continue

            dir_fp = os.path.join (downloads_dir, channel)

            if not os.path.exists (dir_fp):
                continue
            if not os.path.isdir (dir_fp):
                continue

            for f in os.listdir (dir_fp):
                if f[0] in '.#~':
                    continue

                fname      = os.path.join (channel, f)
                fname_fp   = os.path.join (dir_fp, f)
                fname_size = os.path.getsize(fname_fp)

                # No dirs within channels
                if not os.path.isfile (fname_fp):
                    continue

                utils.set_md5_attr (fname_fp, force=False)
                fname_md5 = xattr.getxattr (fname_fp, 'md5')

                files.append ({'path': fname, 'size': fname_size, 'md5': fname_md5})

        return files
Exemplo n.º 2
0
    def get_local_files(self, channels):
        downloads_dir = self.config.config['downloads']

        files = []
        for channel in channels:
            if '..' in channel:
                continue

            dir_fp = os.path.join(downloads_dir, channel)

            if not os.path.exists(dir_fp):
                continue
            if not os.path.isdir(dir_fp):
                continue

            for f in os.listdir(dir_fp):
                if f[0] in '.#~':
                    continue

                fname = os.path.join(channel, f)
                fname_fp = os.path.join(dir_fp, f)
                fname_size = os.path.getsize(fname_fp)

                utils.set_md5_attr(fname_fp)
                fname_md5 = xattr.getxattr(fname_fp, 'md5')

                files.append({
                    'path': fname,
                    'size': fname_size,
                    'md5': fname_md5
                })

        return files
Exemplo n.º 3
0
    def execute (self):
        op = self._build_operation ('download file', {'channel': self.channel, 'file': self.filename})

        def progress(download_t, download_d, upload_t, upload_d):
            self.download_t = download_t
            self.download_d = download_d
            self.upload_t   = upload_t
            self.upload_d   = upload_d

            if self.callback_step:
                self.callback_step (self.filename, download_t, download_d)

        # Prepare final file
        #
        out_dir = os.path.join (self.download_dir, self.channel)
        if not os.path.exists (out_dir):
            os.makedirs (out_dir, 0700)

        out_fullpath = os.path.join (out_dir, self.filename)
        out_f = open (out_fullpath, 'w+')

        # Decrypt
        #
        p = self.keys.decrypt_popen (stdin  = subprocess.PIPE,
                                     stdout = out_f)

        # Handle download
        conn = self._get_url_handler (op)
        conn.setopt (pycurl.NOPROGRESS, 0)
        conn.setopt (pycurl.PROGRESSFUNCTION, progress)
        conn.setopt (pycurl.WRITEFUNCTION, p.stdin.write)
        conn.perform()

        if self.callback_finished:
            self.callback_finished (self)

        # Clean up
        conn.close()
        p.communicate()

        # Set file attributes
        utils.set_md5_attr (out_fullpath, force=True)