1
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
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 print "Converting from %s to %s" % (old_name, new_name)
40
41 new_name2 = new_name.replace("\\","\\\\")
42 old_name2 = old_name.replace("\\","\\\\")
43
44 count = 0
45 for line in fileinput.input([str(cfg),str(xml)], inplace=1):
46 if line.find(old_name) >= 0:
47 count += 1
48 print line.replace(old_name,new_name),
49 elif line.find(old_name2) >= 0:
50 count += 1
51 print line.replace(old_name2,new_name2),
52 else:
53 print line,
54
55 fileinput.close()
56 print "Changes made: %s" % count
57 return count
58
59 if __name__ == "__main__":
60 try:
61 if "-h" in sys.argv or "--help" in sys.argv:
62 pass
63 elif len(sys.argv) == 1:
64 win_set_path()
65 sys.exit(0)
66 elif len(sys.argv) == 2:
67 win_set_path(new_name = sys.argv[1])
68 sys.exit(0)
69 elif len(sys.argv) == 3:
70 win_set_path(old_name = sys.argv[1], new_name = sys.argv[2])
71 sys.exit(0)
72 except exceptions.Exception, e:
73 print "Failed to set path: ", e
74 sys.exit(1)
75
76 print """Usage: %s [oldname] newname
77
78 Replaces the [oldname] entries in the Windows configuration files
79 with [newname]. By default, [oldname] is set to "c:\omero_dist"
80 """ % sys.argv[0]
81 sys.exit(2)
82