- port to over-1.99
- remove --output - remove unused filters
This commit is contained in:
parent
99da8068be
commit
7e48c863c4
2 changed files with 42 additions and 39 deletions
|
@ -10,31 +10,26 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# --------------------------------------------------
|
# local imports
|
||||||
|
import version
|
||||||
prefix = over.core.textui.prefix
|
|
||||||
_print = over.core.textui.Output('Find Orphans')
|
|
||||||
|
|
||||||
# --------------------------------------------------
|
|
||||||
# Functions
|
|
||||||
|
|
||||||
# --------------------------------------------------
|
|
||||||
# Classes
|
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main = over.core.app.Main('Find Orphans', None, 'AWARE-Overwatch Joint Software License')
|
main = over.app.Main("Find Orhpans", version.str, "AO-JSL", features={"config_file": True})
|
||||||
main.add_option('filter', 'str', ['/home/*', '/var/*', '*.pyc', '/lib*/modules/*', '*.pyo', '/usr/share/mime/*', '/usr/local/*'], 'Shell globs that should be filtered out.', plural=True)
|
#main.add_option("filter", "Shell globs that should be filtered out.", over.callback.strings, abbr="f", count=1)
|
||||||
main.add_option('null-separated', 'bool', False, 'Output each filename separated with a null character. Otherwise use a newline.', short_name='0')
|
main.add_option("filter", "Shell globs that should be filtered out.", over.callback.strings, abbr="f", count=1, overwrite=False)
|
||||||
main.add_option('output', 'bool', True, 'Output filenames to stdout. Otherwise just counts them.')
|
main.add_option("null-separated", "Output each filename separated with a null character. Otherwise use a newline.", bool, [False], abbr="0", count=1)
|
||||||
main.add_help('Description', ['Finds files on Gentoo systems that aren\'t owned by any installed package and lists them.'])
|
main.add_doc("Description", ["Finds files on Gentoo systems that aren\"t owned by any installed package and lists them."])
|
||||||
main.enable_help('h')
|
main.setup()
|
||||||
main.parse()
|
|
||||||
|
# works around bug over:#15 (https://git.covalent.cz/overwatch/over/issues/15)
|
||||||
|
if not main.cfg.filter:
|
||||||
|
main.cfg.filter = ["*.pyc", "/lib*/modules/*", "*.pyo", "/usr/share/mime/*", "/usr/local/*", "/usr/src/*"]
|
||||||
|
|
||||||
if not main.targets:
|
if not main.targets:
|
||||||
_print('specify at least one directory to work on, e.g. \'/\'', prefix.fail)
|
main.print("specify at least one directory to work on, e.g. <M>/usr<.> or <M>/lib64<.>", main.print.tl.fail)
|
||||||
main.exit(silent=True)
|
main.exit(1)
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# Create a list of all files
|
# Create a list of all files
|
||||||
|
@ -43,20 +38,20 @@ if __name__ == '__main__':
|
||||||
threads = [] # {proc, output_buffer}
|
threads = [] # {proc, output_buffer}
|
||||||
|
|
||||||
for root in main.targets:
|
for root in main.targets:
|
||||||
proc = over.core.cmd.Command('find', root, '-type', 'f', '-print0')
|
proc = over.cmd.Command("find", root, "-type", "f", "-print0")
|
||||||
proc.run()
|
proc.run()
|
||||||
threads.append({'proc': proc, 'output_buffer': [], 'root': root})
|
threads.append({"proc": proc, "output_buffer": [], "root": root})
|
||||||
|
|
||||||
_print('gathering a list of all files using %d processes' %(len(threads)), prefix.start)
|
main.print("gathering a list of all files using %d processes" %(len(threads)), main.print.tl.start)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
at_least_one_lives = False
|
at_least_one_lives = False
|
||||||
|
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
tmp = thread['proc'].get_output()
|
tmp = thread["proc"].get_output()
|
||||||
|
|
||||||
if not tmp is None:
|
if not tmp is None:
|
||||||
thread['output_buffer'].append(tmp)
|
thread["output_buffer"].append(tmp)
|
||||||
at_least_one_lives = True
|
at_least_one_lives = True
|
||||||
|
|
||||||
if at_least_one_lives:
|
if at_least_one_lives:
|
||||||
|
@ -64,33 +59,33 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
_print('post-processing file list')
|
main.print("post-processing file list")
|
||||||
|
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
output = b''.join(thread['output_buffer']).decode('utf-8')
|
output = b"".join(thread["output_buffer"]).decode("utf-8")
|
||||||
all_files.update(os.path.normpath(os.path.join(os.path.abspath(thread['root']), f)) for f in output.split('\x00') if f)
|
all_files.update(os.path.normpath(os.path.join(os.path.abspath(thread["root"]), f)) for f in output.split("\x00") if f)
|
||||||
|
|
||||||
_print('found %d files' %(len(all_files)), prefix.done)
|
main.print("found %d files" %(len(all_files)), main.print.tl.done)
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# create a list of owned files
|
# create a list of owned files
|
||||||
|
|
||||||
_print('gathering a list of files owned by installed packages', prefix.start)
|
main.print("gathering a list of files owned by installed packages", main.print.tl.start)
|
||||||
|
|
||||||
owned_files = set()
|
owned_files = set()
|
||||||
|
|
||||||
for contents_filename in glob.glob('/var/db/pkg/*/*/CONTENTS'):
|
for contents_filename in glob.glob("/var/db/pkg/*/*/CONTENTS"):
|
||||||
owned_files.update(re.findall('obj (.+) [0-9a-f]+ \d+', open(contents_filename).read()))
|
owned_files.update(re.findall("obj (.+) [0-9a-f]+ \d+", open(contents_filename).read()))
|
||||||
|
|
||||||
unowned_files = all_files - owned_files
|
unowned_files = all_files - owned_files
|
||||||
|
|
||||||
_print('found %d owned files' %(len(owned_files)), prefix.done)
|
main.print("found %d owned files" %(len(owned_files)), main.print.tl.done)
|
||||||
_print('there are %d unowned files' %(len(unowned_files)))
|
main.print("there are %d unowned files" %(len(unowned_files)))
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# apply filters
|
# apply filters
|
||||||
|
|
||||||
_print('applying filters', prefix.start)
|
main.print("applying filters", main.print.tl.start)
|
||||||
|
|
||||||
unowned_files_ignored = set()
|
unowned_files_ignored = set()
|
||||||
|
|
||||||
|
@ -98,12 +93,12 @@ if __name__ == '__main__':
|
||||||
unowned_files_ignored.update(fnmatch.filter(unowned_files, filter))
|
unowned_files_ignored.update(fnmatch.filter(unowned_files, filter))
|
||||||
|
|
||||||
files_to_output = unowned_files - unowned_files_ignored
|
files_to_output = unowned_files - unowned_files_ignored
|
||||||
|
color = "y" if files_to_output else "g"
|
||||||
_print('found §y%d unowned files§/' %(len(files_to_output)), prefix.done)
|
main.print("found <%s>%d unowned files<.>" %(color, len(files_to_output)), main.print.tl.done)
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# output
|
# output
|
||||||
|
|
||||||
if main.cfg.output:
|
if files_to_output:
|
||||||
joiner = '\x00' if main.cfg.null_separated else '\n'
|
joiner = "\x00" if main.cfg.null_separated else "\n"
|
||||||
print(joiner.join(sorted(files_to_output)))
|
print(joiner.join(sorted(files_to_output)))
|
||||||
|
|
8
version.py
Normal file
8
version.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#! /usr/bin/env python3
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
major = 0 # VERSION_MAJOR_IDENTIFIER
|
||||||
|
minor = 2 # VERSION_MINOR_IDENTIFIER
|
||||||
|
# VERSION_LAST_MM 0.2
|
||||||
|
patch = 2 # VERSION_PATCH_IDENTIFIER
|
||||||
|
str = ".".join(str(v) for v in (major, minor, patch))
|
Loading…
Add table
Add a link
Reference in a new issue