Skip to content

Instantly share code, notes, and snippets.

@zodman
Created February 22, 2010 07:15
Show Gist options
  • Save zodman/310894 to your computer and use it in GitHub Desktop.
Save zodman/310894 to your computer and use it in GitHub Desktop.
(working version) Mon Feb 22 08:14:31 2010 (no log message)
PackageMetadata.py: changed
Index: PackageMetadata.py
====================================================================
contents(size sha1)
inode(mtime owner group)
--- PackageMetadata.py /foresight.rpath.org@fl:2-devel/2.0.0-2
+++ PackageMetadata.py @NEW@
@@ -31,3 +31,150 @@
self.recipe.Description(shortDesc = self.recipe.packageSummary, longDesc = self.recipe.packageDescription, macros = True)
else:
self.info('Package descriptions are not set; Application metadata is critical for a good user experience. Please consider fixing it')
+
+
+class _BaseMetadata(policy.PackagePolicy):
+ keywords = {
+ 'language' : None,
+ 'troveNames' : None,
+ 'macros' : True,
+ }
+
+ def __init__(self, recipe, *args, **keywords):
+ policy.PackagePolicy.__init__(self, recipe, *args, **keywords)
+ self.applymacros = self.macros
+
+ def updateArgs(self, *args, **keywords):
+ policy.PackagePolicy.updateArgs(self, *args, **keywords)
+ self.applymacros = self.macros
+
+ def _getTroveNames(self):
+ # Build a map of troves that we have available
+ availTroveNames = set(x.name
+ for x in self.recipe.autopkg.getComponents())
+ availTroveNames.update(set(self.recipe.packages))
+
+ # If no trove names were supplied, apply the metadata to all packages
+ troveNamesArg = ((self.troveNames is None and self.recipe.packages) or
+ self.troveNames)
+ troveNames = []
+ for troveName in troveNamesArg:
+ # Check to see if the :component syntax was used
+ if not troveName.startswith(':'):
+ if troveName not in availTroveNames:
+ # We don't know about this trove name, just move on
+ continue
+ troveNames.append(troveName)
+ continue
+ # The trove spec starts with :. Extract all troves that have that
+ # component.
+ for pkgName in self.recipe.packages:
+ if pkgName + troveName in availTroveNames:
+ troveNames.append(pkgName + troveName)
+ return troveNames
+
+
+class SetupRecipeMetadata(_BaseMetadata):
+ """
+ NAME
+ ====
+
+ B{C{r.SetupRecipeMetadata()}} - Setup metadata for the package
+
+ SYNOPSIS
+ ========
+
+ C{r.SetupRecipeMetadata()}
+
+ DESCRIPTION
+ ===========
+
+ The C{r.SetupRecipeMetadata()} class adds recipe metadata to trove.
+
+ Metadata should be included as a set of variables in the recipe,
+ such as C{r.description}, C{r.long_description}, C{r.url} and
+ C{r.categories[]}.
+ """
+
+ def __init__(self, recipe, *args, **keywords):
+ _BaseMetadata.__init__(self, recipe, *args, **keywords)
+
+ def do(self):
+ if not hasattr(self.recipe, '_addMetadataItem'):
+ # Old Conary
+ return
+ troveNames = self._getTroveNames()
+
+ # Check if macros should be applied (defaults to True)
+ if hasattr(self.recipe, 'applyMacrosToMetadata') \
+ and not self.recipe.applyMacrosToMetadata:
+ applyMacros = False
+ else:
+ applyMacros = True
+
+ # Check for short description
+ if hasattr(self.recipe, 'shortDesc'):
+ if applyMacros:
+ shortDesc = self.recipe.shortDesc % self.recipe.macros
+ else:
+ shortDesc = self.recipe.shortDesc
+ itemDict = dict(shortDesc = shortDesc)
+ self.recipe._addMetadataItem(troveNames, itemDict)
+
+ # Check for long description
+ if hasattr(self.recipe, 'longDesc'):
+ if applyMacros:
+ longDesc = self.recipe.longDesc % self.recipe.macros
+ else:
+ longDesc = self.recipe.longDesc
+ itemDict = dict(longDesc = longDesc)
+ self.recipe._addMetadataItem(troveNames, itemDict)
+
+ # Check for url
+ if hasattr(self.recipe, 'url'):
+ if applyMacros:
+ url = self.recipe.url % self.recipe.macros
+ else:
+ url = self.recipe.url
+ itemDict = dict(url = url)
+ self.recipe._addMetadataItem(troveNames, itemDict)
+
+ # Check for single category
+ if hasattr(self.recipe, 'category'):
+ if applyMacros:
+ categories = [ self.recipe.category % self.recipe.macros ]
+ else:
+ categories = [ self.recipe.category ]
+ itemDict = dict(categories = categories)
+ self.recipe._addMetadataItem(troveNames, itemDict)
+
+ # Check for categories
+ if hasattr(self.recipe, 'categories') and \
+ type(self.recipe.categories) == type([]) and \
+ len(self.recipe.categories) > 0:
+ if applyMacros:
+ categories = [x % self.recipe.macros for x in self.recipe.categories]
+ else:
+ categories = self.recipe.categories
+ itemDict = dict(categories = categories)
+ self.recipe._addMetadataItem(troveNames, itemDict)
+
+ # Check for single license
+ if hasattr(self.recipe, 'license'):
+ if applyMacros:
+ licenses = [ self.recipe.license % self.recipe.macros ]
+ else:
+ licenses = [ self.recipe.license ]
+ itemDict = dict(licenses = licenses)
+ self.recipe._addMetadataItem(troveNames, itemDict)
+
+ # Check for licenses
+ if hasattr(self.recipe, 'licenses') and \
+ type(self.recipe.licenses) == type([]) and \
+ len(self.recipe.licenses) > 0:
+ if applyMacros:
+ licenses = [x % self.recipe.macros for x in self.recipe.licenses]
+ else:
+ licenses = self.recipe.licenses
+ itemDict = dict(licenses = licenses)
+ self.recipe._addMetadataItem(troveNames, itemDict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment