idok-commit AT lists.psi.ch
Subject: Commit emails of the iDok project
List archive
- From: "AFS account Florian Huebner" <huebner AT savannah.psi.ch>
- To: idok-commit AT lists.psi.ch
- Subject: [idok-commit] idok commit r258 - trunk/sites/psi/python/add_metadata
- Date: Fri, 26 Sep 2008 14:21:39 +0200
- List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
- List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>
Author: huebner
Date: Fri Sep 26 14:21:38 2008
New Revision: 258
Log:
A Python script to generate a shell script for adding metadata to the files
in a repository according to a csv file
Added:
trunk/sites/psi/python/add_metadata/
trunk/sites/psi/python/add_metadata/create_meta_script.py (contents,
props changed)
Added: trunk/sites/psi/python/add_metadata/create_meta_script.py
==============================================================================
--- (empty file)
+++ trunk/sites/psi/python/add_metadata/create_meta_script.py Fri Sep 26
14:21:38 2008
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+import sys
+import os
+
+
+searchText = "root/public"
+replaceText = ""
+dictionary = {}
+verzeichnis = []
+
+if len(sys.argv) != 3:
+ print "Please add the address and the csv file you want to pass as an
argument."
+ print "Example: create_meta_script.py https://dms.psi.ch/library/media
Verzeichnis_der_CD-ROMS_mit_Metadaten_18_06_2008.csv"
+ sys.exit(1)
+
+
+url = sys.argv[1]
+file = open(sys.argv[2])
+
+firstline = file.readline()
+keylist = [key.strip('"')for key in firstline.split(',')]
+
+for line in file:
+ line = line.replace("/"+searchText,replaceText)
+ line = line.replace(searchText,replaceText)
+ valuelist = [value.strip('"') for value in line.split(',')]
+ for i in range(8):
+ if valuelist[i] != "":
+ dictionary[keylist[i]] = valuelist[i]
+ verzeichnis.append(dictionary)
+ dictionary = {}
+file.close()
+
+fw = open('/tmp/metaScript.sh','w')
+fw.write("#!/bin/sh \n\n")
+
+for dict in verzeichnis:
+ command = ""
+ start = ""
+ meta = ""
+ filename = ""
+ if dict.has_key("Pathname") and dict.has_key("Title"):
+ start = '/opt/dms/idok put -R -m "" @dms:schema="CD" '
+ for x in dict.iterkeys():
+ if x != "Pathname" and dict[x]!="":
+ meta += '@'+x+'="'+dict[x]+'" '
+ filename = url + dict["Pathname"]
+ command = start + meta + filename
+ #print command + "\n"
+ fw.write(command + '\n\n')
+
+print "Created script: /tmp/metaScript.sh"
+print 'Please execute
"/afs/psi.ch/project/dms/admin/prod/opt/dms/idok_kinit" before using the
generated script'
+
+fw.close()
+os.chmod('/tmp/metaScript.sh', 0744)
+
+
+
+
+
+
+
+
- [idok-commit] idok commit r258 - trunk/sites/psi/python/add_metadata, AFS account Florian Huebner, 09/26/2008
Archive powered by MHonArc 2.6.19.