def edit_metadata(paper_name): global CONF, paper_metadata field_name = bottle.request.forms.get('field_name') value = bottle.request.forms.get('new_value') # Locate the paper in question metadata_path = utils.paper_metadata_path(paper_name, CONF) print metadata_path if metadata_path is None: raise bottle.HTTPError() # Load YAML data from the paper's metadata file with open(metadata_path, 'r') as fp: metadata = yaml.load(fp.read()) # If you're changing author names, make the new value a comma-delimited # list. Otherwise, it can safely be a string if field_name == "authors": metadata[field_name] = [str(x).strip() for x in value.split(',')] else: metadata[field_name] = value # Re-write the new metadata with open(metadata_path, 'w') as fp: yaml.safe_dump(metadata, fp, encoding="utf-8") # Update the metadata cache paper_metadata[paper_name] = metadata return value
def command(config, paper_folder_name): metadata_path = utils.paper_metadata_path(paper_folder_name, config) if metadata_path is None: return 1 with open(metadata_path, 'r') as fp: metadata_file_contents = fp.read() try: metadata = yaml.load(metadata_file_contents) except yaml.scanner.ScannerError, e: print "Error loading metadata: %s" % (e) return 1
def command(config, paper_name): """ Edits a paper's metadata with the user's configured editor """ paper_metadata_path = utils.paper_metadata_path(paper_name, config) if paper_metadata_path is None: return 1 edit_command = config.get("general", "editor") + " %s" % ( paper_metadata_path) subproc = subprocess.Popen(shlex.split(edit_command)) subproc.communicate()