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