def compile_and_process(self, in_path): """compile a file, save it to the ouput file if the inline flag true""" out_path = self.path_mapping[in_path] if not self.embed: pdebug("[%s::%s] %s -> %s" % ( self.compiler_name, self.name, os.path.relpath(in_path), os.path.relpath(out_path)), groups=["build_task"], autobreak=True) else: pdebug("[%s::%s] %s -> <cache>" % ( self.compiler_name, self.name, os.path.relpath(in_path)), groups=["build_task"], autobreak=True) compiled_string = self.compile_file(in_path) if not self.embed: if compiled_string != "": with open(out_path, "w") as f: f.write(compiled_string) return compiled_string
def sftp_copy_recursive(remote, localpath, remotepath, merge=True, replace=True): local_isdir = os.path.isdir(localpath) remote_exists = remote.exists(remotepath) remote_isdir = remote_exists and remote.isdir(remotepath) pdebug("sftp %s -> %s" %(localpath, remotepath)) if remote_exists: if remote_isdir: if local_isdir and merge: # copy each elem in directory over for elem in os.listdir(localpath): sftp_copy_recursive(remote, os.path.join(localpath, elem), os.path.join(remotepath, elem), merge=merge, replace=replace) elif local_isdir and not merge: pwarning("not merging files!") if not local_isdir: # put file in folder sftp_copy_recursive(remote, localpath, os.path.join(remotepath, os.path.basename(localpath)), merge=merge, replace=replace) else: if replace: # remove old file and replace it remote.remove(remotepath) remote.put(localpath, remotepath) else: pwarning("not replacing file") else: # just copy it over with the correct pysftp function if local_isdir: remote.mkdir(remotepath) remote.put_r(localpath, remotepath) else: remote.put(localpath, remotepath)
def __init__(self, minify=True, embed=True, concat=True, source_dir=None, target_dir=None, build_targets=[], relative_directory="./", external_template_string=None, embed_template_string=None, **kwargs): BuildTarget.__init__(self, **kwargs) self.relative_directory = relative_directory self.input_directory = os.path.abspath(source_dir) self.output_directory = os.path.abspath(target_dir) self.compiler_name = "???" pdebug(self.input_directory) pdebug(self.output_directory) self.build_targets = [os.path.abspath( os.path.join( self.input_directory, target)) for target in build_targets] self.file_watch_targets = self.build_targets if embed_template_string: self.embed_template_string = embed_template_string if external_template_string: self.external_template_string = external_template_string self.minify = minify self.embed = embed self.concat = concat