Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --exclude option to rhnget #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions rhnget
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Options:
self.cleanup = False
self.downloadall = False
self.dryrun = False
self.exclude = []
self.filter = None
self.list = None
self.quiet = False
Expand All @@ -59,8 +60,8 @@ class Options:

try:
opts, args = getopt.getopt (args, 'hlnqp:r:s:u:v',
('delete', 'download-all', 'dry-run', 'filter=', 'help', 'list', 'password=', 'quiet',
'release=', 'source', 'systemid=', 'username=', 'verbose', 'version' ))
('delete', 'download-all', 'dry-run', 'exclude=', 'filter=', 'help', 'list', 'password=',
'quiet', 'release=', 'source', 'systemid=', 'username=', 'verbose', 'version' ))
except getopt.error, exc:
print 'rhnget: %s, try rhnget -h for a list of all the options' % str(exc)
sys.exit(1)
Expand All @@ -70,6 +71,8 @@ class Options:
self.cleanup = True
elif opt in ('--download-all', ):
self.downloadall = True
elif opt in ('--exclude', ):
self.exclude = parts = arg.split(',')
elif opt in ('--filter', ):
self.filter = arg
self.downloadall = True
Expand Down Expand Up @@ -138,6 +141,7 @@ class Options:
rhnget options:
--delete delete files that are not on the sender side
--download-all download all package versions available
--exclude list of packages to exclude based on regexp (e.g., java*bea*,auto-kickstart*)
--filter filter packages based on regexp
-l, --list list the available packages
-n, --dry-run show what would have been done
Expand Down Expand Up @@ -413,6 +417,16 @@ def mirrorrhn(url, path):
filename = '%s-%s-%s.%s.rpm' % (pkg[0], pkg[1], pkg[2], pkg[4])
filesize = int(pkg[5])

### Exclude files
skip = False
for pattern in op.exclude:
if fnmatch.fnmatch(filename, pattern):
info(4, 'Package %s excluded by %s' % (filename, pattern))
skip = True
break

if skip: continue

### Filter packagelist
if op.filter and not fnmatch.fnmatch(filename, op.filter):
info(4, 'Packages %s excluded by filter' % filename)
Expand Down