aboutsummaryrefslogtreecommitdiffstats
path: root/finalstore.py
diff options
context:
space:
mode:
Diffstat (limited to 'finalstore.py')
-rwxr-xr-xfinalstore.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/finalstore.py b/finalstore.py
new file mode 100755
index 0000000..40e5bf4
--- /dev/null
+++ b/finalstore.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python -Wall
+# This is only run from launchd
+# @author Filipp Lepalaan <filipp@tvtools.fi>
+# @updated 10.12.2009
+# @created 09.12.2009
+
+import sys, time, os, glob, traceback
+from config import *
+from subprocess import *
+
+"""
+ Time saver for posting Growl notifications
+"""
+def growl(str):
+ icon = sys.path[0] + "/fcs.png"
+ cmd = ["/usr/local/bin/growlnotify", "-s", "-m", str, "--image", icon]
+ try:
+ Popen(cmd, shell=False).communicate()
+ except Exception, e:
+ print "Growl failed"
+
+
+"""
+ Forward the files to awcli
+ Wait for presstore to finish
+"""
+def doit(task, f, ap):
+ assets = []
+ # Gather up all the assets marked for processing
+ for l in f.readlines():
+ s = l.strip()
+ print "Processing " + l
+ if not s: break
+ assets.append(s)
+
+ # Get rid of these as soon as possible
+ f.close()
+ os.unlink(f.name)
+
+ awcli = sys.path[0] + "/awcli.sh"
+ r = Popen([awcli, task, ap] + assets, stdout=PIPE, shell=False).communicate()
+ jid = r[0].strip()
+
+ print task + " job ID is " + jid
+ growl("Started %s job %s (%d assets)" % (task, jid, len(assets)))
+
+ # Wait for the job to finish
+ sock = "awsock:/%s:%s@%s:9001" % (USER, PASSWORD, HOST)
+ cmd = "Job %s status" % (jid)
+
+ while True:
+ try:
+ check = Popen([NC, "-s", sock , "-c", cmd], stdout=PIPE, shell=False)
+ s = check.communicate()[0].strip()
+ except Exception, e:
+ print traceback.print_exc(file=sys.stdout)
+ if s == "completed" or s == "cancelled" : break
+ time.sleep(2)
+
+ growl("%s %s job %s" % (s.capitalize(), task, jid))
+
+# DO IT
+try:
+ for f in glob.glob("/tmp/finalstore/archive/*.txt"):
+ d = open(f, "r")
+ doit("archive", d, ARCHIVEPLAN)
+except Exception, e:
+ print "Nothing to archive"
+
+try:
+ for f in glob.glob("/tmp/finalstore/restore/*.txt"):
+ d = open(f, "r")
+ doit("restore", d, ARCHIVEPLAN)
+except Exception, e:
+ print "Nothing ro restore"
+
+# To not upset launchd
+time.sleep(5)
+sys.exit(0)