← Back to team overview

mlhim-specs-dev team mailing list archive

[Branch ~cdd-dev/cdd/trunk] Rev 273: Added error checking, added sentlog with status of each file, corrected XMind file extension.

 

------------------------------------------------------------
revno: 273
committer: Timothy W. Cook <timothywayne.cook@xxxxxxxxx>
branch nick: cdd
timestamp: Sun 2012-09-30 16:24:16 -0300
message:
  Added error checking, added sentlog with status of each file, corrected XMind file extension.
modified:
  src/ccd2hkcr/ccd2hkcr.py


--
lp:cdd
https://code.launchpad.net/~cdd-dev/cdd/trunk

Your team MLHIM Specifications Developers is subscribed to branch lp:cdd.
To unsubscribe from this branch go to https://code.launchpad.net/~cdd-dev/cdd/trunk/+edit-subscription
=== modified file 'src/ccd2hkcr/ccd2hkcr.py'
--- src/ccd2hkcr/ccd2hkcr.py	2012-09-30 10:20:23 +0000
+++ src/ccd2hkcr/ccd2hkcr.py	2012-09-30 19:24:16 +0000
@@ -4,17 +4,22 @@
 Uploads all CCDs & XMind CDD Templates in current directory to
 your user folder on HKCR.net
 
+Enter FAKEIT on the cmdline following the directory path and it will simulate sending.
+
 Copyright, 2012 - Timothy W. Cook & Contributors
 License: GPL V.3 http://www.gpl.org
 """
 
 import os
 import sys
-
+import time
+import codecs
 from datetime import datetime
 
 from xmlrpclib import ServerProxy
 from xmlrpclib import DateTime
+from xmlrpclib import Fault
+from xmlrpclib import Binary
 
 try:
     ccd_dir = sys.argv[1]
@@ -41,7 +46,7 @@
 for x in file_list:
     if 'ccd-' in x and '.xsd' in x:
         ccd_list.append(x)
-    elif '.xmt' in x:
+    elif '.xmind' in x:
         xmt_list.append(x)
 
 #read from ccd2hkcr.cfg file
@@ -52,6 +57,8 @@
 password = cfg[4][9:].strip()
 f.close()
 
+sentlog = open('sent-log.txt','a')
+
 print "\nConnecting to: "+host+ " as " + user+"\n"
 
 client = ServerProxy('http://'+user+':'+password+'@'+host)
@@ -60,12 +67,15 @@
 print client
 
 my_folder = 'Members/'+user
-now = datetime.now()
+n = time.localtime()
+now = "%d-%d-%d" % (n.tm_year, n.tm_mon, n.tm_mday)
+
+sentlog.write('\n ***** Appended: '+ str("%d-%d-%d %d:%d" % (n.tm_year, n.tm_mon, n.tm_mday, n.tm_hour, n.tm_min))+"\n")
 
 if len(ccd_list) > 0:
     for filename in ccd_list:
-
-        f = open(ccd_dir+'/'+filename,'r')
+        print "\nProcessing: " + filename
+        f = codecs.open(ccd_dir+'/'+filename, encoding='iso-8859-1')
         ccd_file = f.read()
         f.close()
 
@@ -129,12 +139,17 @@
         end = ccd_file.find('</dc:language>')
         dc_language = ccd_file[begin:end]
 
-        dc_subject += ';ccd_file'  # for the Collection on HKCR.net
-        xmlrpc_dc_date = DateTime(dc_date)
+        dc_subject += ';ccd_file'  # for the CCD Collection on HKCR.net
+
+        try:
+            date_obj = datetime.strptime(dc_date,"%Y-%m-%d")
+        except:
+            date_obj = datetime.today()
+
+        xmlrpc_dc_date = DateTime(date_obj)
 
         push_location = my_folder+'/'+filename
 
-
         #build object
         ccd_object = {'file': ccd_file,
                       'title':filename,
@@ -156,7 +171,15 @@
                       'location': dc_coverage}
         if PUSH != "FAKEIT":
             print "Sending: "+ dc_title + ' --  to '+ push_location
-            client.post_object({push_location:[ccd_object, 'File']})
+            try:
+                client.post_object({push_location:[ccd_object, 'File']})
+                sentlog.write(filename+";Succeeded; "+ dc_title + "\n")
+            except Fault, err:
+                print "FAILED to Send: "+ dc_title + ' --  to '+ push_location
+                sentlog.write(filename+";Failed; "+ dc_title + ";" + repr(err) +"\n")
+                print err
+                continue
+            time.sleep(1)
         else:
             print "Fake Sending: "+ dc_title + ' -- '+filename
 
@@ -166,7 +189,8 @@
 
 if len(xmt_list) > 0:
     for filename in xmt_list:
-        f = open(filename,'r')
+        print "\n Processing XMind files.\n"
+        f = open(ccd_dir+'/'+filename,'r')
         xmt_file = Binary(f.read())
         f.close()
 
@@ -179,4 +203,5 @@
     print "\n\nYou have no CCD (XMind) Templates in: ", ccd_dir
 
 print "\n\nCCD/XMT Processing complete.\n\n"
-
+sentlog.write("\n\nCCD/XMT Processing complete.\n\n")
+sentlog.close()
\ No newline at end of file