Beispiel #1
0
    def _getImportContext(self, context_id, should_purge=None, archive=None):
        """ Crack ID and generate appropriate import context.
        """
        encoding = self.getEncoding()

        if context_id is not None:
            if context_id.startswith('profile-'):
                context_id = context_id[len('profile-'):]
                info = _profile_registry.getProfileInfo(context_id)

                if info.get('product'):
                    path = os.path.join(_getProductPath(info['product']),
                                        info['path'])
                else:
                    path = info['path']
                if should_purge is None:
                    should_purge = (info.get('type') != EXTENSION)
                return DirectoryImportContext(self, path, should_purge,
                                              encoding)

            elif context_id.startswith('snapshot-'):
                context_id = context_id[len('snapshot-'):]
                if should_purge is None:
                    should_purge = True
                return SnapshotImportContext(self, context_id, should_purge,
                                             encoding)

        if archive is not None:
            return TarballImportContext(tool=self,
                                       archive_bits=archive,
                                       encoding='UTF8',
                                       should_purge=should_purge,
                                      )

        raise KeyError('Unknown context "%s"' % context_id)
Beispiel #2
0
    def _getImportContext(self, context_id, should_purge=None, archive=None):
        """ Crack ID and generate appropriate import context.

        Note: it seems context_id (profile id) and archive (tarball)
        are mutually exclusive.  Exactly one of the two should be
        None.  There seems to be no use case for a different
        combination.
        """
        encoding = self.getEncoding()

        if context_id is not None:
            prefix = "snapshot-"
            if context_id.startswith(prefix):
                context_id = context_id[len(prefix) :]
                if should_purge is None:
                    should_purge = True
                return SnapshotImportContext(self, context_id, should_purge, encoding)
            prefix = "profile-"
            if context_id.startswith(prefix):
                context_id = context_id[len(prefix) :]
            info = _profile_registry.getProfileInfo(context_id)
            if info.get("product"):
                path = os.path.join(_getProductPath(info["product"]), info["path"])
            else:
                path = info["path"]
            if should_purge is None:
                should_purge = info.get("type") != EXTENSION
            return DirectoryImportContext(self, path, should_purge, encoding)

        if archive is not None:
            return TarballImportContext(tool=self, archive_bits=archive, encoding="UTF8", should_purge=should_purge)

        raise KeyError('Unknown context "%s"' % context_id)
Beispiel #3
0
    def __init__( self, path, encoding=None, product=None ):

        # don't call the base class __init__ b/c we don't have (or need)
        # a site

        self._path = path
        if product is not None:
            # Handle relative paths
            try:
                product_path = _getProductPath(product)
            except ValueError:
                pass
            else:
                self._path = os.path.join(product_path, path)

        self._encoding = encoding
Beispiel #4
0
    def __init__(self, path, encoding=None, product=None):

        # don't call the base class __init__ b/c we don't have (or need)
        # a site

        self._path = path
        if product is not None:
            # Handle relative paths
            try:
                product_path = _getProductPath(product)
            except ValueError:
                pass
            else:
                self._path = os.path.join(product_path, path)

        self._encoding = encoding