[game-data-packager] 04/05: Add --save-downloads option
Simon McVittie
smcv at debian.org
Sat Jan 17 18:15:37 UTC 2015
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 fa11e56e7ffda1e60d98bbe5514baff8be879e4c
Author: Simon McVittie <smcv at debian.org>
Date: Sat Jan 17 18:06:53 2015 +0000
Add --save-downloads option
---
lib/game_data_packager/__init__.py | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/lib/game_data_packager/__init__.py b/lib/game_data_packager/__init__.py
index 63a25e2..4a40bc6 100644
--- a/lib/game_data_packager/__init__.py
+++ b/lib/game_data_packager/__init__.py
@@ -492,6 +492,9 @@ class GameData(object):
# Set of filenames we couldn't unpack
self.unpack_failed = set()
+ # None or an existing directory in which to save downloaded files.
+ self.save_downloads = None
+
self._populate_files(self.yaml.get('files'))
assert 'packages' in self.yaml
@@ -1168,10 +1171,15 @@ class GameData(object):
if rf is None:
continue
- tmp = os.path.join(self.get_workdir(),
- 'tmp', wanted.name)
- tmpdir = os.path.dirname(tmp)
- mkdir_p(tmpdir)
+ if self.save_downloads is not None:
+ tmp = os.path.join(self.save_downloads,
+ wanted.name)
+ else:
+ tmp = os.path.join(self.get_workdir(),
+ 'tmp', wanted.name)
+ tmpdir = os.path.dirname(tmp)
+ mkdir_p(tmpdir)
+
wf = open(tmp, 'wb')
logger.info('downloading %s', url)
hf = HashedFile.from_file(url, rf, wf,
@@ -1184,6 +1192,7 @@ class GameData(object):
FillResult.COMPLETE)
return FillResult.COMPLETE
else:
+ # file corrupted or something
os.remove(tmp)
except Exception as e:
logger.warning('Failed to download "%s": %s', url,
@@ -1502,6 +1511,9 @@ class GameData(object):
def look_for_files(self, paths=(), search=True):
paths = list(paths)
+ if self.save_downloads is not None:
+ paths.append(self.save_downloads)
+
if search:
for path in self.try_repack_from:
if os.path.isdir(path):
@@ -1534,6 +1546,8 @@ class GameData(object):
# anyway
args.compress = preserve_debs
+ self.save_downloads = args.save_downloads
+
self.look_for_files(paths=args.paths, search=args.search)
if args.shortname in self.packages:
@@ -1855,6 +1869,8 @@ def run_command_line():
'(default)')
group.add_argument('--no-download', action='store_false',
dest='download', help='do not download anything')
+ base_parser.add_argument('--save-downloads', metavar='DIR',
+ help='save downloaded files to DIR, and look for files there')
parser = argparse.ArgumentParser(prog='game-data-packager',
description='Package game files.', parents=(base_parser,))
@@ -1872,6 +1888,7 @@ def run_command_line():
destination=None,
download=True,
install=False,
+ save_downloads=None,
search=True,
)
parser.parse_args(namespace=parsed)
@@ -1885,5 +1902,11 @@ def run_command_line():
parser.print_help()
sys.exit(0)
+ if (parsed.save_downloads is not None and
+ not os.path.isdir(parsed.save_downloads)):
+ logger.error('argument "%s" to --save-downloads does not exist',
+ parsed.save_downloads)
+ sys.exit(2)
+
with games[parsed.shortname] as game:
game.run_command_line(parsed)
--
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