forked from joshwalawender/Panoptes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonitor.py
More file actions
executable file
·98 lines (81 loc) · 3.55 KB
/
Copy pathMonitor.py
File metadata and controls
executable file
·98 lines (81 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# encoding: utf-8
"""
Monitor.py
Created by Josh Walawender on 2013-07-25.
Copyright (c) 2013 __MyCompanyName__. All rights reserved.
"""
from __future__ import division, print_function
import sys
import os
from argparse import ArgumentParser
import re
import time
import subprocess
help_message = '''
The help message goes here.
'''
def main(argv=None):
##-------------------------------------------------------------------------
## Parse Command Line Arguments
##-------------------------------------------------------------------------
## create a parser object for understanding command-line arguments
parser = ArgumentParser(description="Describe the script")
## add arguments
args = parser.parse_args()
telescope = "Panoptes"
##-------------------------------------------------------------------------
## Set date to tonight
##-------------------------------------------------------------------------
now = time.gmtime()
DateString = time.strftime("%Y-%m-%d", now)
##-------------------------------------------------------------------------
## Set data path
##-------------------------------------------------------------------------
DataPath = os.path.join("/skycamdata", DateString, "CR2")
##-------------------------------------------------------------------------
## Look for Pre-existing Files
##-------------------------------------------------------------------------
if not os.path.exists(DataPath): os.mkdir(DataPath)
PreviousFiles = os.listdir(DataPath)
PreviousFilesTime = time.gmtime()
##-------------------------------------------------------------------------
## Operation Loop
##-------------------------------------------------------------------------
PythonString = os.path.join("/usr/", "bin", "python")
homePath = os.path.expandvars("$HOME")
MeasureImageString = os.path.join(homePath, "bin", "Panoptes", "MeasureImage.py")
Operate = True
while Operate:
## Set date to tonight
now = time.gmtime()
nowDecimalHours = now.tm_hour + now.tm_min/60. + now.tm_sec/3600.
DateString = time.strftime("%Y-%m-%d", now)
TimeString = time.strftime("%Y-%m-%d %H:%M:%S -", now)
Files = os.listdir(DataPath)
FilesTime = now
time.sleep(1)
if len(Files) > len(PreviousFiles):
for File in Files:
FileFound = False
for PreviousFile in PreviousFiles:
if File == PreviousFile:
FileFound = True
if not FileFound:
if re.match("IMG0_\d{4}\.CR2", File):
print("New image File Found: %s" % File)
Focus = False
ProcessCall = [PythonString, MeasureImageString, os.path.join(DataPath, File)]
print(" %s Calling MeasureImage.py with %s" % (TimeString, ProcessCall[2:]))
try:
MIoutput = subprocess.check_output(ProcessCall, stderr=subprocess.STDOUT)
print("Call to MeasureImage.py Succeeded")
except:
print("Call to MeasureImage.py Failed: {0} {1} {2}".format(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))
PreviousFiles = Files
PreviousFilesTime = now
time.sleep(5)
if nowDecimalHours > 18.0:
Operate = False
if __name__ == "__main__":
sys.exit(main())