Ticket #197: beporter_new.patch
| File beporter_new.patch, 6.6 KB (added by brecht, 6 years ago) |
|---|
-
beporter
1 1 #!/boot/home/config/bin/python 2 2 # 3 # copyright 2007-2008 Brecht Machiels 3 # copyright 2007-2009 Brecht Machiels 4 # copyright 2009 HaikuBot 4 5 5 6 info = {} 6 7 info['version'] = "0.22 alpha" … … 15 16 import time 16 17 import locale 17 18 import tarfile, zipfile 19 import types 18 20 from optparse import OptionParser 19 from types import *20 21 21 # -- HaikuPorts options ------------------------------------------------------ ---22 # -- HaikuPorts options ------------------------------------------------------ 22 23 23 24 # location of haikuports.conf 24 25 haikuPortsConf = "/etc/haikuports.conf" 25 26 26 27 # create new type 'ShellType' for identifying lists of shell commands 27 class shell(list): pass 28 class shell(list): 29 pass 30 28 31 ShellType = shell 29 32 30 33 # create new type 'StatusType' for identifying the port's status on a platform 31 34 # the possible states are defined in the 'Config' class (reStatusType) 32 class status(str): pass 35 class status(str): 36 pass 37 33 38 StatusType = status 34 39 35 40 # allowed types of the /etc/haikuports.conf values 36 41 confTypes = {} 37 confTypes['PACKAGES_PATH'] = [ StringType]42 confTypes['PACKAGES_PATH'] = [types.StringType] 38 43 39 44 # allowed types of the BepFile values 40 45 bepTypes = {} 41 bepTypes['DESCRIPTION'] = [ StringType,ListType]42 bepTypes['HOMEPAGE'] = [ StringType]43 bepTypes['SRC_URI'] = [ StringType,ListType]44 bepTypes['REVISION'] = [ IntType]46 bepTypes['DESCRIPTION'] = [types.StringType, types.ListType] 47 bepTypes['HOMEPAGE'] = [types.StringType] 48 bepTypes['SRC_URI'] = [types.StringType, types.ListType] 49 bepTypes['REVISION'] = [types.IntType] 45 50 bepTypes['STATUS_R5'] = [StatusType] 46 51 bepTypes['STATUS_BONE'] = [StatusType] 47 52 bepTypes['STATUS_HAIKU']= [StatusType] 48 bepTypes['DEPEND'] = [ StringType, ListType,NoneType]53 bepTypes['DEPEND'] = [types.StringType, types.ListType, types.NoneType] 49 54 bepTypes['BUILD'] = [ShellType] 50 55 bepTypes['INSTALL'] = [ShellType] 51 56 … … 99 104 # read global settings 100 105 mainConfig = Config(haikuPortsConf) 101 106 self.confKeys = mainConfig.getKeys() 107 102 108 for key in self.confKeys: 103 109 try: 104 110 if type(self.confKeys[key]) not in confTypes[key]: … … 106 112 sys.exit() 107 113 except KeyError, e: 108 114 print "Unknown key label '" + key + "' in " + haikuPortsConf + ". Ignoring." 115 109 116 self.packagesPath = self.confKeys['PACKAGES_PATH'] 110 if self.packagesPath[-1] == '/': # strip trailing '/' 117 118 if self.packagesPath[-1] == '/': 119 # strip trailing '/' 111 120 self.packagesPath = self.packagesPath[:-1] 112 121 113 122 # if requested, list all ports in the HaikuPorts tree 114 123 if options.list: 115 124 self.listPorts() 116 125 sys.exit() 117 126 118 127 # if requested, search for a port 119 128 if options.search: 120 129 if len(args) == 0: 121 130 print "You need to specifiy a search string" 122 131 print "Invoke '" + sys.argv[0] + " -h' for usage information." 123 132 sys.exit() 133 124 134 self.searchPorts(args[0]) 125 135 sys.exit() 126 136 … … 158 168 self.downloadDir= self.portDir + '/' + paths['download'] 159 169 self.workDir = self.portDir + '/' + paths['work'] 160 170 self.patchesDir = self.portDir + '/' + paths['patches'] 161 171 162 172 # if the port version was not specified, list available versions 163 173 if self.portVersion == None: 164 174 versions = [] … … 174 184 print " " + version[0] 175 185 print "Run beporter again, specifiying a port version" 176 186 sys.exit() 187 188 # show port description, if requested 189 if options.desc: 190 self.desc() 191 sys.exit() 177 192 178 193 # read data from the bep file 179 194 self.parseBepFile() … … 193 208 pass 194 209 else: 195 210 sys.exit() 196 211 197 212 # clean the work directory, if requested 198 213 if options.clean: 199 214 self.clean() … … 212 227 if options.install: 213 228 self.install() # install 214 229 230 def desc(self): 231 """Show port description""" 232 os.chdir(self.portDir) 233 234 bepFilename = self.portName + '-' + self.portVersion + ".bep" 235 236 reOptionValue = re.compile('^(?P<key>[A-Z0-9_]*)\s*=\s*"(?P<value>.*)(?<!\\\\)"\s*$') 237 reComment = re.compile('^\s*#.*$') 238 reEmptyLine = re.compile('^\s*$') 239 240 if not os.path.exists(bepFilename): 241 print self.portName + " version " + self.portVersion + " not found" 242 sys.exit() 243 244 245 fp = open(bepFilename) 246 lineCount = 0 247 248 line = fp.readline() 249 lineCount += 1 250 251 print '*'*80 252 253 while line != "": 254 # empty line or comment 255 if reEmptyLine.match(line) or reComment.match(line): 256 pass 257 # value option (single line) (check BEFORE list option) 258 elif reOptionValue.match(line): 259 m = reOptionValue.match(line) 260 key = m.group("key") 261 value = m.group("value") 262 263 if 'DESCRIPTION' in key: 264 print key.capitalize()+":",value 265 elif 'HOMEPAGE' in key: 266 print key.capitalize()+":",value 267 268 line = fp.readline() 269 lineCount += 1 270 271 print '*'*80 272 273 fp.close() 274 215 275 def parseBepFile(self): 216 276 """Parse the BepFile of the specified port""" 217 277 os.chdir(self.portDir) … … 245 305 # convert each None/string value into a list (with respectively 0 or 1 element) 246 306 # (simplifies implementation ahead) 247 307 for key in bepTypes: 248 if ListType in bepTypes[key]:308 if types.ListType in bepTypes[key]: 249 309 if self.bepKeys[key] == None: 250 310 self.bepKeys[key] = [] 251 elif type(self.bepKeys[key]) == StringType:311 elif type(self.bepKeys[key]) == types.StringType: 252 312 self.bepKeys[key] = [self.bepKeys[key]] 253 313 else: 254 314 pass … … 623 683 624 684 parser = OptionParser(usage="usage: %prog [options] portname[-portversion]", 625 685 version="%prog " + info['version']) 686 626 687 parser.add_option("-l", "--list", 627 688 action="store_true", dest="list", default=False, 628 689 help="list available ports") 690 691 parser.add_option("-d", "--desc", 692 action="store_true", dest="desc", default=False, 693 help="show port description") 694 629 695 parser.add_option("-s", "--search", 630 696 action="store_true", dest="search", default=False, 631 697 help="search for a port (regex)") 698 632 699 parser.add_option("-p", "--nopatch", 633 700 action="store_false", dest="patch", default=True, 634 701 help="don't patch the sources, just download and unpack") 702 635 703 parser.add_option("-b", "--nobuild", 636 704 action="store_false", dest="build", default=True, 637 705 help="don't build the port, just download, unpack and patch") 706 638 707 parser.add_option("-i", "--install", 639 708 action="store_true", dest="install", default=False, 640 709 help="also install the port (the default is to only build)") 710 641 711 parser.add_option("-c", "--clean", 642 712 action="store_true", dest="clean", default=False, 643 713 help="clean the working directory of the specified port") 714 644 715 (options, args) = parser.parse_args() 645 716 646 717 beporter = BePorter(options, args)
