Exemplo n.º 1
0
    def test_extract_from_zip_file_manifest_name_override(self):
        zf = zipfile.ZipFile(os.path.join(base_path, 'zipfiles', 'manifest-name-override.zip'))
        resourceName, manifestDict = extractManifestFromZipFile(zf, TEST_FORMAT)

        self.assertEqual(resourceName, 'demo1')
        self.assertEqual(manifestDict, None)

        resourceName, manifestDict = extractManifestFromZipFile(zf, TEST_FORMAT, manifestFilename='other-manifest.cfg')

        self.assertEqual(
                manifestDict,
                {'bar': 'baz', 'description': None, 'title': 'No top level dir'}
            )
Exemplo n.º 2
0
def extractThemeInfo(zipfile, checkRules=True):
    """Return an ITheme based on the information in the given zipfile.

    Will throw a ValueError if the theme directory does not contain a single
    top level directory or the rules file cannot be found.

    Set checkRules=False to disable the rules check.
    """

    name, manifest = extractManifestFromZipFile(
        zipfile,
        MANIFEST_FORMAT
    )
    if not manifest:
        manifest = {}
    rules = manifest.get('rules', None)
    if rules is None:
        if checkRules:
            try:
                zipfile.getinfo(
                    "{0:s}/{1:s}".format(name, RULE_FILENAME)
                )
            except KeyError:
                raise ValueError("Could not find theme name and rules file")
        rules = u"/++{0:s}++{1:s}/{0:s}".format(
            THEME_RESOURCE_NAME,
            name,
            RULE_FILENAME
        )
    return getTheme(name, manifest)
def extractResourceName(zipfile):
    """ 
    """
    resourceName, manifestDict = extractManifestFromZipFile(
        zipfile, MANIFEST_FORMAT)

    return resourceName
Exemplo n.º 4
0
    def test_extract_from_zip_file_manifest_name_override(self):
        zf = zipfile.ZipFile(
            os.path.join(base_path, 'zipfiles', 'manifest-name-override.zip'))
        resourceName, manifestDict = extractManifestFromZipFile(
            zf, TEST_FORMAT)

        self.assertEqual(resourceName, 'demo1')
        self.assertEqual(manifestDict, None)

        resourceName, manifestDict = extractManifestFromZipFile(
            zf, TEST_FORMAT, manifestFilename='other-manifest.cfg')

        self.assertEqual(manifestDict, {
            'bar': 'baz',
            'description': None,
            'title': 'No top level dir'
        })
Exemplo n.º 5
0
    def test_extract_from_zip_file_no_manifest(self):
        zf = zipfile.ZipFile(
            os.path.join(base_path, 'zipfiles', 'no-manifest.zip'))
        resourceName, manifestDict = extractManifestFromZipFile(
            zf, TEST_FORMAT)

        self.assertEqual(resourceName, 'demo1')
        self.assertEqual(manifestDict, None)
Exemplo n.º 6
0
    def test_extract_from_zip_file(self):
        zf = zipfile.ZipFile(os.path.join(base_path, 'zipfiles', 'normal.zip'))
        resourceName, manifestDict = extractManifestFromZipFile(zf, TEST_FORMAT)

        self.assertEqual(resourceName, 'demo1')
        self.assertEqual(
                manifestDict,
                {'bar': 'baz', 'description': None, 'title': 'No top level dir'}
            )
Exemplo n.º 7
0
    def test_extract_from_zip_file(self):
        zf = zipfile.ZipFile(os.path.join(base_path, 'zipfiles', 'normal.zip'))
        resourceName, manifestDict = extractManifestFromZipFile(
            zf, TEST_FORMAT)

        self.assertEqual(resourceName, 'demo1')
        self.assertEqual(manifestDict, {
            'bar': 'baz',
            'description': None,
            'title': 'No top level dir'
        })
Exemplo n.º 8
0
def extractThemeInfo(zipfile, checkRules=True):
    """Return an ITheme based on the information in the given zipfile.

    Will throw a ValueError if the theme directory does not contain a single
    top level directory or the rules file cannot be found.

    Set checkRules=False to disable the rules check.
    """

    resourceName, manifestDict = extractManifestFromZipFile(
        zipfile, MANIFEST_FORMAT)

    rulesFile = None
    absolutePrefix = '/++%s++%s' % (THEME_RESOURCE_NAME, resourceName)
    title = None
    description = None
    parameters = {}
    doctype = ""
    preview = None

    if manifestDict is not None:
        rulesFile = manifestDict.get('rules', rulesFile)
        absolutePrefix = manifestDict['prefix'] or absolutePrefix
        title = manifestDict.get('title', None)
        description = manifestDict.get('title', None)
        parameters = manifestDict.get('parameters', {})
        doctype = manifestDict.get('doctype', "")
        preview = manifestDict.get('preview', None)

    if not rulesFile:
        if checkRules:
            try:
                zipfile.getinfo("%s/%s" % (
                    resourceName,
                    RULE_FILENAME,
                ))
            except KeyError:
                raise ValueError("Could not find theme name and rules file")
        rulesFile = u"/++%s++%s/%s" % (
            THEME_RESOURCE_NAME,
            resourceName,
            RULE_FILENAME,
        )

    return Theme(
        resourceName,
        rulesFile,
        title=title,
        description=description,
        absolutePrefix=absolutePrefix,
        parameterExpressions=parameters,
        doctype=doctype,
        preview=preview,
    )
Exemplo n.º 9
0
def extractThemeInfo(zipfile, checkRules=True):
    """Return an ITheme based on the information in the given zipfile.

    Will throw a ValueError if the theme directory does not contain a single
    top level directory or the rules file cannot be found.

    Set checkRules=False to disable the rules check.
    """

    resourceName, manifestDict = extractManifestFromZipFile(zipfile, MANIFEST_FORMAT)

    rulesFile = None
    absolutePrefix = '/++%s++%s' % (THEME_RESOURCE_NAME, resourceName)
    title = None
    description = None
    parameters = {}
    doctype = ""
    preview = None
    enabled_bundles = ''
    disabled_bundles = ''

    if manifestDict is not None:
        rulesFile = manifestDict.get('rules', rulesFile)
        absolutePrefix = manifestDict['prefix'] or absolutePrefix
        title = manifestDict.get('title', None)
        description = manifestDict.get('title', None)
        parameters = manifestDict.get('parameters', {})
        doctype = manifestDict.get('doctype', "")
        preview = manifestDict.get('preview', None)
        enabled_bundles = manifestDict.get('enabled-bundles', '')
        disabled_bundles = manifestDict.get('disabled-bundles', '')

    if not rulesFile:
        if checkRules:
            try:
                zipfile.getinfo("%s/%s" % (resourceName, RULE_FILENAME,))
            except KeyError:
                raise ValueError("Could not find theme name and rules file")
        rulesFile = u"/++%s++%s/%s" % (THEME_RESOURCE_NAME, resourceName, RULE_FILENAME,)

    return Theme(resourceName, rulesFile,
            title=title,
            description=description,
            absolutePrefix=absolutePrefix,
            parameterExpressions=parameters,
            doctype=doctype,
            preview=preview,
            enabled_bundles=enabled_bundles.split(',') if enabled_bundles else [],
            disabled_bundles=disabled_bundles.split(',') if disabled_bundles else []
        )
Exemplo n.º 10
0
def extractThemeInfo(zipfile):
    """Return an ITheme based on the information in the given zipfile.

    Will throw a ValueError if the theme directory does not contain a single
    top level directory or the rules file cannot be found.
    """

    resourceName, manifestDict = extractManifestFromZipFile(zipfile, MANIFEST_FORMAT)

    rulesFile = None
    absolutePrefix = "/++%s++%s" % (THEME_RESOURCE_NAME, resourceName)
    title = None
    description = None
    parameters = {}
    doctype = ""

    if manifestDict is not None:
        rulesFile = manifestDict.get("rules", rulesFile)
        absolutePrefix = manifestDict["prefix"] or absolutePrefix
        title = manifestDict.get("title", None)
        description = manifestDict.get("title", None)
        parameters = manifestDict.get("parameters", {})
        doctype = manifestDict.get("doctype", "")

    if not rulesFile:
        try:
            zipfile.getinfo("%s/%s" % (resourceName, RULE_FILENAME))
        except KeyError:
            raise ValueError("Could not find theme name and rules file")
        rulesFile = u"/++%s++%s/%s" % (THEME_RESOURCE_NAME, resourceName, RULE_FILENAME)

    return Theme(
        resourceName,
        rulesFile,
        title=title,
        description=description,
        absolutePrefix=absolutePrefix,
        parameterExpressions=parameters,
        doctype=doctype,
    )
Exemplo n.º 11
0
    def test_extract_from_zip_file_no_manifest(self):
        zf = zipfile.ZipFile(os.path.join(base_path, 'zipfiles', 'no-manifest.zip'))
        resourceName, manifestDict = extractManifestFromZipFile(zf, TEST_FORMAT)

        self.assertEqual(resourceName, 'demo1')
        self.assertEqual(manifestDict, None)