root/autopilot/trunk/autopilot/list_gliders.py

Revision 68 (checked in by cbc, 12 years ago)

File locking and task prioritization implemented.

Line 
1 """
2 List gliders in configuration file.
3
4     Usage:
5
6         python list_gliders.py path/to/config/file
7 """
8
9 import sys
10 import errno
11 import lockfile as lf
12 import ConfigParser as cp
13
14 if __name__ == "__main__":
15     num_args = len(sys.argv) - 1
16     if num_args != 1:
17         print __doc__
18     else:
19         cfg_path = sys.argv[1]
20         try:
21             lock = lf.FileLock(cfg_path)
22             lock.acquire(5)
23         except lf.LockTimeout:
24             lock.break_lock()
25             lock.acquire(0)
26         config = cp.SafeConfigParser()
27         try:
28             with open(cfg_path) as handle:
29                 config.readfp(handle)
30         except IOError as e:
31             if e.errno == errno.ENOENT:
32                 print "There are no gliders at this time in {0}.". \
33                       format(cfg_path)
34             else:
35                 raise
36         else:
37             gliders = config.sections()
38             if gliders:
39                 print "\n".join(gliders)
40             else:
41                 print "There are no gliders at this time in {0}.". \
42                       format(cfg_path)
43         finally:
44             lock.release()
Note: See TracBrowser for help on using the browser.