Package omero :: Package install :: Module win_set_path
[hide private]
[frames] | no frames]

Source Code for Module omero.install.win_set_path

 1  #!/usr/bin/env python 
 2   
 3  """ 
 4   
 5     Function for setting the working directory for an 
 6     Omero installation on Windows, since relative paths 
 7     are not supported. 
 8   
 9     Copyright 2009 Glencoe Software, Inc. All rights reserved. 
10     Use is subject to license terms supplied in LICENSE.txt 
11   
12     :author: Josh Moore <josh@glencoesoftware.com> 
13   
14  """ 
15   
16   
17  import sys, exceptions 
18  from xml.dom import minidom 
19  from path import path 
20  import fileinput 
21   
22  dir = path(".") 
23  cfg = dir / "etc" / "Windows.cfg" 
24  xml = dir / "etc" / "grid" / "windefault.xml" 
25   
26 -def win_set_path(new_name = dir.abspath(), old_name = r"c:\omero_dist"):
27 """ 28 Parses the Windows cfg and xml files and 29 replaces the default "c:\omero_dist" with the 30 given value. 31 """ 32 33 if new_name is None or old_name is None: 34 raise exceptions.Exception("Arguments cannot be None") 35 36 if new_name.find(" ") >= 0: 37 raise exceptions.Exception("Contains whitespace: '%s'" % new_name) 38 39 new_name = path(new_name).abspath() 40 old_name = path(old_name).abspath() 41 42 print "Converting from %s to %s" % (old_name, new_name) 43 44 new_name2 = new_name.replace("\\","\\\\") 45 old_name2 = old_name.replace("\\","\\\\") 46 47 count = 0 48 for line in fileinput.input([str(cfg),str(xml)], inplace=1): 49 if line.find(old_name) >= 0: 50 count += 1 51 print line.replace(old_name,new_name), 52 elif line.find(old_name2) >= 0: 53 count += 1 54 print line.replace(old_name2,new_name2), 55 else: 56 print line, 57 58 fileinput.close() 59 print "Changes made: %s" % count 60 return count
61 62 if __name__ == "__main__": 63 try: 64 if "-h" in sys.argv or "--help" in sys.argv: 65 pass 66 elif len(sys.argv) == 1: 67 win_set_path() 68 sys.exit(0) 69 elif len(sys.argv) == 2: 70 win_set_path(new_name = sys.argv[1]) 71 sys.exit(0) 72 elif len(sys.argv) == 3: 73 win_set_path(old_name = sys.argv[1], new_name = sys.argv[2]) 74 sys.exit(0) 75 except exceptions.Exception, e: 76 print "Failed to set path: ", e 77 sys.exit(1) 78 79 print """Usage: %s [oldname] newname 80 81 Replaces the [oldname] entries in the Windows configuration files 82 with [newname]. By default, [oldname] is set to "c:\omero_dist" 83 """ % sys.argv[0] 84 sys.exit(2) 85