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

Context Navigation

  • Back to Ticket #51

Ticket #51: haikuporter.checksum.patch

File haikuporter.checksum.patch, 2.5 KB (added by thorn, 6 years ago)

basic checksum support

  • haikuporter

     
    2020import tarfile 
    2121import zipfile 
    2222import types 
     23import hashlib 
    2324from optparse import OptionParser 
    2425 
    2526# -- HaikuPorts options ------------------------------------------------------- 
    … …  
    4445 
    4546# allowed types of the BepFile values 
    4647bepTypes = {} 
    47 bepTypes['DESCRIPTION'] = [types.StringType, types.ListType] 
    48 bepTypes['HOMEPAGE']    = [types.StringType] 
    49 bepTypes['SRC_URI']             = [types.StringType, types.ListType] 
    50 bepTypes['REVISION']    = [types.IntType] 
    51 bepTypes['STATUS_HAIKU']= [StatusType] 
    52 bepTypes['DEPEND']              = [types.StringType, types.ListType, types.NoneType] 
    53 bepTypes['BUILD']               = [ShellType] 
    54 bepTypes['INSTALL']             = [ShellType] 
     48bepTypes['DESCRIPTION']  = [types.StringType, types.ListType] 
     49bepTypes['HOMEPAGE']     = [types.StringType] 
     50bepTypes['SRC_URI']              = [types.StringType, types.ListType] 
     51bepTypes['CHECKSUM_MD5'] = [types.StringType] 
     52bepTypes['REVISION']     = [types.IntType] 
     53bepTypes['STATUS_HAIKU'] = [StatusType] 
     54bepTypes['DEPEND']               = [types.StringType, types.ListType, types.NoneType] 
     55bepTypes['BUILD']                = [ShellType] 
     56bepTypes['INSTALL']              = [ShellType] 
    5557 
    5658                                                        # is field       #      default 
    5759bepDefaults = {}                        # required?      #      value 
    5860bepDefaults['DESCRIPTION']      = [True,                None            ] 
    5961bepDefaults['HOMEPAGE']         = [True,                None            ] 
    6062bepDefaults['SRC_URI']          = [True,                None            ] 
     63bepDefaults['CHECKSUM_MD5']     = [False,               None            ] 
    6164bepDefaults['REVISION']         = [True,                None            ] 
    6265bepDefaults['WORKING']          = [False,               True            ] 
    6366bepDefaults['STATUS_HAIKU']     = [False,               'untested'      ] 
    … …  
    233236 
    234237                self.checkDeps()        # check dependencies 
    235238                self.fetch()            # fetch sources 
     239                self.checksum()         # calculate checksum 
    236240                self.unpack()           # unpack source archive 
    237241                if options.patch: 
    238242                        self.patch()    # apply patches 
    … …  
    520524                sys.stdout.write('\r' + progressInfo) 
    521525                sys.stdout.flush() 
    522526 
     527        def checksum(self):  
     528                if self.bepKeys['CHECKSUM_MD5']: 
     529                        sys.stdout.write('Calculating checksum -') 
     530                        sys.stdout.flush() 
     531                        h = hashlib.md5() 
     532                        f = open(self.src_local, 'rb') 
     533                        while True: 
     534                                d = f.read(16384) 
     535                                if not d: 
     536                                        break 
     537                                h.update(d) 
     538                        f.close() 
     539                        if h.hexdigest() == self.bepKeys['CHECKSUM_MD5']: 
     540                                sys.stdout.write(' OK\n') 
     541                        else: 
     542                                sys.stdout.write(' FAILED\n') 
     543                                sys.exit() 
     544                        sys.stdout.flush() 
     545                else: 
     546                        print "CHECKSUM_MD5 not found" 
     547 
    523548        def unpack(self): 
    524549                """Unpack the source archive (into the work directory)""" 
    525550                # create work dir 

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/