Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert py2 scripts in common/ to py3 #2120

Merged
merged 11 commits into from
Apr 7, 2024
Merged
206 changes: 107 additions & 99 deletions common/Legacy/Scripts/dep_check.py
Original file line number Diff line number Diff line change
@@ -1,108 +1,116 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import pisi.api
import commands
import sys
import os
import subprocess
import sys

import pisi.api

blacklist = (
"/lib/linux-gate.",
"/lib/libm.",
"/lib/ld-linux.",
"/lib/libc.",
"/lib/librt.",
"linux-gate.so.1",
"/lib/libpthread.",
"/lib/libdl.",
)


def package_for_file(filename):
return pisi.api.search_file(filename)


def blacklisted(filename):
if not filename.startswith("/"):
filename = f"/{filename}"
for f in blacklist:
if f in filename:
return True
return False


blacklist = ('/lib/linux-gate.','/lib/libm.', '/lib/ld-linux.', '/lib/libc.', '/lib/librt.', 'linux-gate.so.1', '/lib/libpthread.', '/lib/libdl.')

def package_for_file (filename):
return pisi.api.search_file (filename)

def blacklisted (filename):
if not filename.startswith("/"):
filename = "/%s" % filename
for f in blacklist:
if f in filename:
return True
return False

def ldd (filename):

if "usr/share" in filename:
return

ldd = commands.getoutput ("ldd %s" % filename)

for line in ldd.split ("\n"):
line = line.replace("\n","").replace("\r","").strip()
if line == "":
continue
splits = line.split ("=>")
sourceLib = splits[0].strip()
if len(splits) > 1:
sourceLib = splits[1].strip().split (" ")[0]
else:
sourceLib = sourceLib.split (" ")[0].strip()

# Skip blacklisted
if blacklisted (sourceLib):
continue

if os.path.exists (sourceLib):
dep = package_for_file (sourceLib)

if len(dep) > 0:
# Circular dependencies are ugly :p
if dep[0][0] == sys.argv[1]:
break
# Check its not accounted for
if not dep[0][0] in dependsOn:
dependsOn[ dep[0][0] ] = "/%s" % dep [0][1][0]
def ldd(filename):
if "usr/share" in filename:
return

ldd = subprocess.getoutput(f"ldd {filename}")

for line in ldd.split("\n"):
line = line.replace("\n", "").replace("\r", "").strip()
if line == "":
continue
splits = line.split("=>")
sourceLib = splits[0].strip()
if len(splits) > 1:
sourceLib = splits[1].strip().split(" ")[0]
else:
sourceLib = sourceLib.split(" ")[0].strip()

# Skip blacklisted
if blacklisted(sourceLib):
continue

if os.path.exists(sourceLib):
dep = package_for_file(sourceLib)

if len(dep) > 0:
# Circular dependencies are ugly :p
if dep[0][0] == sys.argv[1]:
break
# Check its not accounted for
if not dep[0][0] in dependsOn:
dependsOn[dep[0][0]] = f"/{dep[0][1][0]}"


if __name__ == "__main__":

if len(sys.argv) != 2:
print "Usage: %s package_name" % sys.argv[0]
sys.exit (1)

pkg = sys.argv[1]
try:
meta,files,other = pisi.api.info_name (pkg, True)
except:
print "Could not find package: %s" % pkg
sys.exit (1)

dependsOn = dict()

for file in files.list:
filename = file.path
if not filename.startswith("/"):
filename = "/%s" % filename


if hasattr(file, 'type'):
if file.type == "executable":
ldd (filename)
elif file.type == "library" and ".so" in filename:
ldd (filename)
else:
if ".so" in filename:
ldd (filename)


print "[ Dependencies ]"
for dep in dependsOn:
print "Depends on %s from %s" % (dependsOn[dep], dep)

print "\n[ XML Dependencies ]"
print "<RuntimeDependencies>"
for dep in dependsOn:
print " <Dependency>%s</Dependency>" % dep
print "</RuntimeDependencies>"

# Suggest build dependencies
print "\n[XML Build Dependencies]"
print "<BuildDependencies>"
for dep in dependsOn:
package = "%s-devel" % dep
try:
subject = pisi.api.info_name (package, True)
print " <Dependency>%s</Dependency>" % package
except:
print " <!-- Info: no %s package - consider splitting -->" % package
print "</BuildDependencies>"
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} package_name")
sys.exit(1)

pkg = sys.argv[1]
try:
meta, files, other = pisi.api.info_name(pkg, True)
except Exception:
print(f"Could not find package: {pkg}")
sys.exit(1)

dependsOn = dict()

for file in files.list:
filename = file.path
if not filename.startswith("/"):
filename = f"/{filename}"

if hasattr(file, "type"):
if file.type == "executable":
ldd(filename)
elif file.type == "library" and ".so" in filename:
ldd(filename)
else:
if ".so" in filename:
ldd(filename)

print("[ Dependencies ]")
for dep in dependsOn:
print(f"Depends on {dependsOn[dep]} from {dep}")

print("\n[ XML Dependencies ]")
print("<RuntimeDependencies>")
for dep in dependsOn:
print(f" <Dependency>{dep}</Dependency>")
print("</RuntimeDependencies>")

# Suggest build dependencies
print("\n[XML Build Dependencies]")
print("<BuildDependencies>")
for dep in dependsOn:
package = f"{dep}-devel"
try:
subject = pisi.api.info_name(package, True)
print(f" <Dependency>{package}</Dependency>")
except Exception:
print(f" <!-- Info: no {package} package - consider splitting -->")
print("</BuildDependencies>")
23 changes: 13 additions & 10 deletions common/Legacy/Scripts/find-old-packages.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Helper script to find any packages not rebuilt in a while

import pisi.db
import datetime
import time

import pisi.db

DAY = 86400 # 86400 seconds in a day
PERIOD = 365 * DAY

class HistoryTeacher:

class HistoryTeacher:
pdb = None
tipbucket = None
stamp = None
Expand All @@ -21,12 +22,12 @@ def __init__(self):
self.stamp = float(time.time())

def assess(self):
""" Walk all known packages in repo """
"""Walk all known packages in repo"""
for key in self.pdb.list_packages(None):
self.maybe_push(key)

def maybe_push(self, key):
""" Maybe assign the package to the tipbucket """
"""Maybe assign the package to the tipbucket"""
if key in self.tipbucket:
return
if not self.pdb.has_package(key):
Expand All @@ -37,18 +38,18 @@ def maybe_push(self, key):
self.tipbucket[key] = whence

def sensible_date(self, shittyInput):
""" Return probably wonky date into a usable timestamp """
"""Return probably wonky date into a usable timestamp"""
try:
whence = datetime.datetime(*time.strptime(shittyInput, "%Y-%m-%d")[0:6])
except:
except Exception:
try:
whence = datetime.datetime(*time.strptime(shittyInput, "%d-%m-%Y")[0:6])
except:
except Exception:
whence = datetime.datetime(*time.strptime(shittyInput, "%m-%d-%Y")[0:6])
return time.mktime(whence.timetuple())

def dumpDelinquints(self):
""" Dump the nasty fecks out """
"""Dump the nasty fecks out"""
oldFogies = []
for key in self.tipbucket:
# Only show source names instead of package names
Expand All @@ -69,13 +70,15 @@ def dumpDelinquints(self):
oldFogies.sort()
print("Not rebuilt in 31 days or more:\n\n")
for fogie in oldFogies:
print(" > {}".format(fogie))
print((" > {}".format(fogie)))


def main():
teacher = HistoryTeacher()
teacher.assess()
teacher.dumpDelinquints()
pass


if __name__ == "__main__":
main()
Loading
Loading