[Erp5-report] r15589 - /erp5/trunk/utils/instanceswitch.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Aug 10 10:52:57 CEST 2007
Author: bartek
Date: Fri Aug 10 10:52:57 2007
New Revision: 15589
URL: http://svn.erp5.org?rev=15589&view=rev
Log:
A developer utility script for fast and easy switching Data.fs files within one INSTANCE_HOME.
Added:
erp5/trunk/utils/instanceswitch.py (with props)
Added: erp5/trunk/utils/instanceswitch.py
URL: http://svn.erp5.org/erp5/trunk/utils/instanceswitch.py?rev=15589&view=auto
==============================================================================
--- erp5/trunk/utils/instanceswitch.py (added)
+++ erp5/trunk/utils/instanceswitch.py Fri Aug 10 10:52:57 2007
@@ -1,0 +1,108 @@
+#!/usr/bin/env python
+
+"""
+ A utility for switching Data.fs if you want to experiment with multiple
+ sites within one INSTANCE_HOME.
+
+ Usage:
+
+ run it from your INSTANCE_HOME; it will ask you if you want to
+ create a new instance, and prompt for a name of the current
+ instance. Then start zope. Next time you run it you will be given a
+ choice of alternative Data.fs's, and an option to create a new one.
+
+ A cmdline arg "tell" will only tell you which instance you are using
+ now (which is the current).
+
+ How it works:
+
+ All it does is rename Data.fs into Data.fs.[instance_name] and write
+ the new name into file var/current. Then when you switch instances,
+ it renames Data.fs into Data.fs.[current_name] and
+ Data.fs[instance_name] into Data.fs, and writes instance_name into
+ var/current.
+"""
+
+import glob
+import os
+import sys
+
+if len(sys.argv) > 1:
+ if sys.argv[1] == 'tell':
+ if os.path.exists('var/current'):
+ print open('var/current').read()
+ else:
+ print 'no current instance'
+ sys.exit(0)
+ else:
+ print 'I dont know cmdline arg ', sys.argv[1]
+ sys.exit(0)
+
+illegal_names = ('index', 'lock', 'tmp')
+
+def checkName(name):
+ name = name.strip()
+ if name in illegal_names:
+ print 'name can not be in ' + str(illegal_names)
+ sys.exit(0)
+
+# check if we can proceed
+if os.path.exists('var/Z2.lock') or os.path.exists('var/Z2.pid'):
+ print 'stop Zope first'
+ sys.exit(0)
+
+# if current instance is not named, name it
+if not os.path.exists('var/current'):
+ current_name = raw_input('How to name current instance? ')
+ if not current_name:
+ print 'you did not give current name'
+ sys.exit(0)
+ checkName(current_name)
+ f = open('var/current', 'w')
+ f.write(current_name)
+ f.close()
+else:
+ current_name = open('var/current').read()
+current_name = current_name.strip()
+
+# instance name can be given on the command line...
+if len(sys.argv) == 2:
+ instance_name = sys.argv[1]
+else:
+ # ...or we ask for it
+ datafs_item_list = list(enumerate([name[12:] for name in glob.glob('var/Data.fs.*') if name[12:] not in illegal_names]))
+ for item in datafs_item_list:
+ print '(%s) %s' % item
+ choice = raw_input('Enter number or name to create new instance: ')
+ checkName(choice)
+ choice = choice.strip()
+ if not choice:
+ print 'bye'
+ sys.exit(0)
+ try:
+ instance_name = datafs_item_list[int(choice)][1]
+ except ValueError:
+ instance_name = choice
+ except IndexError:
+ print 'invalid choice'
+ sys.exit(0)
+
+# check if the instance exists
+instance_exists = os.path.exists('var/Data.fs.'+instance_name)
+if not instance_exists:
+ create = raw_input('Instance ' + instance_name + ' does not exist; create? (y): ')
+ if create and create != 'y':
+ sys.exit(0)
+
+# now we go ahead
+os.rename('var/Data.fs', 'var/Data.fs.' + current_name)
+if instance_exists:
+ os.rename('var/Data.fs.' + instance_name, 'var/Data.fs')
+ # if it is new we do nothing, zope will create it
+ f = open('var/current', 'w')
+f.write(instance_name)
+f.close()
+print 'ok'
+print 'Previous instance renamed as: ' + current_name
+print 'Current instance name is: ' + instance_name
+
Propchange: erp5/trunk/utils/instanceswitch.py
------------------------------------------------------------------------------
svn:executable = *
More information about the Erp5-report
mailing list