def clean(self): """Clears all caches of known projects""" header("Cleaning session...") for project in self.__projects: project.clean()
def permutate(self): """ Generator method for permutations for improving output capabilities """ header("Processing permutations...") permutations = self.getPermutations() length = len(permutations) for pos, current in enumerate(permutations): info(colorize("Permutation %s/%s:" % (pos+1, length), "bold")) setPermutation(current) indent() yield current outdent()
def addProject(self, project): """ Adds the given project to the list of known projects. Projects should be added in order of their priority. This adds the field configuration of each project to the session fields. Fields must not conflict between different projects (same name). Parameters: - project: Instance of Project to append to the list """ result = getProjectDependencies(project) header("Registering projects...") info("Initializing %s projects..." % len(result)) indent() for project in result: # Intialize project project.init() self.__projects.append(project) # Import project defined fields which might be configured using "activateField()" fields = project.getFields() for name in fields: entry = fields[name] if name in self.__fields: raise JasyError("Field '%s' was already defined!" % (name)) if "check" in entry: check = entry["check"] if check in ["Boolean", "String", "Number"] or type(check) == list: pass else: raise JasyError("Unsupported check: '%s' for field '%s'" % (check, name)) if "detect" in entry: detect = entry["detect"] if not self.getClassByName(detect): raise JasyError("Field '%s' uses unknown detection class %s." % (name, detect)) self.__fields[name] = entry outdent()
def __init__(self): atexit.register(self.close) self.__timestamp = time.time() self.__projects = [] self.__projectByName = {} self.__fields = {} if findConfig("jasyproject"): header("Initializing project") try: self.addProject(getProjectFromPath(".")) except JasyError as err: outdent(True) error(err) raise JasyError("Critical: Could not initialize session!")
def storeKernel(fileName, debug=False): """ Writes a so-called kernel script to the given location. This script contains data about possible permutations based on current session values. It optionally might include asset data (useful when boot phase requires some assets) and localization data (if only one locale is built). Optimization of the script is auto-enabled when no other information is given. This method returns the classes which are included by the script so you can exclude it from the real other generated output files. """ header("Storing kernel...") # This exports all field values from the session fields = session.exportFields() # This permutation injects data in the core classes and configures debugging as given by parameter setPermutation(Permutation({ "debug" : debug, "fields" : fields })) # Build resolver # We need the permutation here because the field configuration might rely on detection classes resolver = Resolver() resolver.addClassName("core.Env") resolver.addClassName("core.io.Asset") resolver.addClassName("core.io.Queue") # Sort resulting class list classes = resolver.getSortedClasses() storeCompressed(classes, fileName) setPermutation(None) return classes
def write(self, distFolder, classFilter=None, callback="apiload", showInternals=False, showPrivates=False, printErrors=True, highlightCode=True): # # Collecting # header("Collecting API Data...") apiData = {} highlightedCode = {} for project in session.getProjects(): classes = project.getClasses() info("Loading API of project %s: %s...", colorize(project.getName(), "bold"), colorize("%s classes" % len(classes), "cyan")) indent() for className in classes: if self.isIncluded(className, classFilter): apiData[className] = classes[className].getApi(highlightCode) highlightedCode[className] = classes[className].getHighlightedCode() outdent() # # Processing # header("Processing API Data...") data, index, search = self.process(apiData, classFilter=classFilter, internals=showInternals, privates=showPrivates, printErrors=printErrors) # # Writing # header("Storing API data...") writeCounter = 0 extension = "js" if callback else "json" def encode(content, name): if callback: return "%s(%s,'%s');" % (callback, toJson(content), name) else: return toJson(content) info("Saving class data (%s files)...", len(data)) for className in data: try: classData = data[className] if type(classData) is dict: classExport = classData else: classExport = classData.export() writeFile(os.path.join(distFolder, "%s.%s" % (className, extension)), encode(classExport, className)) except TypeError as writeError: error("Could not write API data of: %s: %s", className, writeError) continue info("Saving highlighted code (%s files)...", len(highlightedCode)) for className in highlightedCode: try: writeFile(os.path.join(distFolder, "%s.html" % className), highlightedCode[className]) except TypeError as writeError: error("Could not write highlighted code of: %s: %s", className, writeError) continue info("Writing index...") writeFile(os.path.join(distFolder, "meta-index.%s" % extension), encode(index, "meta-index")) writeFile(os.path.join(distFolder, "meta-search.%s" % extension), encode(search, "meta-search"))