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  dummy = object() 
23   
24 -def win_set_path(new_name = dummy, old_name = r"c:\omero_dist", dir = path(".")):
25 """ 26 Parses the Windows cfg and xml files and 27 replaces the default "c:\omero_dist" with the 28 given value. 29 """ 30 31 cfg = dir / "etc" / "Windows.cfg" 32 xml = dir / "etc" / "grid" / "windefault.xml" 33 34 if new_name == dummy: 35 new_name = dir.abspath() 36 if new_name is None or old_name is None: 37 raise exceptions.Exception("Arguments cannot be None") 38 39 if new_name.find(" ") >= 0: 40 raise exceptions.Exception("Contains whitespace: '%s'" % new_name) 41 42 new_name = path(new_name).abspath() 43 old_name = path(old_name).abspath() 44 45 print "Converting from %s to %s" % (old_name, new_name) 46 47 new_name2 = new_name.replace("\\","\\\\") 48 old_name2 = old_name.replace("\\","\\\\") 49 50 count = 0 51 for line in fileinput.input([str(cfg),str(xml)], inplace=1): 52 if line.find(old_name) >= 0: 53 count += 1 54 print line.replace(old_name,new_name), 55 elif line.find(old_name2) >= 0: 56 count += 1 57 print line.replace(old_name2,new_name2), 58 else: 59 print line, 60 61 fileinput.close() 62 print "Changes made: %s" % count 63 return count
64 65 if __name__ == "__main__": 66 try: 67 if "-h" in sys.argv or "--help" in sys.argv: 68 pass 69 elif len(sys.argv) == 1: 70 win_set_path() 71 sys.exit(0) 72 elif len(sys.argv) == 2: 73 win_set_path(new_name = sys.argv[1]) 74 sys.exit(0) 75 elif len(sys.argv) == 3: 76 win_set_path(old_name = sys.argv[1], new_name = sys.argv[2]) 77 sys.exit(0) 78 except exceptions.Exception, e: 79 print "Failed to set path: ", e 80 sys.exit(1) 81 82 print """Usage: %s [oldname] newname 83 84 Replaces the [oldname] entries in the Windows configuration files 85 with [newname]. By default, [oldname] is set to "c:\omero_dist" 86 """ % sys.argv[0] 87 sys.exit(2) 88