def __to_svg(self, ged: str) -> bytes: root_family = ged2dot.Config.rootFamilyDefault layout_max_depth = ged2dot.Config.layoutMaxDepthDefault node_label_image = ged2dot.Config.nodeLabelImageDefault if "FilterData" in self.props.keys(): filter_data = self.to_dict(self.props["FilterData"]) if "rootFamily" in filter_data.keys(): root_family = filter_data["rootFamily"] if "layoutMaxDepth" in filter_data.keys(): layout_max_depth = filter_data["layoutMaxDepth"] if "nodeLabelImage" in filter_data.keys(): node_label_image = filter_data["nodeLabelImage"] config_dict = { 'ged2dot': { 'input': ged, 'rootFamily': root_family, 'layoutMaxDepth': layout_max_depth, 'nodeLabelImage': node_label_image } } config = ged2dot.Config(config_dict) model = ged2dot.Model(config) model.load(config.input) dot = io.StringIO() model.save(dot) if sys.platform.startswith("win"): pattern = os.environ['PROGRAMFILES'] + '\\Graphviz*\\bin\\dot.exe' dot_paths = glob.glob(pattern) if not dot_paths and 'PROGRAMFILES(x86)' in os.environ.keys(): pattern = os.environ[ 'PROGRAMFILES(x86)'] + '\\Graphviz*\\bin\\dot.exe' dot_paths = glob.glob(pattern) if not dot_paths: raise Exception( "No dot.exe found at '%s', please download it from <https://graphviz.gitlab.io/_pages/Download/Download_windows.html>." % pattern) dot_path = dot_paths[-1] else: dot_path = "dot" graphviz = subprocess.Popen([dot_path, '-Tsvg'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) dot.seek(0) graphviz.stdin.write(dot.read().encode('utf-8')) graphviz.stdin.close() noinline = io.BytesIO() noinline.write(graphviz.stdout.read()) graphviz.stdout.close() graphviz.wait() noinline.seek(0) inline = io.BytesIO() inlineize.inlineize(noinline, inline) inline.seek(0) return inline.read()
def convert(self, name, configDict={}): if len(configDict): config = ged2dot.Config(configDict) else: config = ged2dot.Config(["%src" % name]) model = ged2dot.Model(config) model.load(config.input) try: os.unlink("%s.dot" % name) except OSError: pass sock = open("%s.dot" % name, "w") model.save(sock) sock.close() return model
def __extract_families(self) -> None: ged = unohelper.fileUrlToSystemPath(self.props['URL']) config_dict = { 'ged2dot': { 'input': ged, } } config = ged2dot.Config(config_dict) model = ged2dot.Model(config) model.load(config.input) self.family_dict = {} for i in model.families: help_string = "" if i.husb and i.husb.surname: help_string += i.husb.surname help_string += "-" if i.wife and i.wife.surname: help_string += i.wife.surname key = "%s (%s)" % (i.fid, help_string) self.family_dict[key] = i