def build(self): """Build static website.""" Console.info("Intializing Konstrukteur...") Console.indent() # Path configuration # TODO: Use Jasy configuration instead self.__templatePath = os.path.join("source", "template") self.__contentPath = os.path.join("source", "content") self.__sourcePath = os.path.join("source") self.__pagePath = os.path.join(self.__contentPath, "page") self.__postPath = os.path.join(self.__contentPath, "post") if not os.path.exists(self.__templatePath): raise RuntimeError("Path to templates not found : %s" % self.__templatePath) if not os.path.exists(self.__contentPath): raise RuntimeError("Path to content not found : %s" % self.__contentPath) # A theme could be any project registered in the current session if self.__theme: themeProject = session.getProjectByName(self.__theme) if not themeProject: raise RuntimeError("Theme '%s' not found" % self.__theme) self.__initializeTemplates() self.__generateOutput()
def runTask(project, task, **kwargs): header("Running %s of project %s..." % (task, project)) import subprocess # Pauses this session to allow sub process fully accessing the same projects session.pause() # Build parameter list from optional arguments params = ["--%s=%s" % (key, kwargs[key]) for key in kwargs] if not "prefix" in kwargs: params.append("--prefix=%s" % getPrefix()) # Full list of args to pass to subprocess args = [__jasyCommand, task] + params # Change into sub folder and execute jasy task oldPath = os.getcwd() remote = session.getProjectByName(project) if remote is None: raise JasyError("Unknown project %s" % project) os.chdir(remote.getPath()) returnValue = subprocess.call(args, shell=sys.platform == "win32") os.chdir(oldPath) # Resumes this session after sub process was finished session.resume() # Error handling if returnValue != 0: raise JasyError("Executing of sub task %s from project %s failed" % (task, project))
def build(self, profile): """ Build static website """ Console.info("Executing Konstrukteur...") Console.indent() self.__templatePath = os.path.join("source", "template") self.__contentPath = os.path.join("source", "content") self.__sourcePath = os.path.join("source") self.__profile = profile self.__fileManager = FileManager.FileManager(profile) if not os.path.exists(self.__templatePath): raise RuntimeError("Path to templates not found : %s" % self.__templatePath) if not os.path.exists(self.__contentPath): raise RuntimeError("Path to content not found : %s" % self.__contentPath) if self.theme: theme = session.getProjectByName(self.theme) if not theme: raise RuntimeError("Theme '%s' not found" % self.theme) self.__postUrl = pystache.parse(self.posturl) self.__pageUrl = pystache.parse(self.pageurl) self.__feedUrl = pystache.parse(self.feedurl) self.__parseTemplate() self.__build() if self.regenerate: fileChangeEventHandler = konstrukteur.FileWatcher.FileChangeEventHandler() observer = Observer() observer.schedule(fileChangeEventHandler, self.__sourcePath, recursive=True) observer.start() try: Console.info("Waiting for file changes (abort with CTRL-C)") while True: time.sleep(1) if fileChangeEventHandler.dirty: fileChangeEventHandler.dirty = False self.__build() except KeyboardInterrupt: observer.stop() observer.join() Console.outdent()
def runTask(project, task, **kwargs): """ Executes the given task of the given projects. This happens inside a new sandboxed session during which the current session is paused/resumed automatically. """ remote = session.getProjectByName(project) if remote is not None: remotePath = remote.getPath() remoteName = remote.getName() elif os.path.isdir(project): remotePath = project remoteName = os.path.basename(project) else: raise UserError("Unknown project or invalid path: %s" % project) Console.info("Running %s of project %s...", Console.colorize(task, "bold"), Console.colorize(remoteName, "bold")) # Pauses this session to allow sub process fully accessing the same projects session.pause() # Build parameter list from optional arguments params = ["--%s=%s" % (key, kwargs[key]) for key in kwargs] if not "prefix" in kwargs: params.append("--prefix=%s" % session.getCurrentPrefix()) # Full list of args to pass to subprocess args = [__command, task] + params # Change into sub folder and execute jasy task oldPath = os.getcwd() os.chdir(remotePath) returnValue = subprocess.call(args, shell=sys.platform == "win32") os.chdir(oldPath) # Resumes this session after sub process was finished session.resume() # Error handling if returnValue != 0: raise UserError("Executing of sub task %s from project %s failed" % (task, project))
def create(name="myproject", origin=None, skeleton=None, **argv): """Creates a new project""" header("Creating project %s" % name) if not validProjectName.match(name): raise JasyError("Invalid project name: %s" % name) # # Initial Checks # # Figuring out destination folder destinationPath = os.path.abspath(name) if os.path.exists(destinationPath): raise JasyError("Cannot create project in %s. File or folder exists!" % destinationPath) # Origin can be either: # 1) None, which means a skeleton from the current main project # 2) An repository URL # 3) A project name known inside the current session # 4) Relative or absolute folder path if origin is None: originProject = session.getMain() if originProject is None: raise JasyError("Auto discovery failed! No Jasy projects registered!") originPath = originProject.getPath() originName = originProject.getName() elif isRepository(origin): info("Using remote skeleton") tempDirectory = tempfile.TemporaryDirectory() originPath = os.path.join(tempDirectory.name, "clone") originUrl = origin originVersion = getKey(argv, "origin-version") indent() originRevision = updateRepository(originUrl, originVersion, originPath) outdent() if originRevision is None: raise JasyError("Could not clone origin repository!") debug("Cloned revision: %s" % originRevision) originProject = getProjectFromPath(originPath) originName = originProject.getName() else: originProject = session.getProjectByName(origin) if originProject is not None: originPath = originProject.getPath() originName = origin elif os.path.isdir(origin): originPath = origin originProject = getProjectFromPath(originPath) originName = originProject.getName() else: raise JasyError("Invalid value for origin: %s" % origin) # Figure out the skeleton root folder skeletonDir = os.path.join(originPath, originProject.getConfigValue("skeletonDir", "skeleton")) if not os.path.isdir(skeletonDir): raise JasyError("The project %s offers no skeletons!" % originName) # For convenience: Use first skeleton in skeleton folder if no other selection was applied if skeleton is None: skeleton = getFirstSubFolder(skeletonDir) # Finally we have the skeleton path (the root folder to copy for our app) skeletonPath = os.path.join(skeletonDir, skeleton) if not os.path.isdir(skeletonPath): raise JasyError('Skeleton %s does not exist in project "%s"' % (skeleton, originName)) # # Actual Work # # Prechecks done info( "Creating %s from %s %s...", colorize(name, "bold"), colorize(skeleton + " @", "bold"), colorize(originName, "magenta"), ) debug("Skeleton: %s", colorize(skeletonPath, "grey")) debug("Destination: %s", colorize(destinationPath, "grey")) # Copying files to destination info("Copying files...") shutil.copytree(skeletonPath, destinationPath) debug("Files were copied successfully.") # Build data for template substitution data = {} data.update(argv) data["name"] = name data["origin"] = originName data["skeleton"] = os.path.basename(skeletonPath) data["jasy"] = jasy.__version__ # Do actual replacement of placeholders massFilePatcher(destinationPath, data) debug("Files were patched successfully.") # Change to directory before continuing os.chdir(destinationPath) # Create configuration file from question configs and custom scripts info("Starting configuration...") config = Config() config.injectValues(**argv) config.readQuestions("jasycreate", optional=True) config.executeScript("jasycreate.py", optional=True) config.write("jasyscript.yaml") # Done info("Your application %s was created successfully!", colorize(name, "bold"))