summaryrefslogtreecommitdiff
path: root/distutils2/command
diff options
context:
space:
mode:
authorFELD Boris <lothiraldan@gmail.com>2011-02-09 09:49:22 +0100
committerFELD Boris <lothiraldan@gmail.com>2011-02-09 09:49:22 +0100
commitefe0772e2d6b7ec3e68bfa65ca798f259f56d314 (patch)
treea4e6e5249ec334ca126275d4e6f3a103c5a11f8d /distutils2/command
parent74314e447d926f90225e4df7cdc8ff25b859b767 (diff)
parentefc095cc5bf7c04a605e8a5bc60a940b4554d264 (diff)
downloaddisutils2-efe0772e2d6b7ec3e68bfa65ca798f259f56d314.tar.gz
Merge with upstream default branch
Diffstat (limited to 'distutils2/command')
-rw-r--r--distutils2/command/install_data.py75
-rw-r--r--distutils2/command/install_dist.py4
-rw-r--r--distutils2/command/install_distinfo.py40
3 files changed, 68 insertions, 51 deletions
diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py
index e77b11c..d4f8143 100644
--- a/distutils2/command/install_data.py
+++ b/distutils2/command/install_data.py
@@ -9,6 +9,8 @@ platform-independent data files."""
import os
from distutils2.command.cmd import Command
from distutils2.util import change_root, convert_path
+from distutils2._backport.sysconfig import get_paths, format_value
+from distutils2._backport.shutil import Error
class install_data(Command):
@@ -28,6 +30,7 @@ class install_data(Command):
def initialize_options(self):
self.install_dir = None
self.outfiles = []
+ self.data_files_out = []
self.root = None
self.force = 0
self.data_files = self.distribution.data_files
@@ -40,54 +43,38 @@ class install_data(Command):
def run(self):
self.mkpath(self.install_dir)
- for f in self.data_files:
- if isinstance(f, str):
- # it's a simple file, so copy it
- f = convert_path(f)
- if self.warn_dir:
- self.warn("setup script did not provide a directory for "
- "'%s' -- installing right in '%s'" %
- (f, self.install_dir))
- (out, _) = self.copy_file(f, self.install_dir)
- self.outfiles.append(out)
- else:
- # it's a tuple with path to install to and a list of files
- dir = convert_path(f[0])
- if not os.path.isabs(dir):
- dir = os.path.join(self.install_dir, dir)
- elif self.root:
- dir = change_root(self.root, dir)
- self.mkpath(dir)
-
- if f[1] == []:
- # If there are no files listed, the user must be
- # trying to create an empty directory, so add the
- # directory to the list of output files.
- self.outfiles.append(dir)
- else:
- # Copy files, adding them to the list of output files.
- for data in f[1]:
- data = convert_path(data)
- (out, _) = self.copy_file(data, dir)
- self.outfiles.append(out)
+ for file in self.data_files.items():
+ destination = convert_path(self.expand_categories(file[1]))
+ dir_dest = os.path.abspath(os.path.dirname(destination))
+
+ self.mkpath(dir_dest)
+ try:
+ (out, _) = self.copy_file(file[0], dir_dest)
+ except Error, e:
+ self.warn(e.message)
+ out = destination
+
+ self.outfiles.append(out)
+ self.data_files_out.append((file[0], destination))
+
+ def expand_categories(self, path_with_categories):
+ local_vars = get_paths()
+ local_vars['distribution.name'] = self.distribution.metadata['Name']
+ expanded_path = format_value(path_with_categories, local_vars)
+ expanded_path = format_value(expanded_path, local_vars)
+ if '{' in expanded_path and '}' in expanded_path:
+ self.warn("Unable to expand %s, some categories may missing." %
+ path_with_categories)
+ return expanded_path
def get_source_files(self):
- sources = []
- for item in self.data_files:
- if isinstance(item, str): # plain file
- item = convert_path(item)
- if os.path.isfile(item):
- sources.append(item)
- else: # a (dirname, filenames) tuple
- dirname, filenames = item
- for f in filenames:
- f = convert_path(f)
- if os.path.isfile(f):
- sources.append(f)
- return sources
+ return self.data_files.keys()
def get_inputs(self):
- return self.data_files or []
+ return self.data_files.keys()
def get_outputs(self):
return self.outfiles
+
+ def get_resources_out(self):
+ return self.data_files_out \ No newline at end of file
diff --git a/distutils2/command/install_dist.py b/distutils2/command/install_dist.py
index 146c905..fb3fd2a 100644
--- a/distutils2/command/install_dist.py
+++ b/distutils2/command/install_dist.py
@@ -87,6 +87,8 @@ class install_dist(Command):
('record=', None,
"filename in which to record a list of installed files "
"(not PEP 376-compliant)"),
+ ('resources=', None,
+ "data files mapping"),
# .dist-info related arguments, read by install_dist_info
('no-distinfo', None,
@@ -184,12 +186,14 @@ class install_dist(Command):
#self.install_info = None
self.record = None
+ self.resources = None
# .dist-info related options
self.no_distinfo = None
self.installer = None
self.requested = None
self.no_record = None
+ self.no_resources = None
# -- Option finalizing methods -------------------------------------
# (This is rather more involved than for most commands,
diff --git a/distutils2/command/install_distinfo.py b/distutils2/command/install_distinfo.py
index 6e76546..b8cfcc0 100644
--- a/distutils2/command/install_distinfo.py
+++ b/distutils2/command/install_distinfo.py
@@ -12,12 +12,12 @@ automatically by the ``install_dist`` command.
# This file was created from the code for the former command install_egg_info
-import os
import csv
-import re
-from distutils2.command.cmd import Command
from distutils2 import logger
from distutils2._backport.shutil import rmtree
+from distutils2.command.cmd import Command
+import os
+import re
try:
import hashlib
except ImportError:
@@ -39,9 +39,11 @@ class install_distinfo(Command):
"do not generate a REQUESTED file"),
('no-record', None,
"do not generate a RECORD file"),
+ ('no-resources', None,
+ "do not generate a RESSOURCES list installed file")
]
- boolean_options = ['requested', 'no-record']
+ boolean_options = ['requested', 'no-record', 'no-resources']
negative_opt = {'no-requested': 'requested'}
@@ -50,6 +52,7 @@ class install_distinfo(Command):
self.installer = None
self.requested = None
self.no_record = None
+ self.no_resources = None
def finalize_options(self):
self.set_undefined_options('install_dist',
@@ -66,13 +69,16 @@ class install_distinfo(Command):
self.requested = True
if self.no_record is None:
self.no_record = False
+ if self.no_resources is None:
+ self.no_resources = False
+
metadata = self.distribution.metadata
basename = "%s-%s.dist-info" % (
- to_filename(safe_name(metadata['Name'])),
- to_filename(safe_version(metadata['Version'])),
- )
+ to_filename(safe_name(metadata['Name'])),
+ to_filename(safe_version(metadata['Version'])),
+ )
self.distinfo_dir = os.path.join(self.distinfo_dir, basename)
self.outputs = []
@@ -113,6 +119,25 @@ class install_distinfo(Command):
f.close()
self.outputs.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)
+ f = open(resources_path, 'wb')
+ try:
+ writer = csv.writer(f, delimiter=',',
+ lineterminator=os.linesep,
+ quotechar='"')
+ for tuple in install_data.get_resources_out():
+ writer.writerow(tuple)
+
+ self.outputs.append(resources_path)
+ finally:
+ f.close()
+
if not self.no_record:
record_path = os.path.join(self.distinfo_dir, 'RECORD')
logger.info('creating %s', record_path)
@@ -142,6 +167,7 @@ class install_distinfo(Command):
finally:
f.close()
+
def get_outputs(self):
return self.outputs