Exemple #1
0
 def test_Version_repr(self):
     """__repr__ should have a known output"""
     invals = (Version.Version(1, 0, 1), Version.Version(5, 0, 1),
               Version.Version(1, 3, 1))
     answers = ('1.0.1', '5.0.1', '1.3.1')
     for i, val in enumerate(invals):
         self.assertEqual(answers[i], str(val))
 def test_extract_Version(self):
     """extract_Version works"""
     self.assertEqual(Version.Version(1,0,0), inspector.extract_Version('rbspa_pre_ect-hope-L1_20130231_v1.0.0.cdf'))
     self.assertEqual(Version.Version(1,0,0), inspector.extract_Version('rbspa_pre_ect-hope-L1_20130202_v1.0.0.cdf'))
     self.assertEqual(Version.Version(1,10,0), inspector.extract_Version('rbspa_pre_ect-hope-L1_20130202_v1.10.0.cdf'))
     self.assertEqual((Version.Version(1,10,0), 'rbspa_pre_ect-hope-L1_20130202_'), inspector.extract_Version('rbspa_pre_ect-hope-L1_20130202_v1.10.0.cdf', basename=True))
     self.assertEqual(None, inspector.extract_Version('rbspa_pre_ect-hope-L1_20130202_v1.f.0.cdf'))
     self.assertEqual(None, inspector.extract_Version('rbspa_pre_ect-hope-L1_20130202_v1.0.cdf'))
     self.assertEqual(None, inspector.extract_Version('rbspa_pre_ect-hope-L1_20130202_v1.0.cdf', basename=True))
Exemple #3
0
 def test_Version_inc(self):
     """The versions should increment"""
     ver = Version.Version(1, 0, 0)
     ver.incRevision()
     self.assertEqual(Version.Version(1, 0, 1), ver)
     ver.incQuality()
     self.assertEqual(Version.Version(1, 1, 0), ver)
     ver.incInterface()
     self.assertEqual(Version.Version(2, 0, 0), ver)
Exemple #4
0
 def test_Version_gt(self):
     """__gt__ should work"""
     invals = ((Version.Version(1, 0, 0), Version.Version(1, 0, 0)),
               (Version.Version(1, 2, 0), Version.Version(1, 0, 0)),
               (Version.Version(1, 0, 4), Version.Version(1, 0, 0)),
               (Version.Version(4, 2, 1), Version.Version(1, 0, 99)))
     real_ans = (False, True, True, True)
     for i, val in enumerate(invals):
         self.assertEqual(real_ans[i], val[0] > val[1])
Exemple #5
0
	def inspect(self, kwargs):
		m = re.match(r'testDB_(\d{3}).*\.raw$', self.basename)
		if not m:
			return None

		self.diskfile.params['utc_start_time'] = datetime.datetime(2016, 1, 1) + datetime.timedelta(days=int(m.group(1)))
		self.diskfile.params['utc_stop_time'] = self.diskfile.params['utc_start_time'] + datetime.timedelta(days=1)
		self.diskfile.params['utc_file_date'] = self.diskfile.params['utc_start_time'].date()
		self.diskfile.params['version'] = Version.Version(1, 0, 0)
		self.diskfile.params['process_keywords'] = 'nnn=' + m.group(1)
		return True
	def inspect(self, kwargs):
		m = re.match(r'testDB_((19|20)\d\d-\d\d-\d\d)\.cat$', self.basename)
		if not m:
			return None

		self.diskfile.params['utc_start_time'] = datetime.datetime.strptime(m.group(1), '%Y-%m-%d')
		self.diskfile.params['utc_stop_time'] = self.diskfile.params['utc_start_time'] + datetime.timedelta(days=1)
		self.diskfile.params['utc_file_date'] = self.diskfile.params['utc_start_time'].date()
		self.diskfile.params['version'] = Version.Version(1, 0, 0)
		self.diskfile.params['process_keywords'] = 'nnn=' + m.group(1)
		return True
    def createDummyDBF(self, fname):
        dbf = DBfile.DBfile(self.tempD + fname, self.dbu, makeDiskFile=True)
        dbf.diskfile.params['utc_file_date'] = datetime.date.today()
        dbf.diskfile.params['utc_start_time'] = datetime.date.today()
        dbf.diskfile.params['utc_stop_time'] = datetime.date.today(
        ) + datetime.timedelta(days=1)
        dbf.diskfile.params['data_level'] = 0
        dbf.diskfile.params['file_create_date'] = datetime.date.today()
        dbf.diskfile.params['exists_on_disk'] = 1
        dbf.diskfile.params['product_id'] = 1
        dbf.diskfile.params['shasum'] = Diskfile.calcDigest(self.tempD + fname)
        dbf.diskfile.params['version'] = Version.Version(1, 2, 3)

        return dbf
Exemple #8
0
def build_graph(dbu):
    """Loads the file records and their parent-child relationships into a networkX graph

    Arguments:
        dbu {DButils} -- The DButils instance for the mission

    Returns:
        networkx.Graph -- A Graph of file records and their parent-child relationships
    """

    G = networkx.DiGraph()
    # This way is WAY slower, by about 3x - Myles 5/29/18
    # G.add_nodes_from([(f.file_id, f)
    #                   for f in dbu.session.query(dbu.File).all()])
    G.add_nodes_from([
        (
            i,
            {
                'file_id': i,
                'filename': a,
                'in_release': False,  #Assume false, correct below
                'newest': False,  #Assume false, correct below
                'product_id': b,
                'utc_file_date': c,
                'exists_on_disk': d,
                'version': Version.Version(e, f, g)
            })
        for i, a, b, c, d, e, f, g in dbu.session.query(
            dbu.File.file_id, dbu.File.filename, dbu.File.product_id, dbu.File.
            utc_file_date, dbu.File.exists_on_disk, dbu.File.interface_version,
            dbu.File.quality_version, dbu.File.revision_version).all()
    ])

    for f in dbu.getFiles(newest_version=True):
        G.node[f.file_id]['newest'] = True
    for f in dbu.session.query(dbu.Release.file_id):
        G.node[f[0]]['in_release'] = True

    G.add_edges_from(
        dbu.session.query(dbu.Filefilelink.source_file,
                          dbu.Filefilelink.resulting_file).all())
    return G
    try:
        code_id = int(args[0])
    except ValueError:
        parser.error("Invalid code_id: {0}, must be an int".format(args[0]))

    newname = args[2]
    
    dbu = DButils.DButils(os.path.expanduser(options.mission))

    try:
        code = dbu.getEntry('Code', code_id)
    except DButils.DBNoData:
        parser.error("Invalid code_id: {0}, must be in the database".format(code_id))

    old_version = Version.Version(code.interface_version, code.quality_version, code.revision_version)
    if version <= old_version:
        parser.error("New version, {0}, must be larger than old version {1}".format(version,old_version ))
    

    # make a new code and copy across the needed keys
    attrs = [ u'active_code',
              u'arguments',
              u'code_description',
              # u'code_id',
              u'code_start_date',
              u'code_stop_date',
              u'cpu',
              u'date_written',
              # u'filename',
              #u'interface_version',
Exemple #10
0
 def test_dirSubs(self):
     """dirSubs substitutions should work"""
     path = '{Y}{m}{d}'
     filename = 'test_filename'
     utc_file_date = datetime.date(2012, 4, 12)
     utc_start_time = datetime.datetime(2012, 4, 12, 1, 2, 3)
     version = '1.2.3'
     version2 = Version.Version(3, 2, 1)
     self.assertEqual(
         '20120412',
         Utils.dirSubs(path, filename, utc_file_date, utc_start_time,
                       version))
     path = '{DATE}'
     self.assertEqual(
         '20120412',
         Utils.dirSubs(path, filename, utc_file_date, utc_start_time,
                       version))
     path = '{Y}{b}{d}'
     self.assertEqual(
         '2012Apr12',
         Utils.dirSubs(path, filename, utc_file_date, utc_start_time,
                       version))
     path = '{y}{j}'
     self.assertEqual(
         '12103',
         Utils.dirSubs(path, filename, utc_file_date, utc_start_time,
                       version))
     path = '{VERSION}'
     self.assertEqual(
         '1.2.3',
         Utils.dirSubs(path, filename, utc_file_date, utc_start_time,
                       version))
     self.assertEqual(
         '3.2.1',
         Utils.dirSubs(path, filename, utc_file_date, utc_start_time,
                       version2))
     path = '{H}{M}{S}'
     self.assertEqual(
         '010203',
         Utils.dirSubs(path, filename, utc_file_date, utc_start_time,
                       version))
     # Substitutions that require referring to the DB...
     filename = 'testDB_000_000.raw'
     path = '{INSTRUMENT}'
     self.assertEqual(
         'rot13',
         Utils.dirSubs(path,
                       filename,
                       utc_file_date,
                       utc_start_time,
                       version,
                       dbu=self.dbu))
     path = '{SATELLITE}'
     self.assertEqual(
         'testDB-a',
         Utils.dirSubs(path,
                       filename,
                       utc_file_date,
                       utc_start_time,
                       version,
                       dbu=self.dbu))
     path = '{SPACECRAFT}'
     self.assertEqual(
         'testDB-a',
         Utils.dirSubs(path,
                       filename,
                       utc_file_date,
                       utc_start_time,
                       version,
                       dbu=self.dbu))
     path = '{MISSION}'
     self.assertEqual(
         'testDB',
         Utils.dirSubs(path,
                       filename,
                       utc_file_date,
                       utc_start_time,
                       version,
                       dbu=self.dbu))
     path = '{PRODUCT}'
     self.assertEqual(
         'testDB_rot13_L0_first',
         Utils.dirSubs(path,
                       filename,
                       utc_file_date,
                       utc_start_time,
                       version,
                       dbu=self.dbu))
     # Verify that unknown values are ignored
     path = '{xxx}'
     self.assertEqual(
         '{xxx}',
         Utils.dirSubs(path,
                       filename,
                       utc_file_date,
                       utc_start_time,
                       version,
                       dbu=self.dbu))
Exemple #11
0
 def test_parseVersion(self):
     """parseVersion"""
     self.assertEqual(Version.Version(1, 2, 3), Utils.parseVersion('1.2.3'))
     self.assertRaises(TypeError, Utils.parseVersion, '1.2')
Exemple #12
0
                if not val: val = str(None)
                out.set(pname, 'code_' + d2, val)
            else:
                out.set(pname, d2, str(getattr(p['code'], d2)))

    # loop over everything and delete individual versions making one
    for sec in out.sections():
        interface_version = None
        quality_version = None
        revision_version = None
        name = None
        for opt in out.options(sec):
            if 'interface_version' in opt:
                interface_version = out.get(sec, opt)
                out.remove_option(sec, opt)
                name = opt.split('_interface_version')[0]
            elif 'quality_version' in opt:
                quality_version = out.get(sec, opt)
                out.remove_option(sec, opt)
            elif 'revision_version' in opt:
                revision_version = out.get(sec, opt)
                out.remove_option(sec, opt)
        if interface_version is not None:
            out.set(sec, name + '_version', str(Version.Version(interface_version, quality_version, revision_version)))

    # write out the conf file
    with open(filename, 'wb') as configfile:
        if not options.nocomments:
            configfile.writelines(header_comments)
        out.write(configfile)
                 dbu.getEntry('Code', c).filename, sd.isoformat(),
                 ed.isoformat()))
 elif field == 'Code':
     print(
         "{0:4} {1:40} {2:10} ({3})   {4:40}  {5} {6:40}   {7}-{8}  {9}  {10} {11:10} -> {12:10}"
         .format('id', 'filename', 'version', 'outV', 'path', 'p_id',
                 'process', 'A', 'N', 'ram', 'cpu', 'start', 'stop'))
     codes = dbu.getAllCodes()
     codes = [c['code'] for c in codes]
     codes = sorted(codes, key=lambda x: x.code_id)
     for c in codes:
         ans = {}
         ans['code_id'] = c.code_id
         ans['filename'] = c.filename
         ans['version'] = Version.Version(c.interface_version,
                                          c.quality_version,
                                          c.revision_version)
         ans['path'] = os.path.join(basepath, c.relative_path)
         ans['process_id'] = c.process_id
         ans['process_name'] = dbu.getEntry('Process',
                                            ans['process_id']).process_name
         ans['out_version'] = c.output_interface_version
         ans['active_code'] = c.active_code
         ans['newest_version'] = c.newest_version
         ans['args'] = c.arguments
         ans['ram'] = c.ram
         ans['cpu'] = c.cpu
         ans['date'] = c.date_written
         ans['code_start_date'] = c.code_start_date
         ans['code_stop_date'] = c.code_stop_date
         print(
Exemple #14
0
 def test_fromString(self):
     """fromString"""
     self.assertEqual(Version.Version(1, 0, 1),
                      Version.Version.fromString('1.0.1'))
Exemple #15
0
 def test_repr(self):
     """__repr__ has known output"""
     self.assertEqual(Version.Version(1, 0, 1).__repr__(), 'Version: 1.0.1')
Exemple #16
0
 def test_sub(self):
     """__sub__ should give known result"""
     self.assertEqual(
         Version.Version(1, 0, 1) - Version.Version(1, 0, 0), [0, 0, 1])