def gedcom_compare(gedcom1,gedcom2): filename1 = gedcom_utils.gedcom_fullname(gedcom1) filename2 = gedcom_utils.gedcom_fullname(gedcom2) lines1 = gedcom_utils.read_gedcom(filename1) lines2 = gedcom_utils.read_gedcom(filename2) difftable = HtmlDiff().make_file(lines1, lines2, context=True, numlines=2, fromdesc=gedcom1, todesc=gedcom2) rsp = dict(diff=difftable) return jsonify(rsp)
def gedcom_revert(gedcom,version): filename1 = gedcom_utils.gedcom_fullname(gedcom) filename2 = gedcom_utils.gedcom_fullname(version) newname = util.generate_name(filename1) if os.path.exists(filename1) and os.path.exists(filename2): os.rename(filename1,newname) os.rename(filename2,filename1) gedcom_utils.history_append(filename1,"\n{}:".format(util.format_timestamp())) gedcom_utils.history_append(filename1,_("File {} saved as {}").format(filename1,newname)) gedcom_utils.history_append(filename1,_("File {} saved as {}").format(filename2,filename1)) rsp = dict(newname=os.path.basename(newname)) else: rsp = dict(status="Error") return jsonify(rsp)
def gedcom_analyze(gedcom): filename = gedcom_utils.gedcom_fullname(gedcom) metadata = gedcom_utils.get_metadata(gedcom) encoding = metadata['encoding'] logger.info(f'-> bp.gedcom.routes.gedcom_analyze f="{gedcom}"') rsp = gedcom_utils.analyze(filename,encoding) return rsp
def gedcom_save(gedcom): filename1 = gedcom_utils.gedcom_fullname(gedcom) filename2 = filename1 + "-temp" newname = util.generate_name(filename1) os.rename(filename1,newname) os.rename(filename2,filename1) gedcom_utils.history_append(filename1,"\n{}:".format(util.format_timestamp())) gedcom_utils.history_append(filename1,_("File {} saved as {}").format(filename1,newname)) gedcom_utils.history_append(filename1,_("File {} saved as {}").format(filename2,filename1)) logger.info(f'-> bp.gedcom.routes.gedcom_save f="{os.path.basename(newname)}"') rsp = dict(newname=os.path.basename(newname)) return jsonify(rsp)
def get_excerpt(gedcom,linenum): filename = gedcom_utils.gedcom_fullname(gedcom) metadata = gedcom_utils.get_metadata(gedcom) encoding = metadata['encoding'] lines = open(filename,encoding=encoding).readlines() firstline = linenum-1 while not lines[firstline].startswith("0"): firstline -= 1 if firstline < 0: firstline = 0 html = "" for i,line in enumerate(lines[firstline:linenum+9]): line = line.strip() if i > 0 and firstline+i > linenum-1 and line.startswith("0"): break html += f"<br><span class=linenum>{firstline+i+1}</span>: " if firstline+i == linenum-1: html += f"<span class=current_line>{line}</span>" else: html += f"{line}" return html
def gedcom_info(gedcom): filename = gedcom_utils.gedcom_fullname(gedcom) if not os.path.exists(filename): flash(_("That GEDCOM file does not exist on the server"), category='flash_error') return redirect(url_for('gedcom.gedcom_list')) metadata = gedcom_utils.get_metadata(gedcom) transforms = gedcom_utils.get_transforms() encoding = metadata.get('encoding','utf-8') info = metadata.get('info') if gedcom_utils.get_gedcom_user() != current_user.username and not metadata.get("admin_permission"): flash(_("You don't have permission to view that GEDCOM"), category='flash_error') return redirect(url_for('gedcom.gedcom_list')) if info: info = eval(info) else: info = gedcom_utils.get_info(filename,encoding) metadata['info'] = repr(info.__dict__) gedcom_utils.save_metadata(gedcom,metadata) logger.info(f'-> bp.gedcom.routes.gedcom_info f="{gedcom}"') return render_template('gedcom_info.html', user=gedcom_utils.get_gedcom_user(), gedcom=gedcom, filename=filename, info=info, transforms=transforms, maxsize=shareds.app.config.get("MAX_CONTENT_LENGTH"), metadata=metadata)
def gedcom_history(gedcom): history_filename = gedcom_utils.gedcom_fullname(gedcom) + "-history" return open(history_filename).read()
def gedcom_transform(gedcom,transform): """ Execute the pre-defined transformation. """ gedcom_filename = gedcom_utils.gedcom_fullname(gedcom) transform_module, parser = build_parser(transform, gedcom, gedcom_filename) if request.method == 'GET': """ (1) Shows transformation parameter page """ rows = parser.generate_option_rows() return render_template('gedcom_transform_params.html', gedcom=gedcom, transform=transform, transform_name=transform_module.name, rows=rows) else: """ (2) Starts the transformation with parameters from (1). """ logfile = gedcom_filename + "-log" # print("#logfile:",logfile) gedcom_utils.removefile(logfile) args = parser.build_command(request.form.to_dict()) encoding = util.guess_encoding(gedcom_filename) logging.info(f"Guessed encoding {encoding} for {gedcom_filename}") args += f" --encoding {encoding}" if hasattr(transform_module, "transformer"): """ (2a) Runs Gedcom transformation using bp.gedcom.models.processor.process_gedcom """ command_args = parser.build_command_args(request.form.to_dict()) arglist = [gedcom_filename] + command_args arglist += ["--logfile",logfile] arglist += ["--encoding",encoding] module_name = transform_module.__name__.split('.')[-1] logger.info(f'-> bp.gedcom.routes.gedcom_transform/{module_name}') rsp = process_gedcom(arglist, transform_module) return jsonify(rsp) """ (2b) Runs Gedcom transformation by obsolete stand alone program emulation. Used only for older bp.gedcom.transforms.names, to be replaced by bp.gedcom.transforms.person_names """ #TODO EI PYTHON EXCECUTABLEN POLKUA, miten korjataan python_exe = sys.executable or "/opt/jelastic-python37/bin/python3" python_path = ':'.join([os.path.join(APP_ROOT, 'app'), GEDCOM_APP]) gedcom_app = GEDCOM_APP transform_py = os.path.join(GEDCOM_APP, "gedcom_transform.py") tr_args = "{} {} {} {} {}".\ format(transform[:-3], gedcom_filename, args, "--logfile", logfile) cmd3 = "cd '{}'; PYTHONPATH='{}' {} {} {}".\ format(gedcom_app, python_path, python_exe, transform_py, tr_args) gedcom_utils.history_append(gedcom_filename,cmd3) print("#Doing " + cmd3) p = subprocess.Popen(cmd3, shell=True, cwd=gedcom_app, stdout=subprocess.PIPE, stderr=subprocess.PIPE) s1 = p.stdout.read().decode('UTF-8') s2 = p.stderr.read().decode('UTF-8') p.wait() if s2: gedcom_utils.history_append(gedcom_filename,"\nErrors:\n"+s2) # s = "\n" + _("Errors:") + "\n" + s2 + "\n\n" + s1 try: log = open(logfile).read() except FileNotFoundError: log = "" rsp = dict(stdout=log + "\n" + s1,stderr=s2,oldname="",logfile=logfile, diff="",plain_text=True) return jsonify(rsp)
def gedcom_check(gedcom): fullname = gedcom_utils.gedcom_fullname(gedcom) if os.path.exists(fullname): return "exists" else: return "does not exist"