def __init__(self, details): """ This constructor uses an existing PackageDetector instance to avoid multiple detection of package meta-information (for each derived subclass BashSrcWriter etc.) """ Any.require(isinstance(details, PackageDetector)) self.content = '' self.details = details
def __init__(self, details, sourceTree=False): """ This constructor uses an existing PackageDetector instance to avoid multiple detection of package meta-information (for each derived subclass BashSrcWriter etc.) The optional parameter 'sourceTree' flags if the resulting pkgInfo.py is intended to be installed into SIT (=False) or if it should go into the source tree of the package. The stored fields vary depending on the target destination. """ Any.require(isinstance(details, PackageDetector)) super(PkgInfoWriter, self).__init__(details) self._sourceTree = sourceTree self._pprintOut = six.StringIO() self._pprinter = pprint.PrettyPrinter(width=self._valueWidthMax, stream=self._pprintOut)
def addDefinitions(self, cursor): """ Extracts all the definitions from the libclang namespace cursor and adds them to the database """ def getNamespace(cur): if (cur.semantic_parent and cur.semantic_parent.kind in (cidx.CursorKind.NAMESPACE, cidx.CursorKind.TRANSLATION_UNIT)): curNamespaceHierarchy = getNamespaceHierarchy(cur) return self._getInnerNamespace(curNamespaceHierarchy) else: return None Any.requireIsNotNone(cursor) Any.require(cursor.kind in (cidx.CursorKind.NAMESPACE, cidx.CursorKind.TRANSLATION_UNIT, cidx.CursorKind.UNEXPOSED_DECL)) for c in cursor.get_children(): ns = getNamespace(c) if c.kind == cidx.CursorKind.UNEXPOSED_DECL: self.addDefinitions(c) elif ns is not None: if c.kind == cidx.CursorKind.VAR_DECL: self.variables[c.spelling] = Variable(c) elif c.kind in (cidx.CursorKind.FUNCTION_DECL, cidx.CursorKind.CXX_METHOD): # function definition or prototype if c.spelling not in ns.functions: ns.functions[c.spelling] = set() # fset is the set of functions named as the one we are visiting now fset = ns.functions[c.spelling] _addDefinitionOrPrototype(c, fset, FunctionDefinition, FunctionPrototype) elif c.kind == cidx.CursorKind.STRUCT_DECL: ns.structs[c.spelling] = Struct(c.get_definition() or c.canonical or c) elif c.kind == cidx.CursorKind.CLASS_DECL: ns.classes[c.spelling] = ClassDef(c.get_definition() or c.canonical or c) elif c.kind == cidx.CursorKind.TYPEDEF_DECL: ns.typedefs[c.spelling] = Typedef(c) elif c.kind == cidx.CursorKind.ENUM_DECL: ns.enums[c.spelling] = Enum(c.get_definition() or c.canonical or c) elif c.kind == cidx.CursorKind.UNION_DECL: ns.unions[c.spelling] = Union(c.get_definition() or c.canonical or c) elif c.kind == cidx.CursorKind.FUNCTION_TEMPLATE: if c.spelling not in ns.templateFunctions: ns.templateFunctions[c.spelling] = set() # fset is the set of functions named as the one we are visiting now fset = ns.templateFunctions[c.spelling] _addDefinitionOrPrototype(c, fset, TemplateFunctionDefinition, TemplateFunctionPrototype) elif c.kind == cidx.CursorKind.CLASS_TEMPLATE: if c.spelling not in ns.templateClasses: ns.templateClasses[c.spelling] = set() classTemplateDef = ClassTemplateDef(c.get_definition() or c.canonical or c) ns.templateClasses[c.spelling].add(classTemplateDef) elif c.kind == cidx.CursorKind.NAMESPACE: cursorNamespaceHierarchy = getNamespaceHierarchy(c) + [ c.spelling ] try: ns = self._getInnerNamespace(cursorNamespaceHierarchy) ns.addDefinitions(c) except (ValueError, KeyError): ns = Namespace(c) self.namespaces[c.spelling] = ns
url = ProjectProperties.guessSVNLocation(package) # strip-off the version from the URL to fetch entire repository (if requested) if fetchAll: url = os.path.dirname(url) Any.requireIsTextNonEmpty(url) # revision to fetch if args['global']: try: revision = PkgInfo.getSVNRevision(package) Any.requireIsInt(revision) Any.require(revision != -1) logging.info('SVN revision = %d' % revision) except (AssertionError, IOError): logging.error('') logging.error('unable to detect last globally installed revision') logging.error('falling back to HEAD revision') logging.error('') projectName = ProjectProperties.splitPath(package)[1] Any.requireIsTextNonEmpty(projectName) # create directory with name of package when downloading a particular version, # and cd into it if not fetchAll: FastScript.mkdir(projectName)