[game-data-packager] 18/24: Improve diagnostics and error handling
Simon McVittie
smcv at debian.org
Tue Dec 30 01:32:04 UTC 2014
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch master
in repository game-data-packager.
commit 20dbc1c23faaf1a472df8bcfd90f77f98d35e086
Author: Simon McVittie <smcv at debian.org>
Date: Mon Dec 29 17:21:03 2014 +0000
Improve diagnostics and error handling
In particular, give up before downloading anything if we can't
possibly get all the files anyway.
---
lib/game_data_packager/__init__.py | 55 +++++++++++++++++++++++++++++++++-----
lib/game_data_packager/__main__.py | 5 +++-
2 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/lib/game_data_packager/__init__.py b/lib/game_data_packager/__init__.py
index e26fff9..ee8997e 100644
--- a/lib/game_data_packager/__init__.py
+++ b/lib/game_data_packager/__init__.py
@@ -455,18 +455,27 @@ class GameDataPackage(object):
logger.warning('file "%s" does not exist or is not a file or ' +
'directory', path)
- def fill_gaps(self, download=False):
+ def fill_gaps(self, download=False, log=True):
+ possible = True
+
for (filename, wanted) in self.files.items():
if wanted.install and filename not in self.found:
- self.fill_gap(wanted, download=download)
+ if not self.fill_gap(wanted, download=download):
+ possible = False
+
+ return possible
+
+ def consider_tar_stream(self, name, tar, provider):
+ should_provide = set(provider.provides)
- def consider_tar_stream(self, name, tar):
for entry in tar:
if not entry.isfile():
continue
- for (filename, wanted) in self.files.items():
- if filename in self.found:
+ for filename in provider.provides:
+ wanted = self.files.get(filename)
+
+ if wanted is None:
continue
if wanted.size is not None and wanted.size != entry.size:
@@ -476,6 +485,11 @@ class GameDataPackage(object):
for lf in wanted.look_for:
if match_path.endswith('/' + lf):
+ should_provide.discard(filename)
+
+ if filename in self.found:
+ continue
+
entryfile = tar.extractfile(entry)
tmp = os.path.join(self.get_workdir(),
@@ -497,6 +511,11 @@ class GameDataPackage(object):
if not self.use_file(wanted, tmp, hf):
os.remove(tmp)
+ if should_provide:
+ for missing in sorted(should_provide):
+ logger.error('%s should have provided %s but did not',
+ name, missing)
+
def choose_mirror(self, wanted):
mirrors = []
for mirror_list, details in wanted.download.items():
@@ -525,11 +544,16 @@ class GameDataPackage(object):
random.shuffle(mirrors)
return mirrors
- def fill_gap(self, wanted, download=False):
+ def fill_gap(self, wanted, download=False, log=True):
logger.debug('could not find %s, trying to derive it...', wanted.name)
+ possible = False
+
for provider_name in self.providers.get(wanted.name, ()):
provider = self.files[provider_name]
+ if provider.download or provider_name in self.found:
+ possible = True
+
if (download and provider_name not in self.found and
provider.download):
logger.debug('trying to download %s to provide %s...',
@@ -595,7 +619,24 @@ class GameDataPackage(object):
found_name,
mode='r|' + fmt[4:],
fileobj=rf) as tar:
- self.consider_tar_stream(found_name, tar)
+ self.consider_tar_stream(found_name, tar, provider)
+
+ if not possible:
+ if log:
+ logger.error('could not find %s:\n' +
+ ' expected:\n' +
+ ' size: %d bytes\n' +
+ ' md5: %s\n' +
+ ' sha1: %s\n' +
+ ' sha256: %s',
+ wanted.name,
+ wanted.size,
+ wanted.md5,
+ wanted.sha1,
+ wanted.sha256)
+ return False
+
+ return True
def check_complete(self, log=False):
# Got everything?
diff --git a/lib/game_data_packager/__main__.py b/lib/game_data_packager/__main__.py
index ea7d3af..5e760ef 100644
--- a/lib/game_data_packager/__main__.py
+++ b/lib/game_data_packager/__main__.py
@@ -41,7 +41,10 @@ def go(argv):
for arg in args.paths:
package.consider_file_or_dir(arg)
- package.fill_gaps()
+ if not package.fill_gaps(log=True):
+ # cannot possibly continue
+ sys.exit(1)
+
package.fill_gaps(download=True)
if not package.fill_dest_dir(os.environ['DESTDIR']):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git
More information about the Pkg-games-commits
mailing list