X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Futils.py;h=c75b6be6a5edb8f24b7d52f2eaa274df445fc704;hb=321e814e04b7e01820120fd888e55975dafc240a;hp=084ac195bad036266d869de61b2933e752562612;hpb=bc9a2e0eec14192fca315cf4562374d9bedf9fe9;p=dak.git diff --git a/daklib/utils.py b/daklib/utils.py old mode 100755 new mode 100644 index 084ac195..c75b6be6 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -44,6 +44,7 @@ import subprocess import ldap import daklib.config as config +import daklib.daksubprocess from dbconn import DBConn, get_architecture, get_component, get_suite, \ get_override_type, Keyring, session_wrapper, \ get_active_keyring_paths, get_primary_keyring_path, \ @@ -65,7 +66,6 @@ from collections import defaultdict ################################################################################ default_config = "/etc/dak/dak.conf" #: default dak config, defines host properties -default_apt_config = "/etc/dak/apt.conf" #: default apt config, not normally used alias_cache = None #: Cache for email alias checks key_uid_email_cache = {} #: Cache for email addresses from gpg key uids @@ -78,7 +78,7 @@ known_hashes = [("sha1", apt_pkg.sha1sum, (1, 8)), # code in lenny's Python. This also affects commands.getoutput and # commands.getstatus. def dak_getstatusoutput(cmd): - pipe = subprocess.Popen(cmd, shell=True, universal_newlines=True, + pipe = daklib.daksubprocess.Popen(cmd, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) output = pipe.stdout.read() @@ -720,7 +720,7 @@ def move (src, dest, overwrite = 0, perms = 0o664): dest_dir = dest else: dest_dir = os.path.dirname(dest) - if not os.path.exists(dest_dir): + if not os.path.lexists(dest_dir): umask = os.umask(00000) os.makedirs(dest_dir, 0o2775) os.umask(umask) @@ -728,7 +728,7 @@ def move (src, dest, overwrite = 0, perms = 0o664): if os.path.exists(dest) and os.path.isdir(dest): dest += '/' + os.path.basename(src) # Don't overwrite unless forced to - if os.path.exists(dest): + if os.path.lexists(dest): if not overwrite: fubar("Can't move %s to %s - file already exists." % (src, dest)) else: @@ -751,7 +751,7 @@ def copy (src, dest, overwrite = 0, perms = 0o664): if os.path.exists(dest) and os.path.isdir(dest): dest += '/' + os.path.basename(src) # Don't overwrite unless forced to - if os.path.exists(dest): + if os.path.lexists(dest): if not overwrite: raise FileExistsError else: @@ -762,14 +762,6 @@ def copy (src, dest, overwrite = 0, perms = 0o664): ################################################################################ -def where_am_i (): - res = socket.getfqdn() - database_hostname = Cnf.get("Config::" + res + "::DatabaseHostname") - if database_hostname: - return database_hostname - else: - return res - def which_conf_file (): if os.getenv('DAK_CONFIG'): return os.getenv('DAK_CONFIG') @@ -780,7 +772,7 @@ def which_conf_file (): homedir = os.getenv("HOME") confpath = os.path.join(homedir, "/etc/dak.conf") if os.path.exists(confpath): - apt_pkg.ReadConfigFileISC(Cnf,confpath) + apt_pkg.read_config_file_isc(Cnf,confpath) # We are still in here, so there is no local config file or we do # not allow local files. Do the normal stuff. @@ -789,14 +781,6 @@ def which_conf_file (): return default_config -def which_alias_file(): - hostname = socket.getfqdn() - aliasfn = '/var/lib/misc/'+hostname+'/forward-alias' - if os.path.exists(aliasfn): - return aliasfn - else: - return None - ################################################################################ def TemplateSubst(subst_map, filename): @@ -894,7 +878,7 @@ def changes_compare (a, b): def find_next_free (dest, too_many=100): extra = 0 orig_dest = dest - while os.path.exists(dest) and extra < too_many: + while os.path.lexists(dest) and extra < too_many: dest = orig_dest + '.' + repr(extra) extra += 1 if extra >= too_many: @@ -1425,6 +1409,30 @@ def get_logins_from_ldap(fingerprint='*'): ################################################################################ +def get_users_from_ldap(): + """retrieve login and user names from LDAP""" + + LDAPDn = Cnf['Import-LDAP-Fingerprints::LDAPDn'] + LDAPServer = Cnf['Import-LDAP-Fingerprints::LDAPServer'] + l = ldap.open(LDAPServer) + l.simple_bind_s('','') + Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL, + '(uid=*)', ['uid', 'cn', 'mn', 'sn']) + users = {} + for elem in Attrs: + elem = elem[1] + name = [] + for k in ('cn', 'mn', 'sn'): + try: + if elem[k][0] != '-': + name.append(elem[k][0]) + except KeyError: + pass + users[' '.join(name)] = elem['uid'][0] + return users + +################################################################################ + def clean_symlink (src, dest, root): """ Relativize an absolute symlink from 'src' -> 'dest' relative to 'root'. @@ -1608,7 +1616,7 @@ def get_packages_from_ftp(root, suite, component, architecture): if (result != 0): fubar("Gunzip invocation failed!\n%s\n" % (output), result) packages = open_file(temp_file) - Packages = apt_pkg.ParseTagFile(packages) + Packages = apt_pkg.TagFile(packages) os.unlink(temp_file) return Packages @@ -1666,7 +1674,7 @@ def call_editor(text="", suffix=".txt"): try: print >>tmp, text, tmp.close() - subprocess.check_call([editor, tmp.name]) + daklib.daksubprocess.check_call([editor, tmp.name]) return open(tmp.name, 'r').read() finally: os.unlink(tmp.name) @@ -1742,7 +1750,7 @@ def check_reverse_depends(removals, suite, arches=None, session=None, cruft=Fals if package in removals: continue parsed_dep = [] try: - parsed_dep += apt_pkg.ParseDepends(deps[package]) + parsed_dep += apt_pkg.parse_depends(deps[package]) except ValueError as e: print "Error for package %s: %s" % (package, e) for dep in parsed_dep: @@ -1811,7 +1819,7 @@ def check_reverse_depends(removals, suite, arches=None, session=None, cruft=Fals # Remove [arch] information since we want to see breakage on all arches build_dep = re_build_dep_arch.sub("", build_dep) try: - parsed_dep += apt_pkg.ParseDepends(build_dep) + parsed_dep += apt_pkg.parse_depends(build_dep) except ValueError as e: print "Error for source %s: %s" % (source, e) for dep in parsed_dep: @@ -1826,9 +1834,10 @@ def check_reverse_depends(removals, suite, arches=None, session=None, cruft=Fals .filter(Override.package == re.sub('/(contrib|non-free)$', '', source)) \ .join(Override.overridetype).filter(OverrideType.overridetype == 'dsc') \ .first() + key = source if component != "main": - source = "%s/%s" % (source, component) - all_broken.setdefault(source, set()).add(pp_deps(dep)) + key = "%s/%s" % (source, component) + all_broken.setdefault(key, set()).add(pp_deps(dep)) dep_problem = 1 if all_broken: