← Back to team overview

mlhim-specs-dev team mailing list archive

[Branch ~cdd-dev/cdd/trunk] Rev 266: Moved ccd2hkcr to new directory.

 

------------------------------------------------------------
revno: 266
committer: Timothy W. Cook <timothywayne.cook@xxxxxxxxx>
branch nick: cdd
timestamp: Mon 2012-09-24 15:47:56 -0300
message:
  Moved ccd2hkcr to new directory.
added:
  src/ccd2hkcr/ccd2hkcr.cfg
  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
=== added file 'src/ccd2hkcr/ccd2hkcr.cfg'
--- src/ccd2hkcr/ccd2hkcr.cfg	1970-01-01 00:00:00 +0000
+++ src/ccd2hkcr/ccd2hkcr.cfg	2012-09-24 18:47:56 +0000
@@ -0,0 +1,5 @@
+#  Enter your HKCR.net username and password,  e.g. host: www.hkcr.net/HKCR
+# do not remove the text to the left of the ':', do not add/delete any lines.
+host:localhost:8080/Plone
+user:admin
+password:abc123

=== added file 'src/ccd2hkcr/ccd2hkcr.py'
--- src/ccd2hkcr/ccd2hkcr.py	1970-01-01 00:00:00 +0000
+++ src/ccd2hkcr/ccd2hkcr.py	2012-09-24 18:47:56 +0000
@@ -0,0 +1,157 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+Uploads all CCDs & XMind CDD Templates in current directory to
+your user folder on HKCR.net
+
+Copyright, 2012 - Timothy W. Cook & Contributors
+License: GPL V.3 http://www.gpl.org
+"""
+
+import os
+import sys
+
+from datetime import datetime
+
+from xmlrpclib import ServerProxy
+from xmlrpclib import DateTime
+
+try:
+    ccd_dir = sys.argv[1]
+    os.path.isdir(ccd_dir) == True
+except:
+    print "Please include the absolute path to the CCDs/XMTs on the commandline."
+    print "e.g. /home/mydir/my_ccd_dir"
+    exit()
+
+if os.path.isdir(ccd_dir) == False:
+    print "\n\n********>>>  "+ ccd_dir + " is not a valid directory.\n\n"
+    exit()
+
+
+file_list = os.listdir(ccd_dir)
+ccd_list =[]
+xmt_list =[]
+
+for x in file_list:
+    if 'ccd-' in x and '.xsd' in x:
+        ccd_list.append(x)
+    if '.xmt' in x:
+        xmt_list.append(x)
+
+#read from ccd2hkcr.cfg file
+f = open('ccd2hkcr.cfg','r')
+cfg = f.readlines()
+host = cfg[2][5:].strip()
+user = cfg[3][5:].strip()
+password = cfg[4][9:].strip()
+f.close()
+
+print "\nConnecting to: "+host+ " as " + user+"\n"
+
+client = ServerProxy('http://'+user+':'+password+'@'+host)
+my_folder = '/Members/'+user
+now = datetime.now()
+
+if ccd_list:
+    for filename in ccd_list:
+        # validate using ??????, if not valid skip to next file
+        #TODO
+
+        f = open(filename,'r')
+        ccd_file = f.read()
+        f.close()
+
+        #Search ccd_file and get metadata
+        begin = ccd_file.find('<dc:title>') + len('<dc:title>')
+        end = ccd_file.find('</dc:title>')
+        dc_title = ccd_file[begin:end]
+
+        begin = ccd_file.find('<dc:creator>') + len('<dc:creator>')
+        end = ccd_file.find('</dc:creator>')
+        dc_creator = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:contributor>') + len('<dc:contributor>')
+        end = ccd_file.find('</dc:contributor>')
+        dc_contributor = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:subject>') + len('<dc:subject>')
+        end = ccd_file.find('</dc:subject>')
+        dc_subject = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:source>') + len('<dc:source>')
+        end = ccd_file.find('</dc:source>')
+        dc_source = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:rights>') + len('<dc:rights>')
+        end = ccd_file.find('</dc:rights>')
+        dc_rights = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:relation>') + len('<dc:relation>')
+        end = ccd_file.find('</dc:relation>')
+        dc_relation = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:coverage>') + len('<dc:coverage>')
+        end = ccd_file.find('</dc:coverage>')
+        dc_coverage = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:type>') + len('<dc:type>')
+        end = ccd_file.find('</dc:type>')
+        dc_type = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:identifier>') + len('<dc:identifier>')
+        end = ccd_file.find('</dc:identifier>')
+        dc_identifier = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:description>') + len('<dc:description>')
+        end = ccd_file.find('</dc:description>')
+        dc_description = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:publisher>') + len('<dc:publisher>')
+        end = ccd_file.find('</dc:publisher>')
+        dc_publisher = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:date>') + len('<dc:date>')
+        end = ccd_file.find('</dc:date>')
+        dc_date = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:format>') + len('<dc:format>')
+        end = ccd_file.find('</dc:format>')
+        dc_format = ccd_file[begin:end]
+        begin = ccd_file.find('<dc:language>') + len('<dc:language>')
+        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)
+
+        push_location = my_folder+'/'+filename
+        #build object
+        ccd_object = {'file': ccd_file,
+                      'title':filename,
+                      'creators':(dc_creator),
+                      'description':dc_description,
+                      'modification_date': xmlrpc_dc_date,
+                      'title': dc_title,
+                      'language': dc_language,
+                      'contributors': (dc_contributor),
+                      'rights': dc_rights,
+                      'subject': dc_subject.split(';'),
+                      'creation_date': xmlrpc_dc_date,
+                      'effective_date': xmlrpc_dc_date,
+                      #'relatedItems':None,
+                      #'expirationsDate':None,
+                      'allowDiscussion': True,
+                      'excludeFromNav': False,
+                      'id':filename,
+                      'location': dc_coverage}
+
+        print "Sending: "+ dc_title + ' -- '+filename
+        client.post_object({push_location:[ccd_object, 'File']})
+else:
+    print "You have no CCDs in: ", os.getcwd()
+
+
+if xmt_list:
+    for filename in xmt_list:
+        f = open(filename,'r')
+        xmt_file = Binary(f.read())
+        f.close()
+
+        push_location = my_folder+'/'+filename
+        #build object
+        xmt_object = {'file': xmt_file, 'title':filename}
+        print "Storing: "+filename
+        client.post_object({push_location:[xmt_object, 'File']})
+else:
+    print "You have no CCD Templates in: ", os.getcwd()
+
+print "\n\nCCD/XMT Processing complete.\n\n"
\ No newline at end of file