Changeset 75
- Timestamp:
- 06/24/06 09:40:42 (7 years ago)
- Files:
-
- branches/mk/cheesecake/cheesecake_index.py (modified) (11 diffs)
- branches/mk/cheesecake/util.py (modified) (2 diffs)
- branches/mk/tests/unit/test_index_class.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/mk/cheesecake/cheesecake_index.py
r74 r75 28 28 from util import run_cmd, command_successful 29 29 from util import unzip_package, untar_package 30 from util import mkdirs 30 31 from util import StdoutRedirector 31 32 import logger … … 322 323 self.subindices.append(index) 323 324 self._indices_dict[index.name] = index 325 326 def remove_subindex(self, index_name): 327 """Remove subindex (refered by name). 328 329 :Parameters: 330 `index` : Index name 331 Index name to be removed. 332 """ 333 index = self._indices_dict[index_name] 334 self.subindices.remove(index) 335 del self._indices_dict[index_name] 324 336 325 337 def _print_info_one(self): … … 773 785 774 786 class CheesecakeError(Exception): 775 """ 776 Custom exception class for Cheesecake-specific errors 787 """Custom exception class for Cheesecake-specific errors. 777 788 """ 778 789 pass … … 829 840 "tgz": untar_package, 830 841 "zip": unzip_package, 842 "egg": unzip_package, 831 843 } 832 844 … … 841 853 self.index["INSTALLABILITY"].add_subindex(IndexUrlDownload()) 842 854 855 # Get package name. 843 856 self.determine_pkg_name() 857 858 # Configure logging as soon as possible. 844 859 self.configure_logging(logfile) 845 #self.set_defaults() 846 # self.get_config()860 861 # Get package, 847 862 self.retrieve_pkg() 863 864 # Get package name and type. 865 self.package_name, self.package_type = self.get_package_name_and_type(self.package) 866 self.log.debug("Package name: " + self.package_name) 867 self.log.debug("Package type: " + self.package_type) 868 869 # Unpack package and list its files. 848 870 self.unpack_pkg() 849 871 self.walk_pkg() 872 873 # Install package. 850 874 self.install_pkg() 875 876 # When checking an egg exclude irrelevant indices. 877 if self.package_type == 'egg': 878 self.index["INSTALLABILITY"].remove_subindex('setup.py') 879 self.index["INSTALLABILITY"].remove_subindex('unpack_dir') 880 self.index["INSTALLABILITY"].remove_subindex('generated_files') 851 881 852 882 def raise_exception(self, msg): … … 973 1003 except ImportError, e: 974 1004 msg = "Error: setuptools is not installed and is required for downloading a package by name\n" 975 msg += "You can do nwload and process a package by its full URL via the -u or --url option\n"1005 msg += "You can download and process a package by its full URL via the -u or --url option\n" 976 1006 msg += "Example: python cheesecake.py --url=http://www.mems-exchange.org/software/durus/Durus-3.1.tar.gz" 977 1007 self.raise_exception(msg) 1008 1009 def drop_setuptools_info(stdout, error=None): 1010 """Drop all setuptools output as INFO. 1011 """ 1012 self.log.info("*** Begin setuptools output") 1013 map(self.log.info, stdout.splitlines()) 1014 if error: 1015 self.log.info(str(error)) 1016 self.log.info("*** End setuptools output") 978 1017 979 1018 try: … … 986 1025 self.sandbox, 987 1026 force_scan=True, 988 source= True)1027 source=False) 989 1028 captured_stdout = sys.stdout.read_buffer() 990 1029 sys.stdout = old_stdout … … 997 1036 log.set_threshold(old_threshold) 998 1037 999 # Drop all setuptools output as INFO. 1000 self.log.info("*** Begin setuptools output") 1001 map(self.log.info, captured_stdout.splitlines()) 1002 self.log.info(str(e)) 1003 self.log.info("*** End setuptools output") 1004 1005 msg = "Error: setuptools returned an error: %s\n" % e 1006 self.raise_exception(msg) 1038 drop_setuptools_info(captured_stdout, error) 1039 self.raise_exception("Error: setuptools returned an error: %s\n" % e) 1007 1040 1008 1041 if output is None: 1042 drop_setuptools_info(captured_stdout) 1009 1043 self.raise_exception("Error: Could not find distribution for " + self.name) 1010 1044 … … 1063 1097 shutil.copyfile(self.package_path, self.sandbox_pkg_file) 1064 1098 1099 def get_package_name_and_type(self, package): 1100 """Return package name and type. 1101 1102 Raise an exception when package type cannot be recognized. 1103 """ 1104 for type in self.package_types.keys(): 1105 s = re.search(r"(.+)\.%s" % type, package) 1106 if s: 1107 # Package name is name of package without file extension (ex. twill-7.3). 1108 return s.group(1), type 1109 1110 msg = "Could not determine package type for package '%s'" % package 1111 msg += "\nCurrently recognized types: " + ", ".join(self.package_types.keys()) 1112 self.raise_exception(msg) 1113 1065 1114 def unpack_pkg(self): 1066 1115 """Unpack the package in the sandbox directory. … … 1072 1121 original_package_name : str 1073 1122 """ 1074 self.package_type = ""1075 1076 for type in self.package_types.keys():1077 s = re.search(r"(.+)\.%s" % type, self.package)1078 if s:1079 # package_name is name of package without file extension (ex. twill-7.3)1080 self.package_name = s.group(1)1081 self.package_type = type1082 break1083 if not self.package_type:1084 msg = "Could not determine package type for package '%s'" % self.package1085 msg += "\nCurrently recognized types: " + " ".join(self.package_types)1086 self.raise_exception(msg)1087 self.log.debug("Package name: " + self.package_name)1088 self.log.debug("Package type: " + self.package_type)1089 1090 1123 self.sandbox_pkg_dir = os.path.join(self.sandbox, self.package_name) 1091 1124 if os.path.isdir(self.sandbox_pkg_dir): … … 1160 1193 self.sandbox_install_dir = os.path.join(self.sandbox, "tmp_install_%s" % self.package_name) 1161 1194 1162 cwd = os.getcwd() 1163 os.chdir(os.path.join(self.sandbox, self.package_name)) 1164 1165 rc, output = run_cmd("python setup.py install --root=" + self.sandbox_install_dir) 1166 1167 # Install succeeded 1168 if not rc: 1195 if self.package_type == 'egg': 1196 # Create dummy Python directories. 1197 mkdirs('%s/lib/python2.3/site-packages/' % self.sandbox_install_dir) 1198 mkdirs('%s/lib/python2.4/site-packages/' % self.sandbox_install_dir) 1199 1200 environment = {'PYTHONPATH': 1201 '%(sandbox)s/lib/python2.3/site-packages/:'\ 1202 '%(sandbox)s/lib/python2.4/site-packages/' % \ 1203 {'sandbox': self.sandbox_install_dir}} 1204 rc, output = run_cmd("easy_install --no-deps --prefix %s %s" % \ 1205 (self.sandbox_install_dir, self.sandbox_pkg_file), 1206 environment) 1207 else: 1208 cwd = os.getcwd() 1209 os.chdir(os.path.join(self.sandbox, self.package_name)) 1210 rc, output = run_cmd("python setup.py install --root=" + self.sandbox_install_dir) 1211 os.chdir(cwd) 1212 1213 if rc: 1214 self.log('*** Installation failed. Captured output:') 1215 for output_line in output.splitlines(): 1216 self.log(output_line) 1217 self.log('*** End of captured output.') 1218 else: 1169 1219 self.installed = True 1170 1171 os.chdir(cwd)1172 1220 1173 1221 def compute_cheesecake_index(self): branches/mk/cheesecake/util.py
r58 r75 9 9 PAD_VALUE = 4 10 10 11 def run_cmd(cmd): 12 """ 13 Run command and return its return code and its output 11 def run_cmd(cmd, env=None): 12 """Run command and return its return code and its output. 14 13 """ 15 14 arglist = cmd.split() 16 15 try: 17 p = Popen(arglist, stdout=PIPE, stderr=STDOUT )16 p = Popen(arglist, stdout=PIPE, stderr=STDOUT, env=env) 18 17 except ProcessError, e: 19 18 return 1, e … … 149 148 tarinfo = t.members[0] 150 149 return tarinfo.name.split(os.sep)[0] 150 151 def mkdirs(dir): 152 """Make directory with parent directories as needed. 153 154 Don't throw an exception if directory exists. 155 """ 156 parts = dir.split(os.path.sep) 157 for length in xrange(1, len(parts)+1): 158 path = os.path.sep.join([''] + parts[:length]) 159 if not os.path.exists(path): 160 os.mkdir(path) branches/mk/tests/unit/test_index_class.py
r55 r75 7 7 >>> big_index = Index() 8 8 >>> index = Index() 9 >>> index.name = 'small_index' 9 10 10 11 Add one index to another. … … 18 19 ... 19 20 ValueError: subindex have to be instance of Index 21 22 Now remove subindex. 23 >>> big_index.remove_subindex('small_index') 24 >>> index in big_index.subindices 25 False 20 26 """
