Permalink
Browse files

change to use .json args

  • Loading branch information...
1 parent f193451 commit 28ef2483079f1b1030b0ad785384b8795c2ea517 Chris Johnson-Roberson committed Sep 16, 2012
@@ -14,6 +14,7 @@ Zotero.PaperMachines = {
extract_csv_dir: null,
out_dir: null,
log_dir: null,
+ args_dir: null,
install_dir: null,
tagCloudReplace: true,
processors_dir: null,
@@ -48,7 +49,7 @@ Zotero.PaperMachines = {
SCHEME: "zotero://papermachines",
channel: {
- INTERFACE_URI: "chrome://papermachines/content/processors/aux/nowordcloud.html",
+ INTERFACE_URI: "chrome://papermachines/content/processors/support/nowordcloud.html",
newChannel: function (uri) {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
@@ -161,6 +162,7 @@ Zotero.PaperMachines = {
this.out_dir = this._getOrCreateDir("out");
this.processors_dir = this._getOrCreateDir("processors");
this.log_dir = this._getOrCreateDir("logs", this.out_dir);
+ this.args_dir = this._getOrCreateDir("args");
this.getStringsFromBundle();
@@ -327,17 +329,23 @@ Zotero.PaperMachines = {
var progressFile = Zotero.PaperMachines._getOrCreateFile(processor + thisID + "progress.html", Zotero.PaperMachines.out_dir);
var outFile = Zotero.PaperMachines.out_dir.clone();
- var additional_args_str = additional_args.length > 0 ? "_" + encodeURIComponent(additional_args.join("_")) : "";
- outFile.append(processor + thisID + additional_args_str + ".html");
+ var args = [Zotero.PaperMachines.processors_dir.path, csv.path, Zotero.PaperMachines.out_dir.path, collectionName];
+ args = args.concat(additional_args);
+
+ var args_str = JSON.stringify(args);
+ var args_hash = Zotero.PaperMachines.argsHash(args_str);
+ var argsHashFilename = args_hash + ".json";
+ var argFile = Zotero.PaperMachines._getOrCreateFile(argsHashFilename, Zotero.PaperMachines.args_dir);
+ Zotero.File.putContents(argFile, args_str);
+
+ var procArgs = [argFile.path];
+
+ outFile.append(processor + thisID + "-" + args_hash + ".html");
var sql = "INSERT OR REPLACE INTO processed_collections (process_path, collection, processor, status, progressfile, outfile) " +
" values (?, ?, ?, ?, ?, ?);";
Zotero.PaperMachines.DB.query(sql, [processPath, thisID, processor, "running", progressFile.path, outFile.path]);
- var args = [Zotero.PaperMachines.processors_dir.path, csv.path, Zotero.PaperMachines.out_dir.path, collectionName];
-
- args = args.concat(additional_args);
-
var callback = function (finished) {
if (finished) {
var sql_update = "UPDATE processed_collections SET status = 'done' WHERE process_path = ?;";
@@ -351,7 +359,7 @@ Zotero.PaperMachines = {
var observer = new this.processObserver(processor, processPath, callback);
proc.init(proc_file);
- proc.runAsync(args, args.length, observer);
+ proc.runAsync(procArgs, procArgs.length, observer);
},
replaceTagsBoxWithWordCloud: function (uri) {
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
@@ -981,6 +989,20 @@ Zotero.PaperMachines = {
}
}
},
+ argsHash: function (args_str) {
+ return Zotero.PaperMachines.hashCode(args_str);
+ },
+ hashCode: function (str) {
+ var r = 0;
+ for (var i = 0; i < str.length; i++) {
+ r = (r << 5) - r + str.charCodeAt(i);
+ r &= r;
+ }
+ if (r < 0) {
+ r = r + 0xFFFFFFFF + 1;
+ }
+ return r.toString(16);
+ },
selectFromOptions: function(prompt, options, multiple) {
var type = "select";
if (multiple) type = multiple;
@@ -9,11 +9,18 @@ class TextProcessor:
def __init__(self, track_progress=True):
# take in command line options
- self.cwd = sys.argv[1]
- csv_file = sys.argv[2]
- self.out_dir = sys.argv[3]
- self.collection_name = sys.argv[4]
- self.extra_args = sys.argv[5:]
+
+ self.args_filename = sys.argv[1]
+ self.args_basename = os.path.basename(self.args_filename).replace(".json", "")
+
+ with codecs.open(self.args_filename, 'r', encoding='utf-8') as args_file:
+ args = json.load(args_file)
+
+ self.cwd = args[0]
+ csv_file = args[1]
+ self.out_dir = args[2]
+ self.collection_name = args[3]
+ self.extra_args = args[4:]
self.collection = os.path.basename(csv_file).replace(".csv","")
@@ -26,7 +33,7 @@ class TextProcessor:
self.stoplist = os.path.join(self.cwd, "stopwords.txt")
self.stopwords = [x.strip() for x in codecs.open(self.stoplist, 'r', encoding='utf-8').readlines()]
- logging.basicConfig(filename=os.path.join(sys.argv[3], "logs", self.name + ".log"), level=logging.INFO)
+ logging.basicConfig(filename=os.path.join(self.out_dir, "logs", self.name + ".log"), level=logging.INFO)
logging.info("command: " + ' '.join([x.replace(' ','''\ ''') for x in sys.argv]))
@@ -86,8 +93,7 @@ class TextProcessor:
params.update(user_params)
try:
template_filename = getattr(self, "template_filename", os.path.join(self.cwd, "templates", self.name + ".html"))
- additional_arg_str = "_" + "_".join([urllib.quote_plus(x).replace('+',"%20") for x in self.extra_args]) if len(self.extra_args) > 0 else ""
- out_filename = getattr(self, "out_filename", os.path.join(self.out_dir, self.name + self.collection + additional_arg_str + ".html"))
+ out_filename = getattr(self, "out_filename", os.path.join(self.out_dir, self.name + self.collection + "-" + self.args_basename + ".html"))
with file(out_filename, 'w') as outfile:
with file(template_filename) as template:
template_str = template.read()

0 comments on commit 28ef248

Please sign in to comment.