Beispiel #1
0
    def __init__(self,f=None):
        if not f:f=self.fileinfo['filepath']
        self.filelist=[r for r in utilities.rglob(os.path.dirname(f))]
        self._led=f
        self._vol=glob.glob(os.path.dirname(f) + '/[Vv][Oo][Ll]*')[0] #volume file

        img_regex=[
              r'IMG-0[1-4]-ALAV.*_U$',     #ALOS AVNIR-2 img file
              r'IMG-[HV][HV]-ALPSR.*UD$',  #ALOS PALSAR
              r'IMG-ALPSM.*\_U[BFN]$'      #ALOS PRISM
        ]
        self._imgs=[i for i in utilities.rglob(os.path.dirname(f),'|'.join(img_regex),True,re.I, False)]
        
        self.fileinfo['filepath']=self._led #change filename to leader file
        self.fileinfo['filename']=os.path.basename(self._led)
Beispiel #2
0
    def __init__(self,dir):
        ''' 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,False):
            #Use latin-1 encoding to fix Issue 20
            f=utilities.realpath(utilities.normcase(utilities.encode(f)))
            for r in format_regex:
                if re.search(r,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)
Beispiel #3
0
def CreateMEF(outdir,xmlfile,uid,overviews=[]):
    '''Generate Geonetwork "Metadata Exchange Format" from an ISO19139 XML record
    
    @see:
        
        U{http://www.fao.org/geonetwork/docs/ch17s02.html}
        
        U{http://trac.osgeo.org/geonetwork/wiki/MEF}
    
    @param outdir: Directory to write MEF file to.
    @param xmlfile: XML file to create MEF from.
    @param uid: ID of metadata record (UUID/GUID string).
    @keyword overviews: List of overview image file (e.g quicklooks & thumbnails) OPTIONAL.

    @todo: Assumes metadata is ISO19139, need to make generic somehow...

    '''
    xmldir=_path.dirname(xmlfile)
    curdir=_path.abspath(_os.curdir)
    mefdir=_path.join(_os.environ['TEMP'],_path.basename(_path.splitext(xmlfile)[0]))
    mefpath='%s.mef'%(_path.join(outdir,_path.basename(_path.splitext(xmlfile)[0])))
    #mefdir=_path.splitext(xmlfile)[0]) #to get around 260 char filename limit...
    #mefpath='%s.mef'%(mefdir)
    try:
        if _path.exists(mefpath):_os.remove(mefpath)
        if _path.exists(mefdir):_sh.rmtree(mefdir)
        mef=_zip.ZipFile(mefpath,'w',_zip.ZIP_DEFLATED)
        _os.mkdir(mefdir)
        _os.chdir(mefdir)
        ##mef=_zip.ZipFile(r'%s.mef'%(uid),'w',_zip.ZIP_DEFLATED)
        ##_os.mkdir(uid)
        ##_os.chdir(uid)
        _sh.copy(xmlfile,'metadata.xml')
        if overviews:
            _os.mkdir('public')
            for f in overviews:
                _sh.copy(f,_path.join('public',_path.basename(f)))
        _CreateInfo(uid,overviews)
        _sh.copy(xmlfile,'metadata.xml')
        for f in _utilities.rglob('.'):
            if not _path.isdir(f): mef.write(f)
    finally:
        try:_os.chdir(curdir)
        except:pass        
        try:
            mef.close()
            del mef
        except:pass
        try:_sh.rmtree(mefdir)
        except:pass
Beispiel #4
0
    def __init__(self,f=None):
        '''Open the dataset'''
        if not f:f=self.fileinfo['filepath']

        led=glob.glob(os.path.dirname(f) + '/[Ll][Ee][Aa][Dd]*')[0] #volume file
        meta = open(led,'rb').read()

        #Record 2 - Scene header record
        record=2
        recordlength=3960 #SPOT recordlength=3960 
        satellite=utilities.readbinary(meta,(record-1)*recordlength,613,628)
        if not satellite[0:4] == 'SPOT':
            raise NotImplementedError #This error gets ignored in __init__.Open()
        self.filelist=[r for r in utilities.rglob(os.path.dirname(f))] #everything in this dir and below.
Beispiel #5
0
    def __init__(self,f):
        if not f:f=self.fileinfo['filepath']
        d=os.path.dirname(f)

        if open(f).read(1024).strip()[0]=='<':#HTML file, ignore it.
            raise NotImplementedError
        
        if 'HRF' in f.upper():
            self._filetype='HRF'
            #rex='BAND[1-57]\.dat|L7[0-9]{7,7}_[0-9]{11,11}_B[1-57]0\.FST' #not picking up the ACRES .ers files
            rex='BAND[1-57].*|L7[0-9]{7,7}_[0-9]{11,11}_B[1-57]0\.FST'
        elif 'HTM' in f.upper():
            self._filetype='HTM'
            #rex='BAND6[LH]\.dat|L7[0-9]{7,7}_[0-9]{11,11}_B6[1-2]\.FST' #not picking up the ACRES .ers files
            rex='BAND6[LH].*|L7[0-9]{7,7}_[0-9]{11,11}_B6[1-2]\.FST'
        elif 'HPN' in f.upper():
            self._filetype='HPN'
            #rex='BAND8\.dat|L7[0-9]{7,7}_[0-9]{11,11}_B80\.FST' #not picking up the ACRES .ers files
            rex='BAND8.*|L7[0-9]{7,7}_[0-9]{11,11}_B80\.FST'
        
        self.filelist=[f] #header
        self.filelist.extend([f for f in utilities.rglob(d,rex,regex=True, regex_flags=re.I, recurse=False)]) #bands
        pass
Beispiel #6
0
    def __init__(self,f=None):
        '''Open the dataset'''
        if not f:f=self.fileinfo['filepath']
        self.filelist=[r for r in utilities.rglob(os.path.dirname(f))] #everything in this dir and below.

        led=glob.glob(os.path.dirname(f) + '/[Ll][Ee][Aa][Dd]*')[0] #volume file

        meta = open(led,'rb').read()

        '''
        metadata has 4 records, each is 4320 (LS) or 6120 (SPOT) bytes long:
        File descriptor record;
        Scene header record;
        Map projection (scene-related) ancillary record;
        Radiometric transformation ancillary record.
        '''

        #Record 2 - Scene header record
        record=2
        recordlength=4320 #LS 5
        satellite=utilities.readbinary(meta,(record-1)*recordlength,309,324)
        if not satellite[0:7] == 'LANDSAT':
            raise NotImplementedError #This error gets ignored in __init__.Open()
                if vers.count('.')==0:
                    vers=vers+'.0.0.'+rev
                elif vers.count('.')==1:
                    vers=vers+'.0.'+rev
                elif vers.count('.')==2:
                    vers=vers+'.'+rev
                outfile=vers
        if not displayversion:
            if 'trunk' in vers :
                displayversion='%s-%s'%(vers.replace('/','-'),rev)
            else:
                displayversion=vers
        outfile=displayversion.replace(' ','-').lower()
        ##########################################################
        print 'Cleaning up compiled objects'
        for pyco in rglob(BIN_DIR,'*.py[c|o]'):
            os.remove(pyco)

        ##########################################################
        print 'Exporting from SVN repo'
        #cmd='svn export -q --force http://metageta.googlecode.com/svn/%s %s/metageta'%(repo,tmp)

        #DSEWPaC web filter blocks svn:external .bat files with svn export, use checkout
        #instead, then export from the local copy and remove it after
        cmd='svn checkout http://metageta.googlecode.com/svn/%s %s/metageta-svn'%(repo,tmp)
        exit_code,stdout,stderr=runcmd(cmd)
        if exit_code != 0:
            if stderr:    print stderr
            elif stdout:  print stdout
            else :        print 'SVN export failed'
            cleanup(tmp)
                if vers.count('.') == 0:
                    vers = vers + '.0.0.' + rev
                elif vers.count('.') == 1:
                    vers = vers + '.0.' + rev
                elif vers.count('.') == 2:
                    vers = vers + '.' + rev
                outfile = vers
        if not displayversion:
            if 'trunk' in vers:
                displayversion = '%s-%s' % (vers.replace('/', '-'), rev)
            else:
                displayversion = vers
        outfile = displayversion.replace(' ', '-').lower()
        ##########################################################
        print 'Cleaning up compiled objects'
        for pyco in rglob(BIN_DIR, '*.py[c|o]'):
            os.remove(pyco)

        ##########################################################
        print 'Exporting from SVN repo'
        #cmd='svn export -q --force http://metageta.googlecode.com/svn/%s %s/metageta'%(repo,tmp)

        #DSEWPaC web filter blocks svn:external .bat files with svn export, use checkout
        #instead, then export from the local copy and remove it after
        cmd = 'svn checkout http://metageta.googlecode.com/svn/%s %s/metageta-svn' % (
            repo, tmp)
        exit_code, stdout, stderr = runcmd(cmd)
        if exit_code != 0:
            if stderr: print stderr
            elif stdout: print stdout
            else: print 'SVN export failed'