def write_docset(self, dirname): ensure_dir(self.doc.docset_path) with open(self.doc.docset_path, 'wb') as tmp_file: arc_root = slugify(self.doc.name) compression_file = tarfile.open(name=arc_root + '.gz', mode='w:gz', fileobj=tmp_file) for filename in os.listdir(dirname): full_path = os.path.join(dirname, filename) arcname = os.path.join(os.path.relpath(full_path, dirname)) compression_file.add(full_path, arcname) compression_file.close()
def install_config(self): self.stdout.write(self.style.SUCCESS("installing static files…")) self.execute_hook("pre_install_config") writers = self.get_file_writers( self.written_files_locations, context=self.template_context ) for target_filename in sorted(writers): # fix the writing order writer = writers[target_filename] writer.write( self.host_package_dir, self.template_context, dry_mode=False, verbose_mode=self.verbose_mode, ) # noinspection PyUnresolvedReferences script_content = render_to_string( "djangofloor/vagrant/systemd-web.service", self.template_context ) # noinspection PyStringFormat filename = os.path.join( self.host_package_dir, "etc", "systemd", "system", "%(DF_MODULE_NAME)s-HTTP-worker.service" % self.template_context, ) ensure_dir(filename, parent=True) with open(filename, "w") as fd: fd.write(script_content) local_template_context = {} local_template_context.update(self.template_context) for queue in get_expected_queues(): local_template_context["queue"] = queue # noinspection PyUnresolvedReferences script_content = render_to_string( "djangofloor/vagrant/systemd-worker.service", local_template_context ) # noinspection PyStringFormat filename = os.path.join( self.host_package_dir, "etc", "systemd", "system", "%(DF_MODULE_NAME)s-%(queue)s.service" % local_template_context, ) with open(filename, "w") as fd: fd.write(script_content) self.copy_vagrant_script("djangofloor/vagrant/configure_project.sh") self.execute_hook("post_install_config")
def zip_archive(doc: UploadDoc): ensure_dir(doc.zip_path) arc_root = slugify(doc.name) with open(doc.zip_path, 'wb') as tmp_file: compression_file = zipfile.ZipFile(tmp_file, mode='w', compression=zipfile.ZIP_DEFLATED) path = doc.path documents_dir = os.path.join(path, 'Contents', 'Resources', 'Documents') plist_path = os.path.join(path, 'Contents', 'Info.plist') if os.path.isdir(documents_dir) and os.path.isfile(plist_path): path = documents_dir for (root, dirnames, filenames) in os.walk(path): for filename in filenames: full_path = os.path.join(root, filename) arcname = os.path.join(arc_root, os.path.relpath(full_path, doc.path)) compression_file.write(full_path, arcname) compression_file.close()
def get_log_filenames(): """Return the list of filenames used in all :class:`logging.FileHandler`. """ handlers = [x for x in logging.root.handlers] for name, logger_obj in logging.root.manager.loggerDict.items(): if not isinstance(logger_obj, logging.Logger): continue handlers += logger_obj.handlers handlers = [x for x in handlers if isinstance(x, logging.FileHandler)] filenames = {x.baseFilename for x in handlers} if settings.LOG_DIRECTORY: ensure_dir(settings.LOG_DIRECTORY) filenames |= { os.path.join(settings.LOG_DIRECTORY, x) for x in os.listdir(settings.LOG_DIRECTORY) if x.endswith(".log") } filenames = list(filenames) filenames.sort() return filenames
def prepare(self): path = self.doc.path documents_dir = os.path.join(path, 'Contents', 'Resources', 'Documents') plist_path = os.path.join(path, 'Contents', 'Info.plist') if os.path.isdir(documents_dir) and os.path.isfile(plist_path): with tempfile.TemporaryDirectory(dir=settings.FILE_UPLOAD_TEMP_DIR) as dirname: root = os.path.join(dirname, '%s.docset' % slugify(self.doc.name)) shutil.copytree(self.doc.path, root) self.write_docset(dirname) return with tempfile.TemporaryDirectory(dir=settings.FILE_UPLOAD_TEMP_DIR) as dirname: root = os.path.join(dirname, '%s.docset' % slugify(self.doc.name), 'Contents') ensure_dir(os.path.join(root, 'Resources'), parent=False) index_path = self.doc.index with open(os.path.join(root, 'Info.plist'), 'wb') as fd: info = {'CFBundleIdentifier': slugify(self.doc.name), 'CFBundleName': self.doc.name, 'DocSetPlatformFamily': slugify(self.doc.name), 'isDashDocset': True, 'isJavaScriptEnabled': True} if index_path: info['dashIndexFilePath'] = index_path plistlib.dump(info, fd) shutil.copytree(self.doc.uncompressed_root, os.path.join(root, 'Resources', 'Documents')) self.create_index(root) self.write_docset(dirname)
def handle(self, *args, **options): verbosity = options["verbosity"] ensure_dir(settings.NPM_ROOT_PATH, False) dst_path_dirname = options["to"] for npm_package, patterns in settings.NPM_FILE_PATTERNS.items(): if verbosity > 0: self.stdout.write(self.style.SUCCESS("downloading %s") % npm_package) command = [settings.NPM_EXECUTABLE_PATH, "install", npm_package] try: subprocess.check_output(command, cwd=settings.NPM_ROOT_PATH) except OSError: print("Unable to execute command %s" % " ".join(command)) continue src_package_root = os.path.join( settings.NPM_ROOT_PATH, "node_modules", npm_package ) dst_package_root = os.path.join(dst_path_dirname, npm_package) ensure_dir(dst_package_root) for pattern in patterns: if verbosity > 0: self.stdout.write(self.style.SUCCESS("copying %s files" % pattern)) for src_path in glob.glob(os.path.join(src_package_root, pattern)): dst_path = os.path.join( dst_package_root, os.path.relpath(src_path, src_package_root) ) ensure_dir(dst_path, parent=True) if verbosity > 1: self.stdout.write( self.style.NOTICE("copying %s to %s") % (src_path, dst_path) ) if os.path.isfile(dst_path): os.remove(dst_path) elif os.path.isdir(dst_path): shutil.rmtree(dst_path) if os.path.isfile(src_path): shutil.copy(src_path, dst_path) else: shutil.copytree(src_path, dst_path) if verbosity > 0: self.stdout.write( self.style.SUCCESS( "Selection moved to %s. You can copy it to your " "static source dir." % dst_path_dirname ) )
def handle(self, *args, **options): verbosity = options["verbosity"] ensure_dir(settings.NPM_ROOT_PATH, False) dst_path_dirname = options["to"] for npm_package, patterns in settings.NPM_FILE_PATTERNS.items(): if verbosity > 0: self.stdout.write( self.style.SUCCESS("downloading %s") % npm_package) command = [settings.NPM_EXECUTABLE_PATH, "install", npm_package] try: subprocess.check_output(command, cwd=settings.NPM_ROOT_PATH) except OSError: print("Unable to execute command %s" % " ".join(command)) continue src_package_root = os.path.join(settings.NPM_ROOT_PATH, "node_modules", npm_package) dst_package_root = os.path.join(dst_path_dirname, npm_package) ensure_dir(dst_package_root) for pattern in patterns: if verbosity > 0: self.stdout.write( self.style.SUCCESS("copying %s files" % pattern)) for src_path in glob.glob( os.path.join(src_package_root, pattern)): dst_path = os.path.join( dst_package_root, os.path.relpath(src_path, src_package_root)) ensure_dir(dst_path, parent=True) if verbosity > 1: self.stdout.write( self.style.NOTICE("copying %s to %s") % (src_path, dst_path)) if os.path.isfile(dst_path): os.remove(dst_path) elif os.path.isdir(dst_path): shutil.rmtree(dst_path) if os.path.isfile(src_path): shutil.copy(src_path, dst_path) else: shutil.copytree(src_path, dst_path) if verbosity > 0: self.stdout.write( self.style.SUCCESS( "Selection moved to %s. You can copy it to your " "static source dir." % dst_path_dirname))
def vagrant_box_dir(self): return ensure_dir(os.path.join(self.build_dir, "vagrant"), parent=False)
def host_package_dir(self): return ensure_dir(os.path.join(self.build_dir, "pkg"), parent=False)
def host_tmp_dir(self): return ensure_dir(os.path.join(self.build_dir, "tmp"), parent=False)
def host_install_dir(self): return ensure_dir(os.path.join(self.build_dir, "opt"), parent=False)
def host_dockerfile(self): return ensure_dir(os.path.join(self.host_tmp_dir, "Dockerfile"), parent=True)