Skip to content

Commit

Permalink
Build: more fetch tweaks
Browse files Browse the repository at this point in the history
- df-fetch --disable: exit with error to stop make.
- df-fetch raise error when no URLs specified, or available due to ACLs.
- df-verify report errors consistent with df-fetch.
  • Loading branch information
KonaBlend authored and bradleysepos committed May 25, 2016
1 parent ce3bdc9 commit ccfc9b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
16 changes: 7 additions & 9 deletions make/df-fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self):
self.parser.prog = self.name
self.parser.usage = '%prog [OPTIONS] URL...'
self.parser.description = 'Fetch and verify distfile data integrity.'
self.parser.add_option('--disable', default=False, action='store_true', help='do nothing and exit without error')
self.parser.add_option('--disable', default=False, action='store_true', help='do nothing and exit with error')
self.parser.add_option('--md5', default=None, action='store', metavar='HASH', help='verify MD5 HASH against data')
self.parser.add_option('--accept-url', default=[], action='append', metavar='SPEC', help='accept URL regex pattern')
self.parser.add_option('--deny-url', default=[], action='append', metavar='SPEC', help='deny URL regex pattern')
Expand All @@ -75,11 +75,7 @@ def _load_config2(self, parser, data):

def _run(self, error):
if self.options.disable:
self.infof('%s disabled; nothing to do.\n' % self.name)
sys.exit(0)
if len(self.args) < 1:
self.parser.print_usage()
sys.exit(1)
raise error('administratively disabled')
## create URL objects and keep active
urls = []
i = 0
Expand All @@ -90,6 +86,8 @@ def _run(self, error):
i += 1
## try each URL until first success
error.op = 'download'
if not urls:
raise error('nothing to download')
while urls:
url = urls.pop(0)
try:
Expand All @@ -103,7 +101,7 @@ def _run(self, error):
self.errln('%s failure; %s' % (error.op,x))

def run(self):
error = hb_distfile.ToolError('run')
error = hb_distfile.ToolError(self.name)
try:
self._run(error)
except Exception, x:
Expand All @@ -130,7 +128,7 @@ def _accept(self):
index = 0
for spec in tool.options.accept_url:
if re.search(spec, self.url):
self.rule = 'via accept rule %d: %s' % (index,spec)
self.rule = 'via accept rule[%d]: %s' % (index,spec)
return
index += 1
self.active = False
Expand All @@ -141,7 +139,7 @@ def _deny(self):
for spec in tool.options.deny_url:
if re.search(spec, self.url):
self.active = False
self.rule = 'via deny rule %d: %s' % (index,spec)
self.rule = 'via deny rule[%d]: %s' % (index,spec)
return
index += 1

Expand Down
7 changes: 3 additions & 4 deletions make/df-verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ def _verify(self, filename):

def _run(self, error):
if self.options.disable:
self.infof('%s disabled; nothing to do.\n' % self.name)
self.infof('%s failure; administratively disabled.\n' % self.name)
sys.exit(0)
if len(self.args) != 1:
self.parser.print_usage()
sys.exit(1)
raise error('no file specified')
filename = self.args[0]
if self.options.md5:
error.op = 'verify'
Expand All @@ -78,7 +77,7 @@ def _run(self, error):
self.infof('MD5 (%s) = %s (%d bytes)\n', filename, r.md5, r.size)

def run(self):
error = hb_distfile.ToolError('run')
error = hb_distfile.ToolError(self.name)
try:
self._run(error)
except Exception, x:
Expand Down

0 comments on commit ccfc9b5

Please sign in to comment.