예제 #1
0
def main():
    if len(sys.argv) < 1 or len(sys.argv) > 3:
        print "Usage inv2dlsv [in_xml [out_dataless]]"
        return 1

    if len(sys.argv) > 1:
        inFile = sys.argv[1]
    else:
        inFile = "-"

    if len(sys.argv) > 2:
        out = sys.argv[2]
    else:
        out = ""

    sc3wrap.dbQuery = None

    ar = IO.XMLArchive()
    if ar.open(inFile) == False:
        raise IOError, inFile + ": unable to open"

    obj = ar.readObject()
    if obj is None:
        raise TypeError, inFile + ": invalid format"

    sc3inv = DataModel.Inventory.Cast(obj)
    if sc3inv is None:
        raise TypeError, inFile + ": invalid format"

    inv = Inventory(sc3inv)
    inv.load_stations("*", "*", "*", "*")
    inv.load_instruments()

    vol = SEEDVolume(inv, ORGANIZATION, "", resp_dict=False)

    for net in iterinv(inv.network):
        for sta in iterinv(net.station):
            for loc in iterinv(sta.sensorLocation):
                for strm in iterinv(loc.stream):
                    try:
                        vol.add_chan(net.code, sta.code, loc.code, strm.code, strm.start, strm.end)

                    except SEEDError, e:
                        print >> sys.stderr, "Error (%s,%s,%s,%s):" % (net.code, sta.code, loc.code, strm.code), str(e)
예제 #2
0
    def run(self):
        try:
            logs.info("ArcLink request handler v" + VERSION + " started")
            logs.info("Configuration: ")
            logs.info("Request handler for %s (organization) at %s (Datacenter Id)" % (self.organization, self.dcid))
            logs.info("Request Dir: %s" % self.reqdir)
            logs.info("Max request size: %s" % self.maxsize)
            logs.info("Archive Dir: %s" % self.archdir)
            logs.info("ISO Dir: %s" % self.isodir)
            logs.info("NRT Dir: %s" % self.nrtdir)
            logs.info("Trackdb is %s @ %s" % (self.trackdb, self.trackdir))
            logs.info("Subnodelist: %s" % self.subnodelist)
            logs.info("File Database: %s" % self.filedb)

            subnode_addr = {}
            dcid_override = {}
            if self.subnodelist is not None:
                fd = open(self.subnodelist)
                line = fd.readline()
                while line:
                    try:
                        (dcid, addr) = line.split()
                        subnode_addr[dcid] = addr
                    
                    except ValueError:
                        (dcid, addr, net, sta) = line.split()
                        subnode_addr[dcid] = addr
                        dcid_override[(net,sta)] = dcid

                    line = fd.readline()

                fd.close()

            sc3wrap.dbQuery = self.query()
            handler.sc3App = self

            inv = Inventory(self.query().loadInventory())
            rtn = Routing(self.query().loadRouting())

            wf = WiggleFetcher(self.nrtdir, self.archdir, self.isodir, self.filedb,
                1024*1024*self.maxsize, self.dcid, subnode_addr, dcid_override)

            rh = RequestHandler(inv, rtn, wf, self.reqdir, (self.trackdir, self.trackdb),
                5, self.organization, DEFAULT_LABEL)

            mt = MessageThread(self.connection(), rh)
            mt.start()
            rh.start()

        except Exception:
            logs.print_exc()
            return False

        return True
예제 #3
0
def main():
    if len(sys.argv) < 1 or len(sys.argv) > 3:
        sys.stderr.write("Usage inv2dlsv [in_xml [out_dataless]]\n")
        return 1

    if len(sys.argv) > 1:
        inFile = sys.argv[1]
    else:
        inFile = "-"

    if len(sys.argv) > 2:
        out = sys.argv[2]
    else:
        out = ""

    sc3wrap.dbQuery = None

    ar = IO.XMLArchive()
    if ar.open(inFile) == False:
        raise IOError(inFile + ": unable to open")

    obj = ar.readObject()
    if obj is None:
        raise TypeError(inFile + ": invalid format")

    sc3inv = DataModel.Inventory.Cast(obj)
    if sc3inv is None:
        raise TypeError(inFile + ": invalid format")

    inv = Inventory(sc3inv)
    inv.load_stations("*", "*", "*", "*")
    inv.load_instruments()

    vol = SEEDVolume(inv, ORGANIZATION, "", resp_dict=False)

    for net in iterinv(inv.network):
        for sta in iterinv(net.station):
            for loc in iterinv(sta.sensorLocation):
                for strm in iterinv(loc.stream):
                    try:
                        vol.add_chan(net.code, sta.code, loc.code,
                                     strm.code, strm.start, strm.end)

                    except SEEDError as e:
                        sys.stderr.write("Error (%s,%s,%s,%s): %s\n" % (
                            net.code, sta.code, loc.code, strm.code, str(e)))

    if not out or out == "-":
        output = io.BytesIO()
        vol.output(output)
        stdout = sys.stdout.buffer if hasattr(sys.stdout, "buffer") else sys.stdout
        stdout.write(output.getvalue())
        stdout.flush()
        output.close()
    else:
        with open(sys.argv[2], "wb") as fd:
            vol.output(fd)

    return 0
예제 #4
0
    def __init__(self, inventory, DCID):
        self.obj = inventory
        self.inv = Inventory(inventory)
        self.DCID = DCID
        self.networks = {}
        self.stations = {}

        for i in xrange(inventory.networkCount()):
            network = inventory.network(i)
            self.networks[network.code()] = NetworkWrapper(network)

            for j in xrange(network.stationCount()):
                station = network.station(j)
                self.stations[(network.code(), station.code())] = StationWrapper(network.code(), station)
예제 #5
0
def main():
    if len(sys.argv) < 1 or len(sys.argv) > 3:
        print "Usage inv2dlsv [in_xml [out_dataless]]"
        return 1

    if len(sys.argv) > 1:
        inFile = sys.argv[1]
    else:
        inFile = "-"

    if len(sys.argv) > 2:
        out = sys.argv[2]
    else:
        out = ""

    sc3wrap.dbQuery = None

    ar = IO.XMLArchive()
    if ar.open(inFile) == False:
        raise IOError, inFile + ": unable to open"

    obj = ar.readObject()
    if obj is None:
        raise TypeError, inFile + ": invalid format"

    sc3inv = DataModel.Inventory.Cast(obj)
    if sc3inv is None:
        raise TypeError, inFile + ": invalid format"

    inv = Inventory(sc3inv)
    inv.load_stations("*", "*", "*", "*")
    inv.load_instruments()

    vol = SEEDVolume(inv, ORGANIZATION, "", resp_dict=False)

    for net in sum([i.values() for i in inv.network.itervalues()], []):
        for sta in sum([i.values() for i in net.station.itervalues()], []):
            for loc in sum(
                [i.values() for i in sta.sensorLocation.itervalues()], []):
                for strm in sum([i.values() for i in loc.stream.itervalues()],
                                []):
                    try:
                        vol.add_chan(net.code, sta.code, loc.code, strm.code,
                                     strm.start, strm.end)

                    except SEEDError, e:
                        print >> sys.stderr, "Error (%s,%s,%s,%s):" % (
                            net.code, sta.code, loc.code, strm.code), str(e)