def post(self, p): if not files.exists(p): abort(404, message=('File not found: %s' % p)) o = json.load(request.stream) if not (isinstance(o, dict) and 'command' in o): abort(400) cmd = o['command'] try: if cmd == 'move': if not 'to' in o: abort(400) files.move_file(p, o['to']) elif cmd == 'copy': if not 'to' in o: abort(400) files.copy_file(p, o['to']) elif cmd == 'mkdir': name = o['name'] if '/' in name: abort(400, message='Invalid filename.') if not files.is_directory(p): abort(400, message='Not a directory.') if not 'name' in o: abort(400) return files.mkdir(p, name) else: abort(400, message=('Invalid command: %s' % cmd)) except OSError as e: abort(500, message=('File system error: ' + e.strerror)) except IOError as e: abort(500, message=('File system error: ' + e.strerror)) return '', 204
def file_paste(): p = request.form['p'] path = '/'+p action = session['clipboard'] fs = users.get_clipboard(g.user_id) if action == 'Cut': for f in fs: files.move_file(f, path) else: for f in fs: files.copy_file(f, path) return redirect(url_for('.file_ui', p=p))
def file_paste(): p = request.form['p'] path = '/' + p action = session['clipboard'] fs = users.get_clipboard(g.user_id) if action == 'Cut': for f in fs: files.move_file(f, path) else: for f in fs: files.copy_file(f, path) return redirect(url_for('.file_ui', p=p))
def build(self): # Document modules from source dir into self.temp_docs, remove temp conf.py, replace with template apidoc_command = f"-F -o {self.temp_docs} {self.source}".split(" ") print(f"Running sphinx api doc... [{apidoc_command}]") sphinx_apidoc_cmd(apidoc_command) conf_py_target = str(self.temp_docs / "conf.py") unlink(conf_py_target) data = asdict( SphinxKWArgs( sphinx_docs_target=str(self.source), project_name="", copyright="", author="", )) print("Rendering conf.py...") render_jinja_file(str(TEMPLATES_DIR / "conf.template"), conf_py_target, data) print("Replacing .rst files with available notebooks...") for notebook in self.notebook_path_iterator: unlink(self.temp_docs / f"{notebook.stem}.rst", ignore_errors=True) copy_file(source=notebook, target=(self.temp_docs / notebook.name)) build_command = f"-b html {self.temp_docs} {self.temp_docs / '_build'}" print(f"Running sphinx build... [{build_command}]") sphinx_build_cmd(build_command.split(" ")) change_log = ChangeLog() for source_dir in self.source_item_iterator: update_or_create_item(source_dir, self.target, self.temp_docs, change_log) target_static = self.target / "_static/_static" if not target_static.exists(): copy_file(self.temp_docs / "_build/_static", target_static) build_catalog_json(self.target_item_iterator, self.target) render_index(self.target_item_iterator, self.target) render_pages(self.target_item_iterator, self.target / "_static") copy_file(STATIC_DIR / "styles.css", self.target / "_static" / "styles.css") write_change_log(self.target / "README.md", change_log) rmtree(str(self.temp_docs))
def update_or_create_item(source_dir: Path, target: Path, temp_docs: Path, change_log: ChangeLog): # Copy source directories to target directories, if target already has the directory, archive previous version source_yaml = yaml.load(open(source_dir / "item.yaml", "r"), Loader=yaml.FullLoader) source_version = source_yaml["version"] target_dir = target / source_dir.stem target_latest = target_dir / "latest" target_version = target_dir / source_version html_dir = temp_docs / "_build" html_file_name = f"{source_dir.stem}.html" html_path = html_dir / html_file_name update_html_resource_paths(html_path, relative_path="../../_static/") # If its the first source is encountered, copy source to target if not target_dir.exists(): copy_file(source_dir, target_latest) copy_file(source_dir, target_version) copy_file(html_path, target_latest / html_file_name) copy_file(html_path, target_version / html_file_name) change_log.new_item(source_dir.stem, source_version) if target_version.exists() or source_version == target_version: return rmtree(target_latest) copy_file(source_dir, target_latest) copy_file(source_dir, target_version) copy_file(html_path, target_latest / html_file_name) copy_file(html_path, target_version / html_file_name) change_log.update_item(source_dir.stem, source_version, target_version.name)