Skip to content
Snippets Groups Projects
Commit 33226f44 authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #2669: Allow generating obs ids from the command line

parent 6d7b3f66
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
from util.Hosts import ropen from util.Hosts import ropen
from Locations import Locations
# do not modify any files if DRYRUN is True # do not modify any files if DRYRUN is True
DRYRUN = False DRYRUN = False
...@@ -10,16 +9,13 @@ DRYRUN = False ...@@ -10,16 +9,13 @@ DRYRUN = False
The following files exist to aid the creation of observation IDs: The following files exist to aid the creation of observation IDs:
nextMSnumber contains the next free observation ID (integer) nextMSnumber contains the next free observation ID (integer)
MSList contains a list of existing measurements and their start time [deprecated: not updated anymore]
Their locations are stored in the Locations dictionary.
""" """
class ObservationID: class ObservationID:
def __init__( self ): def __init__( self ):
self.obsid = 0 self.obsid = 0
def generateID( self ): def generateID( self, nextMSnumber = "/globalhome/lofarsystem/log/nextMSNumber" ):
""" Returns an unique observation ID to use and reserve it. """ """ Returns an unique observation ID to use and reserve it. """
if self.obsid: if self.obsid:
...@@ -27,16 +23,21 @@ class ObservationID: ...@@ -27,16 +23,21 @@ class ObservationID:
return self.obsid return self.obsid
# read the next ms number # read the next ms number
f = ropen( Locations.files["nextmsnumber"], "r" ) f = ropen( nextMSnumber, "r" )
obsid = int(f.readline()) obsid = int(f.readline())
f.close() f.close()
if not DRYRUN: if not DRYRUN:
# increment it and save # increment it and save
f = ropen( Locations.files["nextmsnumber"], "w" ) f = ropen( nextMSnumber, "w" )
print >>f, "%s" % (obsid+1) print >>f, "%s" % (obsid+1)
f.close() f.close()
self.obsid = obsid self.obsid = obsid
return self.obsid return self.obsid
if __name__ == "__main__":
obsID = ObservationID()
print obsID.generateID()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment