]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/distutils/command/install_egg_info.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / distutils / command / install_egg_info.py
CommitLineData
4710c53d 1"""distutils.command.install_egg_info\r
2\r
3Implements the Distutils 'install_egg_info' command, for installing\r
4a package's PKG-INFO metadata."""\r
5\r
6\r
7from distutils.cmd import Command\r
8from distutils import log, dir_util\r
9import os, sys, re\r
10\r
11class install_egg_info(Command):\r
12 """Install an .egg-info file for the package"""\r
13\r
14 description = "Install package's PKG-INFO metadata as an .egg-info file"\r
15 user_options = [\r
16 ('install-dir=', 'd', "directory to install to"),\r
17 ]\r
18\r
19 def initialize_options(self):\r
20 self.install_dir = None\r
21\r
22 def finalize_options(self):\r
23 self.set_undefined_options('install_lib',('install_dir','install_dir'))\r
24 basename = "%s-%s-py%s.egg-info" % (\r
25 to_filename(safe_name(self.distribution.get_name())),\r
26 to_filename(safe_version(self.distribution.get_version())),\r
27 sys.version[:3]\r
28 )\r
29 self.target = os.path.join(self.install_dir, basename)\r
30 self.outputs = [self.target]\r
31\r
32 def run(self):\r
33 target = self.target\r
34 if os.path.isdir(target) and not os.path.islink(target):\r
35 dir_util.remove_tree(target, dry_run=self.dry_run)\r
36 elif os.path.exists(target):\r
37 self.execute(os.unlink,(self.target,),"Removing "+target)\r
38 elif not os.path.isdir(self.install_dir):\r
39 self.execute(os.makedirs, (self.install_dir,),\r
40 "Creating "+self.install_dir)\r
41 log.info("Writing %s", target)\r
42 if not self.dry_run:\r
43 f = open(target, 'w')\r
44 self.distribution.metadata.write_pkg_file(f)\r
45 f.close()\r
46\r
47 def get_outputs(self):\r
48 return self.outputs\r
49\r
50\r
51# The following routines are taken from setuptools' pkg_resources module and\r
52# can be replaced by importing them from pkg_resources once it is included\r
53# in the stdlib.\r
54\r
55def safe_name(name):\r
56 """Convert an arbitrary string to a standard distribution name\r
57\r
58 Any runs of non-alphanumeric/. characters are replaced with a single '-'.\r
59 """\r
60 return re.sub('[^A-Za-z0-9.]+', '-', name)\r
61\r
62\r
63def safe_version(version):\r
64 """Convert an arbitrary string to a standard version string\r
65\r
66 Spaces become dots, and all other non-alphanumeric characters become\r
67 dashes, with runs of multiple dashes condensed to a single dash.\r
68 """\r
69 version = version.replace(' ','.')\r
70 return re.sub('[^A-Za-z0-9.]+', '-', version)\r
71\r
72\r
73def to_filename(name):\r
74 """Convert a project or version name to its filename-escaped form\r
75\r
76 Any '-' characters are currently replaced with '_'.\r
77 """\r
78 return name.replace('-','_')\r