예제 #1
0
    def test_10_network_comment(self):
        tabString = '''
Nw: NN 2020/092
Na: Region=Atlantis
Na: Comment="This is commentary"
Na: Remark="Remarkable!"
Sl: AA01  "Zeus"  Q330/N%xxxx  STS-2/N%yyyy  20  Z  30 -15  -2  2.0 2020/093
'''
        tabFile = self._writeTempTab(tabString)
        t = Tab(None, None, 'filters', None, None)
        t.digest(tabFile)
        t.digest(self.instFile)
        t.check()
        os.unlink(tabFile)

        sc3inv = t.sc3Obj()
        self.assertTrue(sc3inv)
        outFile = '/tmp/testTabInvComment.xml'
        self._writeNewInvXML(sc3inv, '/tmp/testTabInvComment.xml')
        self.assertTrue(os.path.exists(outFile))

        # Further checks: that the file contains a network with PID. TODO
        (elem, ns) = xmlparse(outFile)
        for e in elem:
            for f in e:
                if f.tag == ns + 'network':
                    g = f.findall(ns + 'comment')
                    self.assertTrue(len(g) == 1)
예제 #2
0
    def test_6_network_pid(self):
        '''Key 'Pid' is an allowed network attribute'''
        tabString = '''
Nw: QQ 2001/001
Na: Region=Atlantis
Na: Pid=10.123/xyz
'''
        tabFile = self._writeTempTab(tabString)

        t = Tab(None, None, '.', None, None)
        t.digest(tabFile)
        os.unlink(tabFile)
예제 #3
0
    def SKIPtest_3_digest_check(self):
        tabFile = self._writeTempTab(self.simpleTab)

        t = Tab(None, None, 'filters', None, None)
        t.digest(tabFile)
        t.digest(self.instFile)
        t.check()
        os.unlink(tabFile)
예제 #4
0
    def test_9_network_pid_sc3Obj(self):
        '''Load a network with PID, write XML, confirm PID is there.
        Older nettabs reported 'ignoring attribute Pid'.
        '''
        tabFile = self._writeTempTab(self.tabWithPid)

        t = Tab(None, None, 'filters', None, None)
        t.digest(tabFile)
        t.digest(self.instFile)
        sc3inv = t.sc3Obj()
        self.assertTrue(sc3inv)

        outFile = '/tmp/testTabInvPid.xml'
        self._writeNewInvXML(sc3inv, outFile)
        self.assertTrue(os.path.exists(outFile))

        # Check that the file contains exactly one network comment
        # which is a JSON string with PID.
        # e.g. '{"type": "DOI", "value": "10.1234/xsdfa"}'
        (elem, ns) = xmlparse(outFile)
        for e in elem:
            for f in e:
                if f.tag == ns + 'network':
                    g = f.findall(ns + 'comment')
                    self.assertTrue(len(g) == 1)
                    t = g[0].findall(ns + 'text')
                    text = t[0].text
                    j = json.loads(t[0].text)
                    self.assertEqual(j['type'], 'DOI')
                    self.assertEqual(j['value'], '10.1234/xyz')
예제 #5
0
    def test_2_defaults_warning(self):
        '''Provide and load a defaults file'''
        defaults = tempfile.NamedTemporaryFile(delete=False)
        print('''
Nw: QQ 2001/001
        ''', file=defaults)
        defaultsFile = defaults.name
        defaults.close()
        t = Tab(None, defaultsFile, '.', None, None)
        os.unlink(defaultsFile)
        print("Expect: 'Warning: Defaults file can only contain attributes'",
              file=sys.stderr)
예제 #6
0
    def test_2_defaults_attributes(self):
        '''Provide and load a defaults file'''
        defaults = tempfile.NamedTemporaryFile(delete=False)
        print('''
Na: Foo=bar
Sa: StationFoo=bla * *
Ia: InstrumentFoo=blu *
        ''',
              file=defaults)
        defaultsFile = defaults.name
        defaults.close()
        t = Tab(None, defaultsFile, '.', None, None)
        os.unlink(defaultsFile)
예제 #7
0
    def test_4_digest_twice(self):
        '''Exception is raised by digesting twice.'''
        tabFile = self._writeTempTab(self.simpleTab)

        t = Tab(None, None, '.', None, None)
        t.digest(tabFile)
        with self.assertRaises(Exception):
            t.digest(tabFile)
        # print('Expect: "Warning: File {name}  is already digested."')

        os.unlink(tabFile)
예제 #8
0
    def test_6_network_pid_check(self):
        '''No problem to define extra unhandled attributes'''
        tabString = '''
Nw: QQ 2001/001
Na: Region=Atlantis
Na: Pid=10.123/xyz
Na: Foo=bar
'''
        tabFile = self._writeTempTab(tabString)

        t = Tab(None, None, '.', None, None)
        t.digest(tabFile)
        t.check()
        os.unlink(tabFile)
예제 #9
0
    def test_8_network_sc3Obj(self):
        '''Call sc3Obj with an actual network, write XML'''
        tabFile = self._writeTempTab(self.simpleTab)

        t = Tab(None, None, 'filters', None, None)
        t.digest(tabFile)
        t.digest(self.instFile)
        sc3inv = t.sc3Obj()
        # Returns ok, but reports inst.db errors and warnings to stdout.
        self.assertTrue(sc3inv)
        if sc3inv is None:
            assert ('scinv is None')
        sc3inv
        outFile = '/tmp/testTabInv.xml'

        try:
            os.unlink(outFile)
        except OSError:  # Python3: Catch FileNotFoundError instead.
            pass

        self._writeInvXML(sc3inv, filename=outFile)
        self.assertTrue(os.path.exists(outFile))
예제 #10
0
파일: tab2inv.py 프로젝트: salichon/extras
def main():
    # Creating the parser
    parser = OptionParser(usage="Tab to Inventory (sc3) converter",
                          version="1.0",
                          add_help_option=True)

    parser.add_option("-i",
                      "--ip",
                      type="string",
                      help="Prefix to be added to each instrument generated.",
                      dest="instrumentPrefix",
                      default=None)

    parser.add_option(
        "-f",
        "--filterf",
        type="string",
        help="Indicates a folder containing the filters coefficients files",
        dest="ffolder",
        default=None)

    parser.add_option(
        "-x",
        "--xmlf",
        type="string",
        help=
        "Indicates a folder containing the XML inventory files (needed for station group support)",
        dest="xfolder",
        default=None)

    parser.add_option(
        "-D",
        "--database",
        type="string",
        help="Database URL for inventory (needed for station group support)",
        dest="database",
        default=None)

    parser.add_option("",
                      "--force",
                      action="store_true",
                      help="Don't stop on error of individual files",
                      dest="force",
                      default=False)

    parser.add_option("-g",
                      "--generate",
                      action="store_true",
                      help="Generate XML file at the end",
                      dest="generate",
                      default=False)

    parser.add_option("-c",
                      "--check",
                      action="store_true",
                      help="Check the loaded files",
                      dest="check",
                      default=False)

    parser.add_option("-d",
                      "--default",
                      type="string",
                      help="Indicates the default file",
                      dest="defaultFile",
                      default=None)

    parser.add_option("-o",
                      "--output",
                      type="string",
                      help="Indicates the output file",
                      dest="outFile",
                      default="-")

    # Parsing & Error check
    (options, args) = parser.parse_args()
    error = False

    if len(args) < 1:
        print("No input file(s) to digest", file=sys.stderr)
        error = True

    if error:
        print("Use -h for help on usage", file=sys.stderr)
        return 1

    # Execution
    try:
        inv = None
        t = Tab(options.instrumentPrefix, options.defaultFile, options.ffolder,
                options.xfolder, options.database)
        for f in args:
            try:
                t.digest(f)
            except Exception as e:
                print("Error digesting %s:\n %s" % (f, e), file=sys.stderr)
                if not options.force:
                    raise e

        if options.check:
            t.check()
            return

        if options.generate:
            inv = t.sc3Obj()
            if inv:
                ar = seiscomp.io.XMLArchive()
                print("Generating file: %s" % options.outFile, file=sys.stderr)
                ar.create(options.outFile)
                ar.setFormattedOutput(True)
                ar.setCompression(False)
                ar.writeObject(inv)
                ar.close()
    except Exception as e:
        print("Error: " + str(e), file=sys.stderr)
        return 1
    finally:
        print("Ending.", file=sys.stderr)

    return 0
예제 #11
0
파일: tab2inv.py 프로젝트: Fran89/seiscomp3
def main():
	# Creating the parser
	parser = OptionParser(usage="Tab to Inventory (sc3) converter", version="1.0", add_help_option=True)

	parser.add_option("-i", "--ip", type="string",
					  help="Prefix to be added to each instrument generated.", dest="instrumentPrefix", default=None)

	parser.add_option("-f", "--filterf", type="string",
					  help="Indicates a folder containing the filters coefficients files", dest="ffolder", default=None)

	parser.add_option("-x", "--xmlf", type="string",
					  help="Indicates a folder containing the XML inventory files (needed for station group support)", dest="xfolder", default=None)

	parser.add_option("-D", "--database", type="string",
					  help="Database URL for inventory (needed for station group support)", dest="database", default=None)

	parser.add_option("", "--force", action="store_true",
					help="Don't stop on error of individual files", dest="force", default=False)
	
	parser.add_option("-g", "--generate", action="store_true",
					help="Generate XML file at the end", dest="generate", default=False)

	parser.add_option("-c", "--check", action="store_true",
					help="Check the loaded files", dest="check", default=False)

	parser.add_option("-d", "--default", type="string",
					help="Indicates the default file", dest="defaultFile", default=None)

	parser.add_option("-o", "--output", type="string",
					help="Indicates the output file", dest="outFile", default="-")

	# Parsing & Error check
	(options, args) = parser.parse_args()
	error = False
	
	if len(args) < 1:
		print >> sys.stderr, "No input file(s) to digest"
		error = True
	
	if error:
		print >> sys.stderr, "Use -h for help on usage"
		return 1

	# Execution
	try:
		inv = None
		t=Tab(options.instrumentPrefix, options.defaultFile, options.ffolder, options.xfolder, options.database)
		for f in args:
			try:
				t.digest(f)
			except Exception,e:
				print >> sys.stderr, "Error digesting %s:\n %s" % (f, e)
				if not options.force:
					raise e

		if options.check:
			t.check()
			return
		
		if options.generate:
			inv = t.sc3Obj()
			if inv:
				ar = IO.XMLArchive()
				print >> sys.stderr, "Generating file: %s" % options.outFile
				ar.create(options.outFile)
				ar.setFormattedOutput(True)
				ar.setCompression(False)
				ar.writeObject(inv)
				ar.close()
예제 #12
0
 def loadInstrumentsFile(self, filename, filterFolder):
     tab = Tab(filterFolder=filterFolder)
     tab.digest(filename)
     if tab.i:
         self.inst = tab.i
예제 #13
0
 def test_2_filter(self):
     '''Provide a (trivial, non-useful) filter folder'''
     t = Tab(None, None, '.', None, None)
예제 #14
0
 def test_1(self):
     '''Create object'''
     t = Tab()
     print('Expect: "Warning, not filter folder supplied."',
           file=sys.stderr)
예제 #15
0
 def test_7_sc3Obj(self):
     '''Call sc3Obj with a trivial t'''
     t = Tab(None, None, '.', None, None)
     sc3inv = t.sc3Obj()
예제 #16
0
    def test_3_digest(self):
        tabFile = self._writeTempTab(self.simpleTab)

        t = Tab(None, None, '.', None, None)
        t.digest(tabFile)
        os.unlink(tabFile)