Changeset 5246 for ndgCommon


Ignore:
Timestamp:
05/05/09 10:21:19 (10 years ago)
Author:
cbyrom
Message:

Tighten up package definition to allow overlap with ndg.security +
adjust resource finding for this scenario + improve fileutilities
cleandir method, using python code rather than system ops to do work +
relax equality method for abstract records slightly.

Location:
ndgCommon/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ndgCommon/trunk/ndg/__init__.py

    r4793 r5246  
     1"""NDG common  
     2 
     3http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages 
     4 
     5... for details. 
     6""" 
     7 
     8__import__('pkg_resources').declare_namespace(__name__) 
  • ndgCommon/trunk/ndg/common/src/lib/fileutilities.py

    r5058 r5246  
    8686    ''' 
    8787    logging.info("Cleaning dir " + dir) 
    88     commandline = "find " + dir + "  -type f -print | xargs -i rm \{\}" 
    89     logging.debug("Executing : " + commandline) 
     88    # add in a little safety check here - we don't want to delete large chunks 
     89    # of the filesystem by accident... 
     90    if dir.strip().startswith('/') and len(dir) < 5: 
     91        raise ValueError("Top level directory specified (or something close to this) - will not delete the entire system") 
    9092 
    91     status = os.system(commandline) 
    92     if status != 0: 
    93         sys.exit("Failed at cleaning out directory, %s" %dir) 
    94      
     93    for root, dirs, files in os.walk(dir, topdown=False): 
     94        for name in files: 
     95            os.remove(os.path.join(root, name)) 
     96        for name in dirs: 
     97            os.rmdir(os.path.join(root, name)) 
    9598    logging.info("Directory cleaned successfully") 
    9699 
  • ndgCommon/trunk/ndg/common/src/lib/ndgresources.py

    r4991 r5246  
    1717class ndgResources(object): 
    1818     
    19     def __init__(self, directory='common/xmldb/'): 
     19    def __init__(self, directory='xmldb/'): 
    2020        '''  
    2121        Loads up resources from the internal package directory 
    2222        @keyword directory: root directory from which to retrieve docs from. 
    23         Default is 'common/xmldb/' 
     23        Default is 'xmldb/' 
    2424        ''' 
    2525        logging.debug("Initialising ndgResources") 
     
    5151        ''' 
    5252        xqueryDir = directory + 'xquery' 
    53         files=pkg_resources.resource_listdir('ndg', xqueryDir) 
     53        files=pkg_resources.resource_listdir('ndg.common', xqueryDir) 
    5454        # this next bit to get rid of .svn and anything else in testing 
    5555        self.xq = {} 
     
    5757            if f.endswith('.xq'): 
    5858                self.xq[re.sub('.xq\Z','',f)] = \ 
    59                     pkg_resources.resource_string('ndg','%s/%s'%(xqueryDir,f)) 
     59                    pkg_resources.resource_string('ndg.common','%s/%s'%(xqueryDir,f)) 
    6060 
    6161        schemaDir = directory + 'schema' 
    62         files=pkg_resources.resource_listdir('ndg', schemaDir) 
     62        files=pkg_resources.resource_listdir('ndg.common', schemaDir) 
    6363        self.xsd = {} 
    6464        for f in files: 
    6565            if f.endswith('.xsd'): 
    6666                self.xsd[re.sub('.xsd\Z','',f)] = \ 
    67                     pkg_resources.resource_string('ndg','%s/%s'%(schemaDir, f)) 
     67                    pkg_resources.resource_string('ndg.common','%s/%s'%(schemaDir, f)) 
    6868                           
    6969        # add the various xquery libraries, too 
     
    7171        for dir in ['Vocabs', 'Utilities', 'StubB']: 
    7272            xqueryLibDir = xqueryDir + '/lib/' + dir 
    73             files = pkg_resources.resource_listdir('ndg', xqueryLibDir) 
     73            files = pkg_resources.resource_listdir('ndg.common', xqueryLibDir) 
    7474            for f in files: 
    7575                if f.endswith('.xquery'):  
    7676                    fullPath = '%s/%s'%(xqueryLibDir,f) 
    7777                    partPath = '/%s/%s' %(dir, f) 
    78                     self.xqlib[partPath] = pkg_resources.resource_string('ndg', fullPath) 
     78                    self.xqlib[partPath] = pkg_resources.resource_string('ndg.common', fullPath) 
    7979         
    8080        # also add the organisation data files - NB, this class should be generalised 
    8181        # to make more sense... 
    8282        resourceDir = directory + 'resources' 
    83         files = pkg_resources.resource_listdir('ndg', resourceDir) 
     83        files = pkg_resources.resource_listdir('ndg.common', resourceDir) 
    8484        self.resources = {} 
    8585        for f in files: 
    8686            if f.endswith('.xml'):  
    8787                self.resources[f] = \ 
    88                     pkg_resources.resource_string('ndg','%s/%s' %(resourceDir, f)) 
     88                    pkg_resources.resource_string('ndg.common','%s/%s' %(resourceDir, f)) 
    8989 
    9090        # lastly, add the indexes 
     
    9292        for dir in ['eXist']: 
    9393            indexDir = directory + 'indexing' + '/' + dir 
    94             files = pkg_resources.resource_listdir('ndg', indexDir) 
     94            files = pkg_resources.resource_listdir('ndg.common', indexDir) 
    9595            for f in files: 
    9696                if f.endswith('.xconf'):  
    9797                    self.indexes[f] = \ 
    98                         pkg_resources.resource_string('ndg','%s/%s'%(indexDir,f)) 
     98                        pkg_resources.resource_string('ndg.common','%s/%s'%(indexDir,f)) 
    9999         
    100100         
  • ndgCommon/trunk/ndg/common/src/models/abstractrecord.py

    r5231 r5246  
    9090             
    9191            if getattr(self, att) != getattr(other, att): 
    92                 return False 
     92                # NB, allow comparison of bools as strings and booleans 
     93                if str(getattr(self, att)) != str(getattr(other, att)): 
     94                    return False 
    9395 
    9496        return True 
  • ndgCommon/trunk/setup.py

    r4983 r5246  
    1212                                                  'common/xmldb/xquery/*.xq', 
    1313                                                  'common/xmldb/xquery/lib/*/*.xquery']}, 
     14        namespace_packages =    ['ndg', 'ndg.common'], 
    1415        author = 'Calum Byrom', 
    1516        license = 'LGPL', 
Note: See TracChangeset for help on using the changeset viewer.