Changeset 2fb99de in flex_extract.git for python/MarsRetrieval.py


Ignore:
Timestamp:
Sep 20, 2018, 11:56:37 AM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
5d42acd
Parents:
3232589
Message:

introduced config with path definitions and changed py files accordingly; Installation works; some tests were added for tarball making; Problems in submission to ecgate

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/MarsRetrieval.py

    r54a8a01 r2fb99de  
    6565import os
    6666
     67import _config
    6768# ------------------------------------------------------------------------------
    6869# CLASS
     
    310311        '''
    311312        @Description:
    312             Prints all class attributes and their values.
     313            Prints all class attributes and their values to the
     314            standard output.
    313315
    314316        @Input:
     
    328330                pass
    329331            else:
    330                 print item[0] + ': ' + str(item[1])
     332                print(item[0] + ': ' + str(item[1]))
     333
     334        return
     335
     336
     337    def print_info(self):
     338        '''
     339        @Description:
     340            Prints all mars requests to an extra file for debugging and
     341            information.
     342
     343        @Input:
     344            self: instance of MarsRetrieval
     345                For description see class documentation.
     346
     347        @Return:
     348            <nothing>
     349        '''
     350        # Get all class attributes and their values as a dictionary
     351        attrs = vars(self)
     352
     353        # open a file to store all requests to
     354        with open(os.path.join(_config.PATH_RUN_DIR,
     355                               _config.FILE_MARS_REQUESTS), 'a') as f:
     356            f.write('mars\n')
     357            # iterate through all attributes and print them
     358            # with their corresponding values
     359            for item in attrs.items():
     360                if item[0] in 'server':
     361                    pass
     362                else:
     363                    f.write(item[0] + ': ' + str(item[1]) + '\n')
     364            f.write('\n\n')
    331365
    332366        return
     
    371405                self.server.execute(s, target)
    372406            except:
    373                 print 'MARS Request failed, \
    374                     have you already registered at apps.ecmwf.int?'
     407                print('MARS Request failed, \
     408                      have you already registered at apps.ecmwf.int?')
    375409                raise IOError
    376410            if os.stat(target).st_size == 0:
    377                 print 'MARS Request returned no data - please check request'
     411                print('MARS Request returned no data - please check request')
    378412                raise IOError
    379413        # MARS request via extra process in shell
     
    384418                                 stderr=subprocess.PIPE, bufsize=1)
    385419            pout = p.communicate(input=s)[0]
    386             print pout.decode()
     420            print(pout.decode())
    387421
    388422            if 'Some errors reported' in pout.decode():
    389                 print 'MARS Request failed - please check request'
     423                print('MARS Request failed - please check request')
    390424                raise IOError
    391425
    392426            if os.stat(target).st_size == 0:
    393                 print 'MARS Request returned no data - please check request'
     427                print('MARS Request returned no data - please check request')
    394428                raise IOError
    395429
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG