[Python-checkins] cpython: Fix usage of dry-run in packaging bdist_wininst and install_distinfo.
eric.araujo
python-checkins at python.org
Mon Sep 12 17:42:19 CEST 2011
http://hg.python.org/cpython/rev/545eb37dc3f7
changeset: 72351:545eb37dc3f7
user: Éric Araujo <merwok at netwok.org>
date: Sat Sep 10 18:10:23 2011 +0200
summary:
Fix usage of dry-run in packaging bdist_wininst and install_distinfo.
In dry-run mode, packaging commands should log the same info as in real
operation and should collect the same files in self.outputs, so that
users can run a command in verbose and dry-run mode to see exactly what
operations will be done in the real run.
files:
Lib/packaging/command/bdist_wininst.py | 5 +-
Lib/packaging/command/install_distinfo.py | 80 +++++-----
2 files changed, 42 insertions(+), 43 deletions(-)
diff --git a/Lib/packaging/command/bdist_wininst.py b/Lib/packaging/command/bdist_wininst.py
--- a/Lib/packaging/command/bdist_wininst.py
+++ b/Lib/packaging/command/bdist_wininst.py
@@ -186,9 +186,8 @@
os.remove(arcname)
if not self.keep_temp:
- if self.dry_run:
- logger.info('removing %s', self.bdist_dir)
- else:
+ logger.info('removing %s', self.bdist_dir)
+ if not self.dry_run:
rmtree(self.bdist_dir)
def get_inidata(self):
diff --git a/Lib/packaging/command/install_distinfo.py b/Lib/packaging/command/install_distinfo.py
--- a/Lib/packaging/command/install_distinfo.py
+++ b/Lib/packaging/command/install_distinfo.py
@@ -28,7 +28,7 @@
('no-record', None,
"do not generate a RECORD file"),
('no-resources', None,
- "do not generate a RESSOURCES list installed file")
+ "do not generate a RESSOURCES list installed file"),
]
boolean_options = ['requested', 'no-record', 'no-resources']
@@ -70,56 +70,56 @@
self.distinfo_dir = os.path.join(self.distinfo_dir, basename)
def run(self):
- # FIXME dry-run should be used at a finer level, so that people get
- # useful logging output and can have an idea of what the command would
- # have done
+ target = self.distinfo_dir
+
+ if os.path.isdir(target) and not os.path.islink(target):
+ if not self.dry_run:
+ rmtree(target)
+ elif os.path.exists(target):
+ self.execute(os.unlink, (self.distinfo_dir,),
+ "removing " + target)
+
+ self.execute(os.makedirs, (target,), "creating " + target)
+
+ metadata_path = os.path.join(self.distinfo_dir, 'METADATA')
+ self.execute(self.distribution.metadata.write, (metadata_path,),
+ "creating " + metadata_path)
+ self.outfiles.append(metadata_path)
+
+ installer_path = os.path.join(self.distinfo_dir, 'INSTALLER')
+ logger.info('creating %s', installer_path)
if not self.dry_run:
- target = self.distinfo_dir
-
- if os.path.isdir(target) and not os.path.islink(target):
- rmtree(target)
- elif os.path.exists(target):
- self.execute(os.unlink, (self.distinfo_dir,),
- "removing " + target)
-
- self.execute(os.makedirs, (target,), "creating " + target)
-
- metadata_path = os.path.join(self.distinfo_dir, 'METADATA')
- logger.info('creating %s', metadata_path)
- self.distribution.metadata.write(metadata_path)
- self.outfiles.append(metadata_path)
-
- installer_path = os.path.join(self.distinfo_dir, 'INSTALLER')
- logger.info('creating %s', installer_path)
with open(installer_path, 'w') as f:
f.write(self.installer)
- self.outfiles.append(installer_path)
+ self.outfiles.append(installer_path)
- if self.requested:
- requested_path = os.path.join(self.distinfo_dir, 'REQUESTED')
- logger.info('creating %s', requested_path)
+ if self.requested:
+ requested_path = os.path.join(self.distinfo_dir, 'REQUESTED')
+ logger.info('creating %s', requested_path)
+ if not self.dry_run:
open(requested_path, 'wb').close()
- self.outfiles.append(requested_path)
+ self.outfiles.append(requested_path)
-
- if not self.no_resources:
- install_data = self.get_finalized_command('install_data')
- if install_data.get_resources_out() != []:
- resources_path = os.path.join(self.distinfo_dir,
- 'RESOURCES')
- logger.info('creating %s', resources_path)
+ if not self.no_resources:
+ install_data = self.get_finalized_command('install_data')
+ if install_data.get_resources_out() != []:
+ resources_path = os.path.join(self.distinfo_dir,
+ 'RESOURCES')
+ logger.info('creating %s', resources_path)
+ if not self.dry_run:
with open(resources_path, 'wb') as f:
writer = csv.writer(f, delimiter=',',
lineterminator='\n',
quotechar='"')
- for tuple in install_data.get_resources_out():
- writer.writerow(tuple)
+ for row in install_data.get_resources_out():
+ writer.writerow(row)
- self.outfiles.append(resources_path)
+ self.outfiles.append(resources_path)
- if not self.no_record:
- record_path = os.path.join(self.distinfo_dir, 'RECORD')
- logger.info('creating %s', record_path)
+ if not self.no_record:
+ record_path = os.path.join(self.distinfo_dir, 'RECORD')
+ logger.info('creating %s', record_path)
+ if not self.dry_run:
with open(record_path, 'w', encoding='utf-8') as f:
writer = csv.writer(f, delimiter=',',
lineterminator='\n',
@@ -141,7 +141,7 @@
# add the RECORD file itself
writer.writerow((record_path, '', ''))
- self.outfiles.append(record_path)
+ self.outfiles.append(record_path)
def get_outputs(self):
return self.outfiles
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list