def createCaseTwo(self): #application path = os.path.join(tempfile.TemporaryDirectory().name, "myproject") os.makedirs(path) def createFolders(): os.makedirs(os.path.join(path, "source")) os.makedirs(os.path.join(os.path.join(path, "source"), "class")) os.makedirs(os.path.join(os.path.join(path, "source"), "asset")) os.makedirs( os.path.join(os.path.join(path, "source"), "translation")) def createSampleClasses(): self.writeFile(os.path.join(path, "source"), "index.html", """<html></html>""") self.writeFile(os.path.join(os.path.join(path, "source"), "class"), "Main.js", ";") def createSampleAssets(): self.writeFile(os.path.join(os.path.join(path, "source"), "asset"), "main.css", """html{}""") def createSampleTranslations(): self.writeFile( os.path.join(os.path.join(path, "source"), "translation"), "de.po", " ") createFolders() self.createjpyaml(path) createSampleClasses() createSampleAssets() createSampleTranslations() return Project.getProjectFromPath(path)
def createProject(self, session, requirements): path = os.path.join(tempfile.TemporaryDirectory().name, "myproject") os.makedirs(path) def createFolders(): os.makedirs(os.path.join(path, "source")) os.makedirs(os.path.join(os.path.join(path, "source"), "class")) os.makedirs(os.path.join(os.path.join(path, "source"), "asset")) os.makedirs(os.path.join(os.path.join(path, "source"), "translation")) def createSampleClasses(): self.writeFile(os.path.join(path, "source"), "index.html", """<html></html>""") self.writeFile(os.path.join(os.path.join(path, "source"), "class"), "Main.js", ";") def createSampleAssets(): self.writeFile(os.path.join(os.path.join(path, "source"), "asset"), "main.css", """html{}""") def createSampleTranslations(): self.writeFile(os.path.join(os.path.join(path, "source"), "translation"), "de.po", " ") createFolders() self.createjpyaml(path, requirements) createSampleClasses() createSampleAssets() createSampleTranslations() os.chdir(path) return Project.getProjectFromPath(path, session)
def createCaseTwo(self): # application path = os.path.join(tempfile.TemporaryDirectory().name, "myproject") os.makedirs(path) def createFolders(): os.makedirs(os.path.join(path, "source")) os.makedirs(os.path.join(os.path.join(path, "source"), "class")) os.makedirs(os.path.join(os.path.join(path, "source"), "asset")) os.makedirs(os.path.join(os.path.join(path, "source"), "translation")) def createSampleScripts(): self.writeFile(os.path.join(path, "source"), "index.html", """<html></html>""") self.writeFile(os.path.join(os.path.join(path, "source"), "class"), "Main.js", ";") def createSampleAssets(): self.writeFile(os.path.join(os.path.join(path, "source"), "asset"), "main.css", """html{}""") def createSampleTranslations(): self.writeFile(os.path.join(os.path.join(path, "source"), "translation"), "de.po", " ") createFolders() self.createjpyaml(path) createSampleScripts() createSampleAssets() createSampleTranslations() return Project.getProjectFromPath(path, Session.Session())
def getVirtualProject(self): """ Returns the virtual project for this application. The project offers storage for dynamically created JavaScript classes and other files. Storage is kept intact between different Jasy sessions. """ # Create only once per session if self.__virtualProject: return self.__virtualProject # Place virtual project in application's ".jasy" folder path = os.path.abspath(os.path.join(".jasy", "virtual")) # Set package to empty string to allow for all kind of namespaces in this virtual project jasy.core.File.write(os.path.join(path, "jasyproject.yaml"), 'name: virtual\npackage: ""\n') # Generate project instance from path, store and return project = Project.getProjectFromPath(path, self) self.__virtualProject = project self.__projects.append(project) return project
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). :param project: Instance of Project to append to the list :type project: object """ result = Project.getProjectDependencies(project, "external", self.__updateRepositories) for project in result: Console.info("Adding %s...", Console.colorize(project.getName(), "bold")) Console.indent() # Append to session list self.__projects.append(project) # Import library methods libraryPath = os.path.join(project.getPath(), "jasylibrary.py") if os.path.exists(libraryPath): self.loadLibrary(project.getName(), libraryPath, doc="Library of project %s" % project.getName()) # Import command methods commandPath = os.path.join(project.getPath(), "jasycommand.py") if os.path.exists(commandPath): self.loadCommands(project.getName(), commandPath) # 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 UserError("Field '%s' was already defined!" % (name)) if "check" in entry: check = entry["check"] if check in ["Boolean", "String", "Number"] or isinstance(check, list): pass else: raise UserError("Unsupported check: '%s' for field '%s'" % (check, name)) self.__fields[name] = entry Console.outdent()
def getCurrentLocaleProject(self, update=False): """ Returns a locale project for the currently configured locale. Returns None if locale is not set to a valid value. """ locale = self.getCurrentLocale() if not locale: return None path = os.path.abspath(os.path.join(".jasy", "locale", locale)) if not os.path.exists(path) or update: Locale.LocaleParser(locale).export(path) return Project.getProjectFromPath(path, self.__session)
def createProject(self, requirements, onlyFileCreation=False): global globProject globProject = tempfile.TemporaryDirectory() path = os.path.join(globProject.name, "myproject") os.makedirs(path) def createFolders(): os.makedirs(os.path.join(path, "source")) os.makedirs(os.path.join(os.path.join(path, "source"), "class")) os.makedirs(os.path.join(os.path.join(path, "source"), "asset")) os.makedirs( os.path.join(os.path.join(path, "source"), "translation")) def createSampleClasses(): self.writeFile(os.path.join(path, "source"), "index.html", """<html></html>""") self.writeFile(os.path.join(os.path.join(path, "source"), "class"), "Main.js", ";") def createSampleAssets(): self.writeFile(os.path.join(os.path.join(path, "source"), "asset"), "main.css", """html{}""") def createSampleTranslations(): self.writeFile( os.path.join(os.path.join(path, "source"), "translation"), "de.po", " ") createFolders() self.createjpyaml(path, requirements) createSampleClasses() createSampleAssets() createSampleTranslations() os.chdir(path) if onlyFileCreation: return path return Project.getProjectFromPath(path)
def init(self, autoInitialize=True, updateRepositories=True, scriptEnvironment=None): """ Initialize the actual session with projects. :param autoInitialize: Whether the projects should be automatically added when the current folder contains a valid Jasy project. :param updateRepositories: Whether to update repositories of all project dependencies. :param scriptEnvironment: API object as being used for loadLibrary to add Python features offered by projects. :param commandEnvironment: API object as being used for loadCommands to add Python features for any item nodes. """ self.__scriptEnvironment = scriptEnvironment self.__updateRepositories = updateRepositories if autoInitialize and Config.findConfig("jasyproject"): Console.info("Initializing session...") Console.indent() try: self.addProject(Project.getProjectFromPath(".", self)) except UserError as err: Console.outdent(True) Console.error(err) raise UserError("Critical: Could not initialize session!") self.getVirtualProject() Console.debug("Active projects (%s):", len(self.__projects)) Console.indent() for project in self.__projects: if project.version: Console.debug("%s @ %s", Console.colorize(project.getName(), "bold"), Console.colorize(project.version, "magenta")) else: Console.debug(Console.colorize(project.getName(), "bold")) Console.outdent() Console.outdent()
def createCaseThree(self): #src path = os.path.join(tempfile.TemporaryDirectory().name, "myproject") os.makedirs(path) def createFolders(): os.makedirs(os.path.join(path, "src")) def createSampleClasses(): self.writeFile(os.path.join(path, "src"), "index.html", """<html></html>""") self.writeFile(os.path.join(path, "src"), "Main.js", ";") def createSampleAssets(): self.writeFile(os.path.join(path, "src"), "main.css", """html{}""") createFolders() self.createjpyaml(path) createSampleClasses() createSampleAssets() return Project.getProjectFromPath(path)
def createCaseThree(self): # src path = os.path.join(tempfile.TemporaryDirectory().name, "myproject") os.makedirs(path) def createFolders(): os.makedirs(os.path.join(path, "src")) def createSampleScripts(): self.writeFile(os.path.join(path, "src"), "index.html", """<html></html>""") self.writeFile(os.path.join(path, "src"), "Main.js", ";") def createSampleAssets(): self.writeFile(os.path.join(path, "src"), "main.css", """html{}""") createFolders() self.createjpyaml(path) createSampleScripts() createSampleAssets() return Project.getProjectFromPath(path, Session.Session())
def createCaseOne(self): #manual path = os.path.join(tempfile.TemporaryDirectory().name, "myproject") os.makedirs(path) def createFolders(): os.makedirs(os.path.join(path, "man")) def createSampleClasses(): self.writeFile(os.path.join(path, "man"), "index.html", """<html></html>""") self.writeFile(os.path.join(path, "man"), "Main.js", ";") self.writeFile(os.path.join(path, "man"), "Add.js", ";") def createSampleAssets(): self.writeFile(os.path.join(path, "man"), "main.css", """html{}""") createFolders() self.createjpyaml_withContent(path) createSampleClasses() createSampleAssets() return Project.getProjectFromPath(path)
def createCaseOne(self): # manual path = os.path.join(tempfile.TemporaryDirectory().name, "myproject") os.makedirs(path) def createFolders(): os.makedirs(os.path.join(path, "man")) def createSampleScripts(): self.writeFile(os.path.join(path, "man"), "index.html", """<html></html>""") self.writeFile(os.path.join(path, "man"), "Main.js", ";") self.writeFile(os.path.join(path, "man"), "Add.js", ";") def createSampleAssets(): self.writeFile(os.path.join(path, "man"), "main.css", """html{}""") createFolders() self.createjpyaml_withContent(path) createSampleScripts() createSampleAssets() return Project.getProjectFromPath(path, Session.Session())
def test_get_name_from_path(self): for project in self.getProjects(): self.assertEqual(Project.getProjectNameFromPath(project.getPath()), "myproject")