HaikuPorts
  • Login
  • Preferences
  • Help/Guide
  • Wiki
  • Timeline
  • Roadmap
  • View Tickets
  • Search
  • Port Log
  • Blog

Context Navigation

  • Back to Ticket #197

Ticket #197: beporter_new.patch

File beporter_new.patch, 6.6 KB (added by brecht, 6 years ago)
  • beporter

     
    11#!/boot/home/config/bin/python 
    22# 
    3 # copyright 2007-2008 Brecht Machiels 
     3# copyright 2007-2009 Brecht Machiels 
     4# copyright 2009 HaikuBot 
    45 
    56info = {} 
    67info['version'] = "0.22 alpha" 
    … …  
    1516import time 
    1617import locale 
    1718import tarfile, zipfile 
     19import types 
    1820from optparse import OptionParser 
    19 from types import * 
    2021 
    21 # -- HaikuPorts options --------------------------------------------------------- 
     22# -- HaikuPorts options ------------------------------------------------------ 
    2223 
    2324# location of haikuports.conf 
    2425haikuPortsConf = "/etc/haikuports.conf" 
    2526 
    2627# create new type 'ShellType' for identifying lists of shell commands 
    27 class shell(list): pass 
     28class shell(list): 
     29        pass 
     30         
    2831ShellType = shell 
    2932 
    3033# create new type 'StatusType' for identifying the port's status on a platform 
    3134#  the possible states are defined in the 'Config' class (reStatusType) 
    32 class status(str): pass 
     35class status(str): 
     36        pass 
     37         
    3338StatusType = status 
    3439 
    3540# allowed types of the /etc/haikuports.conf values 
    3641confTypes = {} 
    37 confTypes['PACKAGES_PATH'] = [StringType] 
     42confTypes['PACKAGES_PATH'] = [types.StringType] 
    3843 
    3944# allowed types of the BepFile values 
    4045bepTypes = {} 
    41 bepTypes['DESCRIPTION'] = [StringType, ListType] 
    42 bepTypes['HOMEPAGE']    = [StringType] 
    43 bepTypes['SRC_URI']             = [StringType, ListType] 
    44 bepTypes['REVISION']    = [IntType] 
     46bepTypes['DESCRIPTION'] = [types.StringType, types.ListType] 
     47bepTypes['HOMEPAGE']    = [types.StringType] 
     48bepTypes['SRC_URI']             = [types.StringType, types.ListType] 
     49bepTypes['REVISION']    = [types.IntType] 
    4550bepTypes['STATUS_R5']   = [StatusType] 
    4651bepTypes['STATUS_BONE'] = [StatusType] 
    4752bepTypes['STATUS_HAIKU']= [StatusType] 
    48 bepTypes['DEPEND']              = [StringType, ListType, NoneType] 
     53bepTypes['DEPEND']              = [types.StringType, types.ListType, types.NoneType] 
    4954bepTypes['BUILD']               = [ShellType] 
    5055bepTypes['INSTALL']             = [ShellType] 
    5156 
    … …  
    99104                # read global settings 
    100105                mainConfig = Config(haikuPortsConf) 
    101106                self.confKeys = mainConfig.getKeys() 
     107                 
    102108                for key in self.confKeys: 
    103109                        try: 
    104110                                if type(self.confKeys[key]) not in confTypes[key]: 
    … …  
    106112                                        sys.exit() 
    107113                        except KeyError, e: 
    108114                                print "Unknown key label '" + key + "' in " + haikuPortsConf + ". Ignoring." 
     115                                 
    109116                self.packagesPath = self.confKeys['PACKAGES_PATH'] 
    110                 if self.packagesPath[-1] == '/':        # strip trailing '/' 
     117                 
     118                if self.packagesPath[-1] == '/': 
     119                        # strip trailing '/' 
    111120                        self.packagesPath = self.packagesPath[:-1] 
    112121                 
    113122                # if requested, list all ports in the HaikuPorts tree 
    114123                if options.list: 
    115124                        self.listPorts() 
    116125                        sys.exit() 
    117                  
     126 
    118127                # if requested, search for a port 
    119128                if options.search: 
    120129                        if len(args) == 0: 
    121130                                print "You need to specifiy a search string" 
    122131                                print "Invoke '" + sys.argv[0] + " -h' for usage information." 
    123132                                sys.exit() 
     133                                 
    124134                        self.searchPorts(args[0]) 
    125135                        sys.exit() 
    126136 
    … …  
    158168                self.downloadDir= self.portDir + '/' + paths['download'] 
    159169                self.workDir    = self.portDir + '/' + paths['work'] 
    160170                self.patchesDir = self.portDir + '/' + paths['patches'] 
    161  
     171         
    162172                # if the port version was not specified, list available versions 
    163173                if self.portVersion == None: 
    164174                        versions = [] 
    … …  
    174184                                print "  " + version[0] 
    175185                        print "Run beporter again, specifiying a port version" 
    176186                        sys.exit() 
     187                         
     188                # show port description, if requested 
     189                if options.desc: 
     190                        self.desc() 
     191                        sys.exit() 
    177192                 
    178193                # read data from the bep file 
    179194                self.parseBepFile() 
    … …  
    193208                                        pass 
    194209                                else: 
    195210                                        sys.exit() 
    196  
     211                                                 
    197212                # clean the work directory, if requested 
    198213                if options.clean: 
    199214                        self.clean() 
    … …  
    212227                if options.install: 
    213228                        self.install()  # install 
    214229 
     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                         
    215275        def parseBepFile(self): 
    216276                """Parse the BepFile of the specified port""" 
    217277                os.chdir(self.portDir) 
    … …  
    245305                # convert each None/string value into a list (with respectively 0 or 1 element) 
    246306                #       (simplifies implementation ahead) 
    247307                for key in bepTypes: 
    248                         if ListType in bepTypes[key]: 
     308                        if types.ListType in bepTypes[key]: 
    249309                                if self.bepKeys[key] == None: 
    250310                                        self.bepKeys[key] = [] 
    251                                 elif type(self.bepKeys[key]) == StringType: 
     311                                elif type(self.bepKeys[key]) == types.StringType: 
    252312                                        self.bepKeys[key] = [self.bepKeys[key]] 
    253313                                else: 
    254314                                        pass 
    … …  
    623683 
    624684parser = OptionParser(usage="usage: %prog [options] portname[-portversion]", 
    625685                                                version="%prog " + info['version']) 
     686                                                 
    626687parser.add_option("-l", "--list", 
    627688        action="store_true", dest="list", default=False, 
    628689        help="list available ports") 
     690         
     691parser.add_option("-d", "--desc", 
     692        action="store_true", dest="desc", default=False, 
     693        help="show port description") 
     694         
    629695parser.add_option("-s", "--search", 
    630696        action="store_true", dest="search", default=False, 
    631697        help="search for a port (regex)") 
     698         
    632699parser.add_option("-p", "--nopatch", 
    633700        action="store_false", dest="patch", default=True, 
    634701        help="don't patch the sources, just download and unpack") 
     702         
    635703parser.add_option("-b", "--nobuild", 
    636704        action="store_false", dest="build", default=True, 
    637705        help="don't build the port, just download, unpack and patch") 
     706         
    638707parser.add_option("-i", "--install", 
    639708        action="store_true", dest="install", default=False, 
    640709        help="also install the port (the default is to only build)") 
     710         
    641711parser.add_option("-c", "--clean", 
    642712        action="store_true", dest="clean", default=False, 
    643713        help="clean the working directory of the specified port") 
     714         
    644715(options, args) = parser.parse_args() 
    645716 
    646717beporter = BePorter(options, args) 

Download in other formats:

  • Original Format

Trac Powered

Powered by Trac 0.13dev-r10686
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/