From 242896ba37f409042856112261a0e4c4cb5f9657 Mon Sep 17 00:00:00 2001 From: Martinez Date: Thu, 12 Feb 2015 13:15:51 +0100 Subject: [PATCH] app config, parallel filelist generation --- .gitignore | 3 +++ find-orphans.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .gitignore create mode 100755 find-orphans.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a5929e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +__pycache__ +over diff --git a/find-orphans.py b/find-orphans.py new file mode 100755 index 0000000..93c6d0a --- /dev/null +++ b/find-orphans.py @@ -0,0 +1,66 @@ +#! /bin/env python3 +# encoding: utf-8 + +# library imports +import os +import over +import re +import sys +import time + +# -------------------------------------------------- + +prefix = over.core.textui.prefix +_print = over.core.textui.Output('Find Orphans') + +# -------------------------------------------------- +# Functions + +# -------------------------------------------------- +# Classes + +# -------------------------------------------------- + +if __name__ == '__main__': + main = over.core.app.Main('Find Orphans', None, 'AWARE-Overwatch Joint Software License') + main.add_option('filter', 'str', ['/home/*', '/var/*', '*.pyc'], 'Shell globs that should be filtered out.', plural=True) + main.add_option('null-separated', 'bool', False, 'Output each filename separated with a null character. Otherwise use a newline.', short_name='0') + main.add_help('Description', ['Finds files on Gentoo systems that aren\'t owned by any installed package and lists them.']) + main.enable_help('h') + main.parse() + + if not main.targets: + _print('specify at least one directory to work on, e.g. \'/\'', prefix.fail) + main.exit(silent=True) + + # -------------------------------------------------- + # Create a file list + + file_list = [] + threads = [] # {proc, output_buffer} + + for root in main.targets: + proc = over.core.cmd.Command('find', root, '-print0') + proc.run() + threads.append({'proc': proc, 'output_buffer': []}) + + _print('gathering file list using %d processes' %(len(threads)), prefix.start) + + while True: + at_least_one_lives = False + + for thread in threads: + tmp = thread['proc'].get_output() + + if not tmp is None: + thread['output_buffer'].append(tmp) + at_least_one_lives = True + + if at_least_one_lives: + time.sleep(1) + else: + break + + _print('post-processing file list') + +