def test_file_linking(self): te = models.TaskEntry.objects.all()[0] system = models.System.objects.get(name="test_system") data_file = models.DataFile(path="dummy_file_path", system_id=system.id, entry_id=te.id) data_file.save() data_file = models.DataFile.objects.get(path="dummy_file_path") self.assertTrue(data_file.entry_id == te.id) self.assertTrue(data_file.system_id == system.id)
def assoc_plexon2(): rplex = models.Feature.objects.get(name='relay_plexon') rplexb = models.Feature.objects.get(name='relay_plexbyte') for te in models.TaskEntry.objects.filter(feats__in=[rplex, rplexb]): fname = te.plexfile("/storage/plexon2", True) if fname is not None: query = models.DataFile.objects.filter(system=hdf, entry=te) if len(query) == 0: raise Exception('invalid entry, unknown!') newname = os.path.splitext(query[0].path)[0] + '.plx' os.rename(fname, os.path.join("/storage/plexon2", newname)) models.DataFile(system=plex2, entry=te, path=newname).save() print(newname)
def reassoc_20130106(): rplex = models.Feature.objects.get(name='relay_plexon') rplexb = models.Feature.objects.get(name='relay_plexbyte') for te in models.TaskEntry.objects.filter(feats__in=[rplex, rplexb]): plxdata = models.DataFile.objects.filter(system=plexon, entry=te) if len(plxdata) == 0: fname = te.plexfile() hdfdata = models.DataFile.objects.filter(system=hdf, entry=te) if fname is not None and len(hdfdata) == 1: path, ext = os.path.splitext(hdfdata[0].path) newname = os.path.join(plexon.path, path) + ".plx" #os.rename(fname, newname) #models.DataFile(system=plexon, entry=te, path=path+'.plx').save() print(models.DataFile(system=plexon, entry=te, path=newname))
def old(): path = "/storage/plexon/" plxform = re.compile('cart(\d{2})(\d{2})(\d{4})(\d{3}).plx') orphans = [ f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) and plxform.match(f) ] system = models.System.objects.get(name="plexon") for orphan in orphans: mtime = os.stat(os.path.join(path, orphan)).st_mtime day, month, year, num = plxform.match(orphan).groups() entries = models.TaskEntry.objects.filter(date__year=year, date__month=month, date__day=day) etime = dict([ (e, i) for i, e in enumerate(sorted(entries, key=lambda x: x.date)) ]) tdiffs = [(e, abs(mtime - json.loads(e.report)[-1][2])) if e.report != '[]' else e for e in entries] target, tdiff = sorted(tdiffs, key=lambda x: x[1])[0] if tdiff < 60: newname = "cart{time}_{num:02}.plx".format( time=target.date.strftime('%Y%m%d'), num=etime[target] + 1) print("renaming %s to %s" % (os.path.join(path, orphan), os.path.join(path, newname))) df = models.DataFile(local=False, path=newname, system=system, entry=target) os.rename(os.path.join(path, orphan), os.path.join(path, newname)) df.save() print(df)