source: TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/insecure.py @ 769

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/insecure.py@769
Revision 769, 1.7 KB checked in by lawrence, 14 years ago (diff)

Unstable commit of moles portal code
(part of directory reorg)

Line 
1#
2#This module provides python wrappers to Kevin's java code
3# I'm aiming to avoid having any java dependencies in the main browseCGI code
4# as I figure these command line activities at some point ought to be removed.
5# They certainly should be regarded as potentially insecure, especially the
6# exist call ...
7# BNL, April 2006
8#
9
10import os, os.path, tmpfile
11
12def jarLoc(jar):
13        #don't want the jar in the cgi directory ... not quite sure why, but
14        #it seems wrong ...
15        cwd=os.getcwd()
16        return os.path.normpath(os.path.join(cwd,jar))
17
18def insecureGetDoc(uri):
19        ''' Use Kevin's code to get the document from exist '''
20        #we assume the URI is of the form repository/localid
21        #we don't use os.path.split, because this is os indpendent.
22        try:
23                repPath,localID=uri.split('/')
24        except:
25                return 'Invalid URI'
26        else:
27                returnMolesJar=jarLoc('./returnmoles.jar')
28                cmd='java -jar %s %s %s xmldb:exist://glue.badc.rl.ac.uk:8080/exist/xmlrpc'%(
29                returnMolesJar,repPath,localID)
30                try:
31                        stdin,stdout,stderr=os.popen3(cmd)
32                except:
33                        return 'Unable to Obtain Document'
34                error=stderr.readlines()
35                if error!=[]:
36                        #return returnMolesJar
37                        return error
38                else:
39                        return stdout.readlines()
40       
41def doXSLT (document,xsltMethod):
42        ''' Handle a possibly external transformation to produce an html page '''
43       
44        #use temporary files for the moment, ugly, but it will work.
45        # consider using pyana or some other way of doing this later ...
46        #try:
47        fn=tmpfile('ndg-xml')
48        f=file(fn,'wb')
49        f.write(document)
50        f.close()
51        on=tmpfile('ndg-xml')
52        xalanjar=jarLoc('./xalan=j_2_7_0/xalan.jar')
53        xslt=jarLoc('./xslt')
54        cmd='java -cp %s -IN %s -XSL %s -OUT %s'%(xalanjar,fn,xslt,on)
55       
56       
57if __name__=="__main__":
58        print insecureGetDoc('badc.nerc.ac.uk/dataent13')
Note: See TracBrowser for help on using the repository browser.