Example #1
0
    def __init__(self,dir, recurse=True, archive=False):
        ''' Iterator for metadata crawling

            @type  dir: C{str}
            @param dir: The directory to start the metadata crawl.
        '''

        format_regex  = formats.format_regex
        dir=utilities.uncpath(utilities.realpath(utilities.normcase(utilities.encode(dir))))
        #Build a dict of matching files and regexes then sort according to the priority of the regex formats
        fileformats={}
        for f in utilities.rglob(dir,'|'.join(format_regex), True, re.IGNORECASE, recurse=recurse, archive=archive):
            #Don't return existing overviews
            if f[-7:] in ('qlk.jpg','thm.jpg'):continue
            #Use utf-8 encoding to fix Issue 20
            if f[:4]=='/vsi':f=utilities.encode(f)
            else:f=utilities.realpath(utilities.normcase(utilities.encode(f)))
            for r in format_regex: #This is so we always return _default_ format datasets last.
                if re.search(r,os.path.basename(f),re.IGNORECASE):
                    if fileformats.has_key(r):fileformats[r].append(f)
                    else:fileformats[r]=[f]
                    break
        files=[]
        for r in format_regex:
            if fileformats.has_key(r):files.extend(fileformats[r])

        #Class vars
        self.errors=[] #A list of files that couldn't be opened. Contains a tuple with file name, error info, debug info
        self.files=files
        self.file=''
        self.filecount=len(self.files)
Example #2
0
    def __init__(self, dir, recurse=True, archive=False, excludes=[]):
        ''' Iterator for metadata crawling

            @type  dir: C{str}
            @param dir: The directory to start the metadata crawl.
            @type    recurse: C{bool}
            @param   recurse: Recurse into subdirectories?
            @type    archive: C{bool}
            @param   archive: Look in zip/gzip archives
            @type    excludes: C{list}
            @param   excludes: List of glob style file/directory exclusion pattern/s
        '''

        #Class vars
        self.errors = [
        ]  #A list of files that couldn't be opened. Contains a tuple with file name, error info, debug info

        format_regex = formats.format_regex
        dir = utilities.uncpath(
            utilities.realpath(utilities.normcase(utilities.encode(dir))))
        #Build a dict of matching files and regexes then sort according to the priority of the regex formats
        fileformats = {}
        for f in utilities.rglob(dir,
                                 '|'.join(format_regex),
                                 True,
                                 re.IGNORECASE,
                                 recurse=recurse,
                                 archive=archive,
                                 excludes=excludes,
                                 onerror=self.onerror,
                                 followlinks=False):
            #Don't return existing overviews
            if f[-7:] in ('qlk.jpg', 'thm.jpg'): continue
            #Use utf-8 encoding to fix Issue 20
            if f[:4] == '/vsi': f = utilities.encode(f)
            else:
                f = utilities.realpath(utilities.normcase(utilities.encode(f)))
            for r in format_regex:  #This is so we always return _default_ format datasets last.
                if re.search(r, os.path.basename(f), re.IGNORECASE):
                    if fileformats.has_key(r): fileformats[r].append(f)
                    else: fileformats[r] = [f]
                    break
        files = []
        for r in format_regex:
            if fileformats.has_key(r): files.extend(fileformats[r])

        #Class vars
        self.files = files
        self.file = ''
        self.filecount = len(self.files)
    def __getfilelist__(self, *args, **kwargs):
        '''Get all files that have the same name (sans .ext), or are related according to gdalinfo.
            Special cases may be handled separately in their respective format drivers.'''
        f = self.fileinfo['filepath']
        files = []
        try:
            files = glob.glob(os.path.splitext(f)[0] + '.*')
            if os.path.exists(os.path.splitext(f)[0]):
                files.append(os.path.splitext(f)[0])
            hdr_dir = os.path.join(
                os.path.split(f)[0],
                'headers')  #Cause ACRES creates a 'headers' directory
            if os.path.exists(hdr_dir):
                files.extend(glob.glob(os.path.join(hdr_dir, '*')))
        except:
            pass  # Need to handle errors when dealing with an VRT XML string better...

        if self._gdaldataset:
            #try:files.extend(self._gdaldataset.GetFileList()) #GetFileList can return files that don't exist... - e.g. the aux.xml in a read-only directory
            try:
                files.extend([
                    os.path.abspath(f)
                    for f in self._gdaldataset.GetFileList()
                    if os.path.exists(f)
                ])
            except:
                pass

        self._filelist = list(set(
            utilities.normcase(files)))  #list(set([])) filters out duplicates
Example #4
0
    def __init__(self, dir, recurse=True, archive=False):
        ''' Iterator for metadata crawling

            @type  dir: C{str}
            @param dir: The directory to start the metadata crawl.
        '''

        format_regex = formats.format_regex
        dir = utilities.uncpath(
            utilities.realpath(utilities.normcase(utilities.encode(dir))))
        #Build a dict of matching files and regexes then sort according to the priority of the regex formats
        fileformats = {}
        for f in utilities.rglob(dir,
                                 '|'.join(format_regex),
                                 True,
                                 re.IGNORECASE,
                                 recurse=recurse,
                                 archive=archive):
            #Use utf-8 encoding to fix Issue 20
            if f[:4] == '/vsi': f = utilities.encode(f)
            else:
                f = utilities.realpath(utilities.normcase(utilities.encode(f)))
            for r in format_regex:  #This is so we always return _default_ format datasets last.
                if re.search(r, os.path.basename(f), re.IGNORECASE):
                    if fileformats.has_key(r): fileformats[r].append(f)
                    else: fileformats[r] = [f]
                    break
        files = []
        for r in format_regex:
            if fileformats.has_key(r): files.extend(fileformats[r])

        #Class vars
        self.errors = [
        ]  #A list of files that couldn't be opened. Contains a tuple with file name, error info, debug info
        self.files = files
        self.file = ''
        self.filecount = len(self.files)
Example #5
0
    def __getfilelist__(self,*args,**kwargs):
        '''Get all files that have the same name (sans .ext), or are related according to gdalinfo.
            Special cases may be handled separately in their respective format drivers.'''
        f=self.fileinfo['filepath']
        files=[]
        try:
            files=glob.glob(os.path.splitext(f)[0]+'.*')
            if os.path.exists(os.path.splitext(f)[0]):files.append(os.path.splitext(f)[0])
            hdr_dir=os.path.join(os.path.split(f)[0], 'headers') #Cause ACRES creates a 'headers' directory
            if os.path.exists(hdr_dir):
                files.extend(glob.glob(os.path.join(hdr_dir,'*')))
        except:pass # Need to handle errors when dealing with an VRT XML string better...

        if self._gdaldataset:
            #try:files.extend(self._gdaldataset.GetFileList()) #GetFileList can return files that don't exist... - e.g. the aux.xml in a read-only directory
            try:files.extend([os.path.abspath(f) for f in self._gdaldataset.GetFileList() if os.path.exists(f)])
            except:pass

        self._filelist=list(set(utilities.normcase(files))) #list(set([])) filters out duplicates
 def fset(self, *args, **kwargs):
     if len(args) == 1: self._filelist = utilities.normcase(args[0])
     elif len(args) == 2:
         self._filelist[args[0]] = utilities.normcase(args[1])
Example #7
0
 def fset(self, *args, **kwargs):
     if len(args) == 1:self._filelist = utilities.normcase(args[0])
     elif len(args) == 2:self._filelist[args[0]] = utilities.normcase(args[1])