Beispiel #1
0
    def _get_files(self):
        all_files, res = [], SortedDict()
        for root, dirs, files in os.walk(self.dest):
            for filename in dirs + files:
                all_files.append([os.path.join(root, filename), filename])

        for path, filename in sorted(all_files):
            short = path[len(self.dest) + 1:]
            mime, encoding = mimetypes.guess_type(filename)
            binary = self.is_binary(mime, filename)
            # TODO: handling for st.a.m.o will be going in here
            url = reverse('files.list', args=[self.file.id, short])
            directory = os.path.isdir(path)
            res[short] = {
                'full': path,
                'filename': filename,
                'short': short,
                'directory': directory,
                'url': url,
                'binary': binary,
                'depth': short.count(os.sep),
                'modified': os.stat(path)[stat.ST_MTIME],
                'mimetype': mime or 'application/octet-stream',
                'encoding': encoding,
                'md5': get_md5(path) if not directory else '',
                'parent': '/'.join(short.split(os.sep)[:-1])
            }
        return res
Beispiel #2
0
    def _get_files(self):
        all_files, res = [], SortedDict()

        # Not using os.path.walk so we get just the right order.

        def iterate(path):
            path_dirs, path_files = storage.listdir(path)
            for dirname in sorted(path_dirs):
                full = os.path.join(path, dirname)
                all_files.append(full)
                iterate(full)

            for filename in sorted(path_files):
                full = os.path.join(path, filename)
                all_files.append(full)

        iterate(self.dest)

        for path in all_files:
            filename = smart_unicode(os.path.basename(path), errors='replace')
            short = smart_unicode(path[len(self.dest) + 1:], errors='replace')
            mime, encoding = mimetypes.guess_type(filename)
            if not mime and filename == 'manifest.webapp':
                mime = 'application/x-web-app-manifest+json'
            directory = os.path.isdir(path)

            res[short] = {
                'binary':
                self._is_binary(mime, path),
                'depth':
                short.count(os.sep),
                'directory':
                directory,
                'filename':
                filename,
                'full':
                path,
                'md5':
                get_md5(path) if not directory else '',
                'mimetype':
                mime or 'application/octet-stream',
                'syntax':
                self.get_syntax(filename),
                'modified':
                os.stat(path)[stat.ST_MTIME],
                'short':
                short,
                'size':
                os.stat(path)[stat.ST_SIZE],
                'truncated':
                self.truncate(filename),
                'url':
                reverse('mkt.files.list', args=[self.file.id, 'file', short]),
                'url_serve':
                reverse('mkt.files.redirect', args=[self.file.id, short]),
                'version':
                self.file.version.version,
            }

        return res
Beispiel #3
0
    def _get_files(self):
        all_files, res = [], SortedDict()
        for root, dirs, files in os.walk(self.dest):
            for filename in dirs + files:
                all_files.append([os.path.join(root, filename), filename])

        for path, filename in sorted(all_files):
            short = path[len(self.dest) + 1:]
            mime, encoding = mimetypes.guess_type(filename)
            binary = self.is_binary(mime, filename)
            # TODO: handling for st.a.m.o will be going in here
            url = reverse('files.list', args=[self.file.id, short])
            directory = os.path.isdir(path)
            res[short] = {'full': path,
                          'filename': filename,
                          'short': short,
                          'directory': directory,
                          'url': url,
                          'binary': binary,
                          'depth': short.count(os.sep),
                          'modified': os.stat(path)[stat.ST_MTIME],
                          'mimetype': mime or 'application/octet-stream',
                          'encoding': encoding,
                          'md5': get_md5(path) if not directory else '',
                          'parent': '/'.join(short.split(os.sep)[:-1])}
        return res
Beispiel #4
0
    def _get_files(self, locale=None):
        """We need the `locale` parameter for the memoization.

        The `@memoize` decorator uses the prefix *and the parameters* to come
        up with a memoize key. We thus add a (seemingly useless) `locale`
        parameter.

        Otherwise, we would just always have the urls for the files with the
        locale from the first person checking them.
        """
        all_files, res = [], SortedDict()

        # Not using os.path.walk so we get just the right order.

        def iterate(path):
            path_dirs, path_files = storage.listdir(path)
            for dirname in sorted(path_dirs):
                full = os.path.join(path, dirname)
                all_files.append(full)
                iterate(full)

            for filename in sorted(path_files):
                full = os.path.join(path, filename)
                all_files.append(full)

        iterate(self.dest)

        for path in all_files:
            filename = smart_unicode(os.path.basename(path), errors='replace')
            short = smart_unicode(path[len(self.dest) + 1:], errors='replace')
            mime, encoding = mimetypes.guess_type(filename)
            directory = os.path.isdir(path)

            res[short] = {
                'binary': self._is_binary(mime, path),
                'depth': short.count(os.sep),
                'directory': directory,
                'filename': filename,
                'full': path,
                'md5': get_md5(path) if not directory else '',
                'mimetype': mime or 'application/octet-stream',
                'syntax': self.get_syntax(filename),
                'modified': os.stat(path)[stat.ST_MTIME],
                'short': short,
                'size': os.stat(path)[stat.ST_SIZE],
                'truncated': self.truncate(filename),
                'url': reverse('files.list',
                               args=[self.file.id, 'file', short]),
                'url_serve': reverse('files.redirect',
                                     args=[self.file.id, short]),
                'version': self.file.version.version,
            }

        return res
Beispiel #5
0
    def _get_files(self, locale=None):
        """We need the `locale` parameter for the memoization.

        The `@memoize` decorator uses the prefix *and the parameters* to come
        up with a memoize key. We thus add a (seemingly useless) `locale`
        parameter.

        Otherwise, we would just always have the urls for the files with the
        locale from the first person checking them.
        """
        all_files, res = [], SortedDict()
        # Not using os.path.walk so we get just the right order.

        def iterate(path):
            path_dirs, path_files = storage.listdir(path)
            for dirname in sorted(path_dirs):
                full = os.path.join(path, dirname)
                all_files.append(full)
                iterate(full)

            for filename in sorted(path_files):
                full = os.path.join(path, filename)
                all_files.append(full)

        iterate(self.dest)

        for path in all_files:
            filename = smart_unicode(os.path.basename(path), errors='replace')
            short = smart_unicode(path[len(self.dest) + 1:], errors='replace')
            mime, encoding = mimetypes.guess_type(filename)
            directory = os.path.isdir(path)

            res[short] = {
                'binary': self._is_binary(mime, path),
                'depth': short.count(os.sep),
                'directory': directory,
                'filename': filename,
                'full': path,
                'md5': get_md5(path) if not directory else '',
                'mimetype': mime or 'application/octet-stream',
                'syntax': self.get_syntax(filename),
                'modified': os.stat(path)[stat.ST_MTIME],
                'short': short,
                'size': os.stat(path)[stat.ST_SIZE],
                'truncated': self.truncate(filename),
                'url': reverse('files.list',
                               args=[self.file.id, 'file', short]),
                'url_serve': reverse('files.redirect',
                                     args=[self.file.id, short]),
                'version': self.file.version.version,
            }

        return res
Beispiel #6
0
    def _get_files(self):
        all_files, res = [], SortedDict()
        # Not using os.path.walk so we get just the right order.

        def iterate(path):
            path_dirs, path_files = storage.listdir(path)
            for dirname in sorted(path_dirs):
                full = os.path.join(path, dirname)
                all_files.append(full)
                iterate(full)

            for filename in sorted(path_files):
                full = os.path.join(path, filename)
                all_files.append(full)

        iterate(self.dest)

        url_prefix = 'mkt.%s' if self.is_webapp else '%s'
        for path in all_files:
            filename = smart_unicode(os.path.basename(path), errors='replace')
            short = smart_unicode(path[len(self.dest) + 1:], errors='replace')
            mime, encoding = mimetypes.guess_type(filename)
            if not mime and filename == 'manifest.webapp':
                mime = 'application/x-web-app-manifest+json'
            directory = os.path.isdir(path)


            res[short] = {
                'binary': self._is_binary(mime, path),
                'depth': short.count(os.sep),
                'directory': directory,
                'filename': filename,
                'full': path,
                'md5': get_md5(path) if not directory else '',
                'mimetype': mime or 'application/octet-stream',
                'syntax': self.get_syntax(filename),
                'modified': os.stat(path)[stat.ST_MTIME],
                'short': short,
                'size': os.stat(path)[stat.ST_SIZE],
                'truncated': self.truncate(filename),
                'url': reverse(url_prefix % 'files.list',
                               args=[self.file.id, 'file', short]),
                'url_serve': reverse(url_prefix % 'files.redirect',
                                     args=[self.file.id, short]),
                'version': self.file.version.version,
            }

        return res
Beispiel #7
0
    def _get_files(self):
        all_files, res = [], SortedDict()
        # Not using os.path.walk so we get just the right order.

        def iterate(node):
            for filename in sorted(os.listdir(node)):
                full = os.path.join(node, filename)
                all_files.append(full)
                if os.path.isdir(full):
                    iterate(full)
        iterate(self.dest)

        for path in all_files:
            filename = smart_unicode(os.path.basename(path), errors='replace')
            short = smart_unicode(path[len(self.dest) + 1:], errors='replace')
            mime, encoding = mimetypes.guess_type(filename)
            directory = os.path.isdir(path)
            res[short] = {'binary': self._is_binary(mime, path),
                          'depth': short.count(os.sep),
                          'directory': directory,
                          'filename': filename,
                          'full': path,
                          'md5': get_md5(path) if not directory else '',
                          'mimetype': mime or 'application/octet-stream',
                          'syntax': self.get_syntax(filename),
                          'modified': os.stat(path)[stat.ST_MTIME],
                          'short': short,
                          'size': os.stat(path)[stat.ST_SIZE],
                          'truncated': self.truncate(filename),
                          'url': reverse('files.list',
                                         args=[self.file.id, 'file', short]),
                          'url_serve': reverse('files.redirect',
                                               args=[self.file.id, short]),
                          'version': self.file.version.version}

        return res
Beispiel #8
0
    def _get_files(self):
        all_files, res = [], SortedDict()
        # Not using os.path.walk so we get just the right order.

        def iterate(node):
            for filename in sorted(os.listdir(node)):
                full = os.path.join(node, filename)
                all_files.append(full)
                if os.path.isdir(full):
                    iterate(full)
        iterate(self.dest)

        for path in all_files:
            filename = smart_unicode(os.path.basename(path))
            short = smart_unicode(path[len(self.dest) + 1:])
            mime, encoding = mimetypes.guess_type(filename)
            directory = os.path.isdir(path)
            res[short] = {'binary': self._is_binary(mime, path),
                          'depth': short.count(os.sep),
                          'directory': directory,
                          'filename': filename,
                          'full': path,
                          'md5': get_md5(path) if not directory else '',
                          'mimetype': mime or 'application/octet-stream',
                          'syntax': self.get_syntax(filename),
                          'modified': os.stat(path)[stat.ST_MTIME],
                          'short': short,
                          'size': os.stat(path)[stat.ST_SIZE],
                          'truncated': self.truncate(filename),
                          'url': reverse('files.list',
                                         args=[self.file.id, 'file', short]),
                          'url_serve': reverse('files.redirect',
                                               args=[self.file.id, short]),
                          'version': self.file.version.version}

        return res