Dear Jindrich

In data mercoledì 21 aprile 2010 12:01:44, Jindrich Dolansky ha scritto:
> I have a small problem with defining syntax of report number. My
>  institution requires it is in the form of the URL:
>  www.nusl.cz/ntk/nusl-xxx<http://www.nusl.cz/ntk/nusl-xxx>.
> 
> The problem consists in forward slashes. I have tried write them either to
>  the parameter "rnformat" of the Report_Number_Generation, i.e.,
> 
> www.nusl.cz/ntk/nusl-<PA>file:SN</PA<http://www.nusl.cz/ntk/nusl-<PA>file:S
> N</PA>>,
> 
> or directly to the Python file Report_Number_Generation.py, line 240,
> 
> reference = "www.nusl.cz/ntk/%s<http://www.nusl.cz/ntk/%s>" % (ref_format).
> 
> The corresponding error message is bellow. I have also tried various
>  variations of '/' to escape this problem as '\/' etc. but without success.
>  By collegue I was told that there should be no problem with forward
>  slashes within Python, so I don't know..

this is indeed due to the fact that the report number (rn) is directly used to 
generate filenames without prior cleaning of the '/' Unix path delimeter.

Thanks for spotting this.

Please, apply the attached patch and let us know if this does not fully fix 
your issue.

The patch modifies three WebSubmit functions, so if you decide to directly 
apply them in the installed tree, you should check in the 

/opt/cds-invenio/lib/python/invenio/websubmit_functions/

directory and use:

$ patch -p5 < /tmp/0001-WebSubmit-protected-usage-of-rn-as-filename.patch

Best regards,
        Samuele

-- 
Samuele Kaplun ** CERN Document Server ** <http://cds.cern.ch/>
From 9e05143379ff1f74fb1abd641a65f599c5546a52 Mon Sep 17 00:00:00 2001
From: Samuele Kaplun <[email protected]>
Date: Wed, 21 Apr 2010 14:53:37 +0200
Subject: [PATCH] WebSubmit: protected usage of rn as filename

* When the reportnumber (rn) is used in the name of a file,
  substitute any occurence of '/' with '-' to not conflict
  with the path delimiter in Unix.
---
 .../lib/functions/Insert_Modify_Record.py          |    2 +-
 modules/websubmit/lib/functions/Insert_Record.py   |    2 +-
 modules/websubmit/lib/functions/Move_to_Done.py    |    3 +--
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/modules/websubmit/lib/functions/Insert_Modify_Record.py b/modules/websubmit/lib/functions/Insert_Modify_Record.py
index 7effc4e..81ffe2e 100644
--- a/modules/websubmit/lib/functions/Insert_Modify_Record.py
+++ b/modules/websubmit/lib/functions/Insert_Modify_Record.py
@@ -38,7 +38,7 @@ def Insert_Modify_Record(parameters, curdir, form, user_info=None):
     else:
         raise InvenioWebSubmitFunctionError("Could not find record file")
     initialfile = "%s/%s" % (curdir,recfile)
-    finalfile = "%s/%s_%s" % (CFG_TMPDIR,rn,time.strftime("%Y-%m-%d_%H:%M:%S"))
+    finalfile = "%s/%s_%s" % (CFG_TMPDIR, rn.replace('/', '-'), time.strftime("%Y-%m-%d_%H:%M:%S"))
     shutil.copy(initialfile,finalfile)
     task_low_level_submission('bibupload', 'websubmit.Insert_Modify_Record', '-c', finalfile)
     return ""
diff --git a/modules/websubmit/lib/functions/Insert_Record.py b/modules/websubmit/lib/functions/Insert_Record.py
index bad1f11..fba194e 100644
--- a/modules/websubmit/lib/functions/Insert_Record.py
+++ b/modules/websubmit/lib/functions/Insert_Record.py
@@ -36,7 +36,7 @@ def Insert_Record(parameters, curdir, form, user_info=None):
     else:
         raise InvenioWebSubmitFunctionError("Could not find record file")
     initialfile = "%s/%s" % (curdir,recfile)
-    finalfile = "%s/%s_%s" % (CFG_TMPDIR,rn,time.strftime("%Y-%m-%d_%H:%M:%S"))
+    finalfile = "%s/%s_%s" % (CFG_TMPDIR, rn.replace('/', '-'), time.strftime("%Y-%m-%d_%H:%M:%S"))
     shutil.copy(initialfile,finalfile)
     task_low_level_submission('bibupload', 'websubmit.Insert_Record', '-r', '-i', finalfile)
     return ""
diff --git a/modules/websubmit/lib/functions/Move_to_Done.py b/modules/websubmit/lib/functions/Move_to_Done.py
index 0eaa31b..d21a983 100644
--- a/modules/websubmit/lib/functions/Move_to_Done.py
+++ b/modules/websubmit/lib/functions/Move_to_Done.py
@@ -47,8 +47,7 @@ def Move_to_Done(parameters, curdir, form, user_info=None):
         except:
             raise InvenioWebSubmitFunctionError("Cannot create done directory %s" % DONEDIR)
     # Moves the files to the done diectory and creates an archive
-    rn = rn.replace("/","-")
-    namedir = "%s_%s" % (rn,time.strftime("%Y%m%d%H%M%S"))
+    namedir = "%s_%s" % (rn.replace("/", "-"), time.strftime("%Y%m%d%H%M%S"))
     FINALDIR = "%s/%s" % (DONEDIR,namedir)
     os.rename(curdir,FINALDIR)
     if CFG_PATH_TAR != "" and CFG_PATH_GZIP != "":
-- 
1.6.3.3

Reply via email to