Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 783762d319bd1a5461348b3e16d1f32142132ff7
Author: clime <clime(a)redhat.com>
Date: Wed Jan 20 12:40:15 2016 +0100
[prunerepo] --quiet option added to suppress info messages
---------------------------------------------------------------
prunerepo/man/prunerepo.1.asciidoc | 3 +++
prunerepo/prunerepo | 24 +++++++++++++++---------
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/prunerepo/man/prunerepo.1.asciidoc b/prunerepo/man/prunerepo.1.asciidoc
index 2a0bccd..2ba8e4c 100644
--- a/prunerepo/man/prunerepo.1.asciidoc
+++ b/prunerepo/man/prunerepo.1.asciidoc
@@ -46,6 +46,9 @@ OPTIONS
--verbose::
print all deleted items to stdout
+--verbose::
+ do not print any info messages, just do your job
+
-h, --help::
show this help message and exit
diff --git a/prunerepo/prunerepo b/prunerepo/prunerepo
index 95c4252..e7cbf92 100755
--- a/prunerepo/prunerepo
+++ b/prunerepo/prunerepo
@@ -20,6 +20,8 @@ parser.add_argument('--nocreaterepo',
action='store_true',
help='repository is not automatically recreated after
deletion')
parser.add_argument('--verbose', action='store_true',
help='print all deleted items to stdout')
+parser.add_argument('--quiet', action='store_true',
+ help='do not print any info messages, just do your job')
parser.add_argument('-v', '--version', action='version',
version='1.0',
help='print program version and exit')
@@ -40,13 +42,17 @@ get_all_packages_cmd = [
get_latest_packages_cmd = get_all_packages_cmd + [ '--latest-limit=1' ]
+def log_info(msg):
+ if not args.quiet:
+ print(msg)
+
def run_cmd(cmd, silent=False):
"""
Run given command in a subprocess
"""
if not silent:
- print("Executing: "+' '.join(cmd))
+ log_info("Executing: "+' '.join(cmd))
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = process.communicate()
if process.returncode != 0:
@@ -75,7 +81,7 @@ def prune_packages():
"""
Remove obsoleted packages
"""
- print('Removing obsoleted packages...')
+ log_info('Removing obsoleted packages...')
latest_packages = get_packages(get_latest_packages_cmd)
all_packages = get_packages(get_all_packages_cmd)
to_remove_packages = set(all_packages) - set(latest_packages)
@@ -85,16 +91,16 @@ def prune_packages():
continue
os.remove(package)
if args.verbose:
- print("Removing: "+package)
+ log_info("Removing: "+package)
removed_counter += 1
- print('- {} packages removed'.format(removed_counter))
+ log_info('- {} packages removed'.format(removed_counter))
def recreate_repo():
"""
Recreate the repository by using createrepo_c
"""
- print("Recreating repository...")
+ log_info("Recreating repository...")
createrepo_cmd = ['/usr/bin/createrepo_c', '--database',
'--update'] + [ args.path ]
return run_cmd(createrepo_cmd)
@@ -103,7 +109,7 @@ def clean_copr():
"""
Remove whole copr build dirs if they no longer contain a srpm/rpm file
"""
- print("Cleaning COPR repository...")
+ log_info("Cleaning COPR repository...")
removed_counter = 0
for dir_name in os.listdir(args.path):
dir_path = os.path.abspath(os.path.join(args.path, dir_name))
@@ -116,7 +122,7 @@ def clean_copr():
continue
if args.verbose:
- print('Removing: '+dir_path)
+ log_info('Removing: '+dir_path)
shutil.rmtree(dir_path)
removed_counter += 1
@@ -125,10 +131,10 @@ def clean_copr():
buildlog_name = 'build-' + build_id + '.log'
buildlog_path = os.path.abspath(os.path.join(args.path, buildlog_name))
if args.verbose:
- print('Removing: '+buildlog_path)
+ log_info('Removing: '+buildlog_path)
os.remove(os.path.join(args.path, buildlog_path))
- print ('- {} build dirs (with no *.rpm inside) and build logs
removed'.format(removed_counter))
+ log_info('- {} build dirs (with no *.rpm inside) and build logs
removed'.format(removed_counter))
if __name__ == '__main__':