Пример #1
0
def buildCommand(config):

    dir = 'Waveform'  # directory of local python scripts
    action = sys.argv[1]
    intern = Intern(action)

    if action == 'getstations':

        #  python arraytool.py(0)  getmeta(1) <event dir>(2)

        intern.checkProgramParameter(3, 3)

        at = os.path.join(os.getcwd(), dir, 'getStationList.py')
        cmd = sys.executable + ' ' + at + ' -f ' + Globals.EventDir()

    elif action == 'getdata':

        #  python arraytool.py(0)  getdata(1) <event dir>(2)  [network(3)]

        intern.checkProgramParameter(3, 4)

        at = os.path.join(os.getcwd(), dir, 'getStationWaveformData.py')
        cmd = sys.executable + ' ' + at + ' -f ' + Globals.EventDir()

        if len(sys.argv) > 3: cmd += (' -n ' + sys.argv[3])  # specific network

    elif action == 'getmeta':

        #  python arraytool.py(0)  getmeta(1) <event dir>(2)  [network(3)]

        intern.checkProgramParameter(3, 4)

        path = Globals.EventDir()  # event directory
        at = os.path.join(os.getcwd(), dir, 'ev_meta_mt4.py')
        C = config.Config(path)
        Origin = C.parseConfig('origin')

        d = obspy.core.utcdatetime.UTCDateTime(Origin['time'])
        jd = "%03d" % d.julday
        cmd = ('%s %s -p %s -y %s -d %s') % (sys.executable, at, path,
                                             str(d.year), str(jd))

        if len(sys.argv) > 3: cmd += (' -n ' + sys.argv[3])  # specific network

    else:
        return None

    return cmd
Пример #2
0
def start(config):

    intern = Intern()

    if sys.argv[1] == 'process':
        intern.checkProgramParameter(3, 4)

        path = Globals.EventDir()
        path_emp = Globals.EventDir_emp()
        try:
            path_emp = Globals.EventDir_emp()
            at = os.path.join(os.getcwd(), 'Process', 'main.py')
            workDir = [path, 'tmp2', 'process']
            workDir = ['tmpProcess']
            cmd = sys.executable + ' ' + at + ' -f ' + path + ' -e ' + path_emp
        except IndexError:
            at = os.path.join(os.getcwd(), 'Process', 'main.py')
            workDir = [path, 'tmp2', 'process']
            workDir = ['tmpProcess']
            cmd = sys.executable + ' ' + at + ' -f ' + path
    else:
        return False

    Basic.changeDirectory(workDir)
    os.system(cmd)
    return True
Пример #3
0
def checkKeys(conf, keyList, optional=False):

    if type(keyList) is str:
        list1 = list(keyList)
    else:
        list1 = keyList

    if not optional:
        Basic.checkExistsKeys(conf, list1, isAbort=True)

    eventDir = Globals.EventDir()
    isOk = True

    for key in list1:
        val = conf[key]
        msg = None

        if key == duration:
            msg = Basic.checkGreaterZero(val)
        elif key in [mindist, maxdist]:
            msg = Basic.checkNotNegative(val)
        elif key in [keyfilefolder, metaCatalog]:
            Basic.checkExistsDir(os.path.join(eventDir, val), isAbort=True)
        elif key in [blacklist, mail, pwd]:
            continue

        if msg is not None:
            isOk = Logfile.error('Key <' + key + '> in config file: ' + msg)

    if not isOk:
        Logfile.abort()
    return True
Пример #4
0
def start(config):

    intern = Intern()

    if sys.argv[1] == 'cluster':
        intern.checkProgramParameter(3, 4)

        at = os.path.join(os.getcwd(), 'Cluster',
                          'callcluster.py')  # directory of python scripts
        workDir = [Globals.EventDir(), 'tmp2', 'cluster']  # ???
        workDir = ['Cluster']
        cmd = sys.executable + ' ' + at + ' -f ' + Globals.EventDir()

    else:
        return False

    Basic.changeDirectory(workDir)  # create working directory
    #Basic.removeFiles('.')             # ... and empty it

    os.system(cmd)
    return True
Пример #5
0
def _getFromCatalog(network):

    return None

    # spaeter ???

    dir = os.path.join(Globals.EventDir(), "keyfiles_catalog")
    files = os.listdir(dir)
    selected = []

    for file in files:
        if file.startwith('station_' + network + '_'):
            selected.append(file)
Пример #6
0
def getFileNames(eventDir=None):

    if eventDir == None: eventDir = Globals.EventDir()

    names = []
    path = os.path.join(eventDir, DATA_DIR)

    for root, dirs, files in os.walk(path):
        for s in files:
            names.append(s)

    #Logfile.addLines(names)
    return sorted(names)
Пример #7
0
    def checkProgramParameter(self, nMinParams, nMaxParams):

        eventName = sys.argv[2]

        if len(sys.argv) < nMinParams: self.error('event name missing')
        if len(sys.argv) > nMaxParams: self.error('Too many parameters')

        if not Globals.checkEventDirParameter(
                eventName):  # Exists event directory ?

            s = 'Invalid parameter - <' + eventName + '>'
            s += '\n        '
            s += 'Cannot find directory ' + Globals.EventDir()
            self.error(s)
Пример #8
0
def initFile(fileName=None, postfix=''):

    dir = Globals.EventDir()

    if not os.path.isdir(dir):
        return None  # ??? Fehler: in Process.main - parallel = True

    if fileName == None:
        log1 = os.path.join(dir, baseLogFileName(postfix))
    else:
        log1 = os.path.join(dir, fileName)

    if not os.path.isfile(log1):
        fp = open(log1, 'w')
        fp.close()
        assert os.path.isfile(log1)

    elif os.stat(log1).st_size < 10 * 1024 * 1024:
        return log1
    else:
        os.remove(log1)
        return log1

    # cut logfile to last n lines   ???
    #
    lines = Basic.readTextFile(log1)
    n = len(lines)
    #print 'n = ', n

    if n > MAX_LINES:
        print 'resize log file ' + log1 + '...'
        lines.append('resize log file to the last ' + str(MAX_LINES) +
                     ' lines')
        newLines = lines[n - MAX_LINES:]
        Basic.writeTextFile(log1, newLines)

    #endif

    return log1
Пример #9
0
def start(config):

    intern = Intern()

    if sys.argv[1] == 'process':

        #  python arraytool.py(0)  process(1) <event dir>(2)

        intern.checkProgramParameter(3, 3)

        path = Globals.EventDir()
        at = os.path.join(os.getcwd(), 'Process', 'main.py')  # python script
        workDir = [path, 'tmp2', 'process']  # ???
        workDir = ['tmpProcess']
        cmd = sys.executable + ' ' + at + ' -f ' + path

    else:
        return False

    Basic.changeDirectory(workDir)  # create and/or change working directory
    #Basic.removeFiles('.')             # ... and empty it

    os.system(cmd)
    return True
Пример #10
0
def run_parallel(options, pwdDict):

    if options.station:  # Client part
        if not init(True): return False

        clt = WaveformClient(options, pwdDict)
        clt.run()
        return True

    else:  # Server part
        if not init(False): return False

        keyfileDir = os.path.join(Globals.EventDir(), options.keyfolder)

        if not Basic.checkExistsDir(keyfileDir):
            return False  # Cannot find directory

        #   Build station list
        #
        stationList = sorted(initWaitingList(options))

        if len(stationList) == 0:
            return Logfile.error('No stations found')

        #
        if not KeyFile.checkVersion(keyfileDir, fullName=stationList[0]):
            return False

        saveUrl(' ', None)  # init debug service
        network = options.network

        mask = KeyFile.getIrisMask(None, stations=stationList)
        irisList = Basic.selectStrings(stationList, mask)
        geofonList = Basic.selectStrings(stationList, Basic.Not(mask))

        if not network or network == 'iris':
            if not startIrisServer(irisList):
                return True  # aborted with ctrl c
        #endif

        if not network or network == 'geofon':
            if not startGeofonServer(geofonList):
                return True  # aborted with ctrl c
    #endif

        if network and network != 'iris' and network != 'geofon':
            if not KeyFile.isNetwork(network):
                return Logfile.error(
                    'Illegal network name <' + network + '>',
                    'Network not found in directory ' +
                    Globals.KeyfileFolder())

            list2 = DataTypes.selectNetwork(irisList,
                                            network)  # search in iris list

            if len(list2) > 0:
                startIrisServer(list2)
                return True

            list2 = DataTypes.selectNetwork(geofonList,
                                            network)  # search in geofon list

            if len(list2) > 0:
                startGeofonServer(list2)
                return True