update to subdir mgmt, active work undergoing on kant, and some notes for future projects for arch pkg mgmt
This commit is contained in:
parent
efa84759da
commit
eddf7750c7
89
arch/reference
Normal file
89
arch/reference
Normal file
@ -0,0 +1,89 @@
|
||||
some random snippets to incorporate...
|
||||
|
||||
|
||||
|
||||
######################
|
||||
this was to assist with https://www.archlinux.org/news/perl-library-path-change/
|
||||
the following was used to gen the /tmp/perlfix.pkgs.lst:
|
||||
pacman -Qqo '/usr/lib/perl5/vendor_perl' >> /tmp/perlfix.pkgs.lst ; pacman -Qqo '/usr/lib/perl5/site_perl' >> /tmp/perlfix.pkgs.lst
|
||||
######################
|
||||
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import datetime
|
||||
import re
|
||||
import os
|
||||
import pprint
|
||||
import subprocess
|
||||
|
||||
pkgs = []
|
||||
|
||||
pkglstfile = '/tmp/perlfix.pkgs.lst'
|
||||
|
||||
if os.path.isfile(pkglstfile):
|
||||
with open(pkglstfile, 'r') as f:
|
||||
pkgs = f.read().splitlines()
|
||||
|
||||
pkgd = {'rdeps': [],
|
||||
'deps': [],
|
||||
'remove': []}
|
||||
|
||||
for p in pkgs:
|
||||
pkgchkcmd = ['apacman', '-Q', p]
|
||||
with open(os.devnull, 'w') as devnull:
|
||||
pkgchk = subprocess.run(pkgchkcmd, stdout = devnull, stderr = devnull).returncode
|
||||
if pkgchk != 0: # not installed anymore
|
||||
break
|
||||
cmd = ['apacman',
|
||||
'-Qi',
|
||||
p]
|
||||
stdout = subprocess.run(cmd, stdout = subprocess.PIPE).stdout.decode('utf-8').strip().splitlines()
|
||||
#pprint.pprint(stdout)
|
||||
d = {re.sub('\s', '_', k.strip().lower()):v.strip() for k, v in (dict(k.split(':', 1) for k in stdout).items())}
|
||||
|
||||
# some pythonizations..
|
||||
# list of things(keys) that should be lists
|
||||
ll = ['architecture', 'conflicts_with', 'depends_on', 'groups', 'licenses', 'make_depends',
|
||||
'optional_deps', 'provides', 'replaces', 'required_by']
|
||||
# and now actually listify
|
||||
for k in ll:
|
||||
if k in d.keys():
|
||||
if d[k].lower() in ('none', ''):
|
||||
d[k] = None
|
||||
else:
|
||||
d[k] = d[k].split()
|
||||
# Not necessary... blah blah inconsistent whitespace blah blah.
|
||||
#for k in ('build_date', 'install_date'):
|
||||
# if k in d.keys():
|
||||
# try:
|
||||
# d[k] = datetime.datetime.strptime(d[k], '%a %d %b %Y %H:%M:%S %p %Z')
|
||||
# except:
|
||||
# d[k] = datetime.datetime.strptime(d[k], '%a %d %b %Y %H:%M:%S %p')
|
||||
|
||||
#pprint.pprint(d)
|
||||
if d['required_by']:
|
||||
pkgd['rdeps'].extend(d['required_by'])
|
||||
else:
|
||||
if d['install_reason'] != 'Explicitly installed':
|
||||
pkgd['remove'].append(p)
|
||||
if d['depends_on']:
|
||||
pkgd['deps'].extend(d['depends_on'])
|
||||
#break
|
||||
|
||||
for x in ('rdeps', 'deps'):
|
||||
pkgd[x].sort()
|
||||
|
||||
#for p in pkgd['rdeps']:
|
||||
# if p in pkgd['deps']:
|
||||
# pkgd['
|
||||
|
||||
#print('DEPENDENCIES:')
|
||||
#print('\n'.join(pkgd['deps']))
|
||||
#print('\nREQUIRED BY:')
|
||||
#print('\n'.join(pkgd['rdeps']))
|
||||
#print('\nCAN REMOVE:')
|
||||
print('\n'.join(pkgd['remove']))
|
||||
|
||||
#cmd = ['apacman', '-R']
|
||||
#cmd.extend(pkgd['remove'])
|
||||
#subprocess.run(cmd)
|
@ -107,7 +107,14 @@ def getKeys(args):
|
||||
return(allkeys)
|
||||
|
||||
def sigKeys(keyids):
|
||||
pass
|
||||
# Map the trust levels to "human" equivs
|
||||
trustmap = {0: 'unknown',
|
||||
1: 'untrusted',
|
||||
2: 'marginal',
|
||||
3: 'full',
|
||||
4: 'ultimate'}
|
||||
def promptTrust(kinfo):
|
||||
trust = input('\nWhat trust level should we sign {0} ({1} <{2}>) with?'.format(kinfo['fpr'], kinfo['name'], kinfo['email']))
|
||||
|
||||
def modifyDirmngr(op, args):
|
||||
if not args['keyservers']:
|
||||
|
@ -70,16 +70,19 @@ def destPrep():
|
||||
nowdir = os.path.join(sks['destdir'], NOWstr)
|
||||
curdir = os.path.join(sks['destdir'], 'current')
|
||||
PAST = NOW - datetime.timedelta(days = sks['days'])
|
||||
for thisdir, dirs, files in os.walk(sks['destdir']):
|
||||
for thisdir, dirs, files in os.walk(sks['destdir'], topdown = False):
|
||||
for f in files:
|
||||
fstat = os.stat(os.path.join(thisdir, f))
|
||||
mtime = fstat.st_mtime
|
||||
if int(mtime) < PAST.timestamp():
|
||||
os.remove(os.path.join(thisdir, f))
|
||||
try:
|
||||
os.removedirs(sks['destdir']) # Remove empty dirs
|
||||
except:
|
||||
pass # thisisfine.jpg
|
||||
# Delete if empty dir
|
||||
if len(os.listdir(thisdir)) == 0:
|
||||
os.rmdir(thisdir)
|
||||
#try:
|
||||
# os.removedirs(sks['destdir']) # Remove empty dirs
|
||||
#except:
|
||||
# pass # thisisfine.jpg
|
||||
os.makedirs(nowdir, exist_ok = True)
|
||||
if getpass.getuser() == 'root':
|
||||
uid = getpwnam(sks['user']).pw_uid
|
||||
@ -119,6 +122,9 @@ def compressDB():
|
||||
for f in files:
|
||||
fullpath = os.path.join(thisdir, f)
|
||||
newfile = '{0}.{1}'.format(fullpath, sks['compress'])
|
||||
# TODO: add compressed tarball support.
|
||||
# However, I can't do this on memory-constrained systems for lrzip.
|
||||
# See: https://github.com/kata198/python-lrzip/issues/1
|
||||
with open(sks['logfile'], 'a') as f:
|
||||
f.write('===== {0} Now compressing {1} =====\n'.format(str(datetime.datetime.utcnow()), fullpath))
|
||||
if sks['compress'].lower() == 'gz':
|
||||
|
Loading…
Reference in New Issue
Block a user