Warning, file /sdk/kde-dev-scripts/portage2craft.py was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 import sys 0002 import re 0003 import os 0004 import subprocess 0005 import argparse 0006 0007 import portage.dep as portage_dep 0008 0009 template = """import info 0010 0011 0012 class subinfo(info.infoclass): 0013 def setTargets(self): 0014 self.versionInfo.setDefaultValues() 0015 0016 self.description = "%(appname)s" 0017 0018 def setDependencies(self): 0019 self.runtimeDependencies["virtual/base"] = "default" 0020 %(qtdeps)s 0021 %(frameworksdeps)s 0022 %(kdeappsdeps)s 0023 %(otherdeps)s 0024 0025 from Package.CMakePackageBase import * 0026 0027 0028 class Package(CMakePackageBase): 0029 def __init__(self): 0030 CMakePackageBase.__init__(self) 0031 """ 0032 0033 def process(app, appname, portage, craft, indent): 0034 print("%sProcessing %s" % (indent, app)) 0035 ebuild = "%s-17.08.1.ebuild" % app 0036 qtdeps = [] 0037 frameworksdeps = [] 0038 kdeappsdeps = [] 0039 otherdeps = [] 0040 qtre = re.compile("\$\(add_qt_dep ([^)]+)\)") 0041 frameworksre = re.compile("\$\(add_frameworks_dep ([^)]+)\)") 0042 kdeappsre = re.compile("\$\(add_kdeapps_dep ([^)]+)\)") 0043 optionalre = re.compile("^[^\?]+\?") 0044 0045 with open(os.path.join(portage, app, ebuild), 'r') as ebuildfile: 0046 allfile = ebuildfile.read() 0047 dependencies = re.search("DEPEND=\"[^\"]*\"", allfile) 0048 0049 if dependencies: 0050 deplines = dependencies.group(0).split("\n") 0051 0052 del deplines[0] # The first one is always spurious 0053 del deplines[-1] # The last one is always spurious 0054 0055 for d in deplines: 0056 depline = d.strip() 0057 qtmatch = qtre.match(depline) 0058 frameworksmatch = frameworksre.match(depline) 0059 kdeappsmatch = kdeappsre.match(depline) 0060 0061 if qtmatch: 0062 qtdeps.append(qtmatch.group(1)) 0063 elif frameworksmatch: 0064 frameworksdeps.append(frameworksmatch.group(1)) 0065 elif kdeappsmatch: 0066 appname = kdeappsmatch.group(1) 0067 0068 with subprocess.Popen(["find", os.path.join(craft, "kde", "applications"), "-name", appname], stdout=subprocess.PIPE) as find: 0069 craftdep = find.stdout.read().decode("utf-8").strip() 0070 0071 if len(craftdep) == 0: 0072 if not process(appname, appname, portage, craft, "%s\t" % indent): 0073 print("%sCould not add application %s, skipping" % (indent, appname)) 0074 0075 return False 0076 0077 kdeappsdeps.append(appname) 0078 elif optionalre.match(depline): 0079 print("%sOptional dep %s" % (indent, depline)) 0080 else: 0081 if portage_dep.isvalidatom(depline): 0082 packagename = portage_dep.dep_getkey(depline).split("/")[1] 0083 0084 # TODO be smart about these types of mappings 0085 if packagename == "eigen": 0086 packagename = "eigen3" 0087 0088 with subprocess.Popen(["find", craft, "-name", packagename], stdout=subprocess.PIPE) as find: 0089 craftdep = find.stdout.read().decode("utf-8").strip() 0090 0091 if len(craftdep) > 0: 0092 otherdeps.append(craftdep[len(craft):]) 0093 else: 0094 print("%sDependency %s not found, skipping" % (indent, packagename)) 0095 return False 0096 else: 0097 print("%sGarbage: %s" % (indent,depline)) 0098 0099 fixedframeworks = [] 0100 0101 for f in frameworksdeps: 0102 with subprocess.Popen(["find", craft, "-name", f], stdout=subprocess.PIPE) as find: 0103 fixedframeworks.append(find.stdout.read().decode("utf-8").strip()[len(craft):]) 0104 0105 qtdepsstr = "\n".join([" self.runtimeDependencies[\"libs/qt5/%s\"] = \"default\"" % q for q in qtdeps]) 0106 frameworksdepsstr = "\n".join([" self.runtimeDependencies[\"%s\"] = \"default\"" % f for f in fixedframeworks]) 0107 kdeappsdepsstr = "\n".join([" self.runtimeDependencies[\"kde/applications/%s\"] = \"default\"" % k for k in kdeappsdeps]) 0108 otherdepsstr = "\n".join([" self.runtimeDependencies[\"%s\"] = \"default\"" % o for o in otherdeps]) 0109 recipe = template % { "appname" : appname, "qtdeps" : qtdepsstr, "frameworksdeps" : frameworksdepsstr, "otherdeps" : otherdepsstr } 0110 outdir = os.path.join(craft, "kde", "applications", app) 0111 0112 os.mkdir(outdir) 0113 0114 with open(os.path.join(outdir, "%s.py" % app), 'w') as out: 0115 out.write(recipe) 0116 0117 return True 0118 0119 if __name__ == "__main__": 0120 parser = argparse.ArgumentParser(description="Translate from portage ebuilds to craft recipes") 0121 0122 parser.add_argument("applist", help="List of applications to translate. Each line in this file is of the form <ebuild name> <application name>", type=argparse.FileType('r')) 0123 parser.add_argument("craft", help="Location of the craft root") 0124 parser.add_argument("--portage", help="Location of the portage ebuilds for KDE (defaults to /usr/portage/kde-apps)", default="/usr/portage/kde-apps") 0125 0126 options = parser.parse_args() 0127 0128 for l in options.applist: 0129 app, appname = tuple(l.strip().split(" ")) 0130 craft_dir = os.path.join(options.craft, "kde/applications/%s" % app) 0131 portage_dir = os.path.join(options.portage, app) 0132 0133 if os.path.exists(craft_dir): 0134 print("%s exists in craft, skipping" % app) 0135 continue 0136 0137 if not os.path.exists(portage_dir): 0138 print("%s does not exist in portage, skipping" % app) 0139 continue 0140 0141 process(app, appname, options.portage, options.craft, "")