dbrtools/dbr/dbrutils.py
author MattD <mattd@symbian.org>
Mon, 15 Mar 2010 19:45:11 +0000
changeset 201 4e09c8ccae86
parent 200 12422144aae1
child 203 e274d29c8bc9
permissions -rw-r--r--
DBRTools - Need to restore the current working directory.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
179
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
     1
# Copyright (c) 2009 Symbian Foundation Ltd
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
     2
# This component and the accompanying materials are made available
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
     3
# under the terms of the License "Eclipse Public License v1.0"
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
     4
# which accompanies this distribution, and is available
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
     5
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
     6
#
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
     7
# Initial Contributors:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
     8
# Symbian Foundation Ltd - initial contribution.
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
     9
#
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    10
# Contributors:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    11
# mattd <mattd@symbian.org>
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    12
#
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    13
# Description:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    14
# DBRutils - Module for handling little bits of stuff to do with generating hashes and scaning directories
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    15
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    16
import re
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    17
import os
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    18
import sys
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    19
import string
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    20
from os.path import join, isfile, stat
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    21
from stat import *
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    22
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    23
import glob # temporary (I hope) used for grabbing stuf from zip files...
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    24
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    25
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    26
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    27
def defaultdb():
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    28
  return os.path.join(patchpath(),'baseline.db')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    29
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    30
def patchpath():
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    31
  return os.path.join(epocroot(),'%s/' % patch_path_internal())
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    32
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    33
def patch_path_internal():
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    34
  return 'epoc32/relinfo'
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    35
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    36
def exclude_dirs():
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    37
    fixpath = re.compile('\\\\')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    38
    leadingslash = re.compile('^%s' % fixpath.sub('/',epocroot()))
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    39
    return [string.lower(leadingslash.sub('',fixpath.sub('/',os.path.join(epocroot(),'epoc32/build')))),string.lower(leadingslash.sub('',fixpath.sub('/',patch_path_internal())))]
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    40
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    41
def exclude_files():
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    42
#    return ['\.sym$','\.dll$'] # just testing...
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    43
    return ['\.sym$']
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    44
    
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    45
def epocroot():
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    46
    return os.environ.get('EPOCROOT')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    47
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    48
def scanenv():
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    49
    print 'Scanning local environment'
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    50
    directory = os.path.join(epocroot(),'epoc32')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    51
    env = scandir(directory, exclude_dirs(), exclude_files())
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    52
    return env
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    53
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    54
def createzip(files, name):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    55
    tmpfilename = os.tmpnam( )
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    56
    print tmpfilename    
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    57
    f = open(tmpfilename,'w')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    58
    for file in sorted(files):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    59
        str = '%s%s' % (file,'\n')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    60
        f.write(str)    
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    61
    f.close()
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    62
    os.chdir(epocroot())
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    63
    exestr = '7z a -Tzip -i@%s %s' %(tmpfilename,name)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    64
    print 'executing: >%s<\n' %exestr
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    65
    os.system(exestr)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    66
    os.unlink(tmpfilename)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    67
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    68
def extractfiles(files, path):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    69
    zips = glob.glob(os.path.join(path, '*.zip'))
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    70
    for name in zips:
200
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
    71
      extractfromzip(files, name,'')    
179
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    72
        
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    73
    
200
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
    74
def extractfromzip(files, name, location):
179
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    75
    tmpfilename = os.tmpnam( )
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    76
    print tmpfilename
201
4e09c8ccae86 DBRTools - Need to restore the current working directory.
MattD <mattd@symbian.org>
parents: 200
diff changeset
    77
    cwd = os.getcwd();
200
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
    78
    os.chdir(os.path.join(epocroot(),location))
179
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    79
    f = open(tmpfilename,'w')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    80
    for file in sorted(files):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    81
        str = '%s%s' % (file,'\n')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    82
        f.write(str)    
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    83
    f.close()
189
0d02b2df4cbb DBRTools - piped the unzip output to null so that cleanenv isn't as noisy.
MattD <mattd@symbian.org>
parents: 179
diff changeset
    84
    exestr = '7z x -y -i@%s %s >nul' %(tmpfilename,name)
0d02b2df4cbb DBRTools - piped the unzip output to null so that cleanenv isn't as noisy.
MattD <mattd@symbian.org>
parents: 179
diff changeset
    85
#    exestr = '7z x -y -i@%s %s' %(tmpfilename,name)
179
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    86
    print 'executing: >%s<\n' %exestr
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    87
    os.system(exestr)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    88
    os.unlink(tmpfilename)
201
4e09c8ccae86 DBRTools - Need to restore the current working directory.
MattD <mattd@symbian.org>
parents: 200
diff changeset
    89
    os.chdir(cwd)
179
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    90
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    91
def deletefiles(files):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    92
    os.chdir(epocroot())
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    93
    for file in files:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    94
      print 'deleting %s' %file
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    95
      os.unlink(file)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    96
          
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    97
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    98
def generateMD5s(testset):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
    99
    db = dict()
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   100
    if(len(testset)):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   101
#      print testset
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   102
      os.chdir(epocroot())
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   103
      tmpfilename = os.tmpnam( )
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   104
      print tmpfilename, '\n'
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   105
      f = open(tmpfilename,'w')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   106
      for file in testset:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   107
          entry = dict()
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   108
          entry['md5'] = 'xxx'
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   109
          db[file] = entry
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   110
          str = '%s%s' % (file,'\n')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   111
          f.write(str)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   112
      f.close()
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   113
      outputfile = os.tmpnam() 
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   114
      exestr = 'evalid -f %s %s %s' % (tmpfilename, epocroot(), outputfile)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   115
#      print exestr
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   116
      exeresult = os.system(exestr) 
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   117
      if(exeresult):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   118
        sys.exit('Fatal error executing: %s\nReported error: %s' % (exestr,os.strerror(exeresult)))
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   119
      else:  
200
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   120
        db = gethashes(db,outputfile, False)
179
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   121
        os.unlink(outputfile)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   122
        os.unlink(tmpfilename)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   123
    return db
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   124
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   125
# Brittle and nasty!!!
200
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   126
def gethashes(db, md5filename, create):
179
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   127
    os.chdir(epocroot())
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   128
#    print 'trying to open %s' % md5filename
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   129
    file = open(md5filename,'r')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   130
    root = ''
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   131
    fixpath = re.compile('\\\\')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   132
    leadingslash = re.compile('^%s' % fixpath.sub('/',epocroot()))
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   133
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   134
    evalidparse = re.compile('(.+)\sTYPE=(.+)\sMD5=(.+)')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   135
    dirparse = re.compile('Directory:(\S+)')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   136
    for line in file:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   137
        res = evalidparse.match(line)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   138
        if(res):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   139
            filename = "%s%s" % (root,res.group(1))
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   140
            filename = string.lower(fixpath.sub('/',leadingslash.sub('',filename)))            
200
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   141
#            print "found %s" % filename
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   142
            if(create):
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   143
              entry = dict()
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   144
              entry['time'] = 'xxx'
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   145
              entry['size'] = 'xxx'
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   146
              entry['md5'] = res.group(3)
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   147
              db[filename] = entry
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   148
            else:    
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   149
              if(filename in db):
12422144aae1 DBRTools - initial version that will diff against a packed release. Also did minor cleanup. Probably caused some regressions.
MattD <mattd@symbian.org>
parents: 189
diff changeset
   150
                  db[filename]['md5'] = res.group(3)
179
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   151
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   152
        else:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   153
            res = dirparse.match(line)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   154
            if(res):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   155
                if(res.group(1) == '.'):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   156
                    root = ''
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   157
                else:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   158
                    root = '%s/' % res.group(1)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   159
            
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   160
    file.close()
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   161
    return db
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   162
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   163
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   164
def scandir(top, exclude_dirs, exclude_files):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   165
# exclude_dirs must be in lower case...
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   166
#    print "Remember to expand the logged dir from", top, "!!!"
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   167
    countdown = 0
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   168
    env = dict()
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   169
    fixpath = re.compile('\\\\')
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   170
    leadingslash = re.compile('^%s' % fixpath.sub('/',epocroot()))
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   171
    
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   172
    ignorestr=''
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   173
    for exclude in exclude_files:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   174
      if(len(ignorestr)):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   175
        ignorestr = '%s|%s' % (ignorestr, exclude)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   176
      else:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   177
        ignorestr = exclude    
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   178
    ignore = re.compile(ignorestr) 
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   179
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   180
    for root, dirs, files in os.walk(top, topdown=True):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   181
        for dirname in dirs:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   182
#            print string.lower(leadingslash.sub('',fixpath.sub('/',os.path.join(root,dirname))))
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   183
            if(string.lower(leadingslash.sub('',fixpath.sub('/',os.path.join(root,dirname)))) in exclude_dirs):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   184
#              print 'removing: %s' % os.path.join(root,dirname)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   185
              dirs.remove(dirname)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   186
        for name in files:
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   187
            filename = os.path.join(root, name)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   188
            statinfo = os.stat(filename)
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   189
            fn = string.lower(leadingslash.sub('',fixpath.sub('/',filename)))
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   190
#            print '%s\t%s' % (filename, fn);
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   191
            if(countdown == 0):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   192
                print '.',
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   193
                countdown = 1000
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   194
            countdown = countdown-1
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   195
            if not ignore.search(fn,1):
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   196
              entry = dict()
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   197
              entry['time'] = '%d' % statinfo[ST_MTIME]
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   198
              entry['size'] = '%d' % statinfo[ST_SIZE]
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   199
              entry['md5'] = 'xxx'
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   200
              env[fn] = entry
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   201
  #            data = [statinfo[ST_MTIME],statinfo[ST_SIZE],'xxx']
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   202
  #            env[fn] = data
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   203
    print '\n'
eab8a264a833 Pulled the DBRTools from their own repo and popped them into this one. Still very much a 'work in progress'.
MattD <mattd@symbian.org>
parents:
diff changeset
   204
    return env