[Neo-report] r2263 vincent - in /trunk: ./ neo/scripts/
nobody at svn.erp5.org
nobody at svn.erp5.org
Sat Aug 28 19:12:02 CEST 2010
Author: vincent
Date: Sat Aug 28 19:12:01 2010
New Revision: 2263
Log:
Change scripts into loadable modules.
This prepares NEO's initial eggification.
Credit: Leonardo Rochael Almeida
Added:
trunk/neo/scripts/
trunk/neo/scripts/__init__.py
trunk/neo/scripts/neoadmin.py
- copied, changed from r2191, trunk/neoadmin
trunk/neo/scripts/neoctl.py
- copied, changed from r2191, trunk/neoctl
trunk/neo/scripts/neomaster.py
- copied, changed from r2191, trunk/neomaster
trunk/neo/scripts/neomigrate.py
- copied, changed from r2191, trunk/neomigrate
trunk/neo/scripts/neostorage.py
- copied, changed from r2191, trunk/neostorage
Modified:
trunk/neoadmin
trunk/neoctl
trunk/neomaster
trunk/neomigrate
trunk/neostorage
Added: trunk/neo/scripts/__init__.py
==============================================================================
(empty)
Copied: trunk/neo/scripts/neoadmin.py (from r2191, trunk/neoadmin)
==============================================================================
--- trunk/neoadmin [iso-8859-1] (original)
+++ trunk/neo/scripts/neoadmin.py [iso-8859-1] Sat Aug 28 19:12:01 2010
@@ -1,5 +1,3 @@
-#! /usr/bin/env python2.4
-#
# neoadmin - run an administrator node of NEO
#
# Copyright (C) 2009 Nexedi SA
@@ -35,31 +33,35 @@ parser.add_option('-m', '--masters', hel
parser.add_option('-b', '--bind', help = 'the local address to bind to')
parser.add_option('-n', '--name', help = 'the node name (improve logging)')
-# build configuration dict from command line options
-(options, args) = parser.parse_args()
-arguments = dict(
- uuid = options.uuid,
- name = options.name or options.section,
- cluster = options.cluster,
- masters = options.masters,
- bind = options.bind,
-)
defaults = dict(
name = 'admin',
bind = '127.0.0.1:9999',
masters = '127.0.0.1:10000',
)
-config = ConfigurationManager(
- defaults,
- options.file,
- options.section or 'admin',
- arguments,
-)
-# setup custom logging
-setupLog(config.getName(), options.logfile or None, options.verbose)
+def main(args=None):
+ # build configuration dict from command line options
+ (options, args) = parser.parse_args(args=args)
+ arguments = dict(
+ uuid = options.uuid,
+ name = options.name or options.section,
+ cluster = options.cluster,
+ masters = options.masters,
+ bind = options.bind,
+ )
+
+ config = ConfigurationManager(
+ defaults,
+ options.file,
+ options.section or 'admin',
+ arguments,
+ )
+
+ # setup custom logging
+ setupLog(config.getName(), options.logfile or None, options.verbose)
+
+ # and then, load and run the application
+ from neo.admin.app import Application
+ app = Application(config)
+ app.run()
-# and then, load and run the application
-from neo.admin.app import Application
-app = Application(config)
-app.run()
Copied: trunk/neo/scripts/neoctl.py (from r2191, trunk/neoctl)
==============================================================================
--- trunk/neoctl [iso-8859-1] (original)
+++ trunk/neo/scripts/neoctl.py [iso-8859-1] Sat Aug 28 19:12:01 2010
@@ -1,6 +1,4 @@
-#! /usr/bin/env python
-#
-# neoadmin - run an administrator node of NEO
+# neoadmin - run an administrator node of NEO
#
# Copyright (C) 2009 Nexedi SA
#
@@ -29,17 +27,18 @@ parser.add_option('-a', '--address', hel
'of an admin node', default = '127.0.0.1:9999')
parser.add_option('--handler', help = 'specify the connection handler')
-(options, args) = parser.parse_args()
-address = options.address
-if ':' in address:
- address, port = address.split(':', 1)
- port = int(port)
-else:
- port = 9999
-handler = options.handler or "SocketConnector"
+def main(args=None):
+ (options, args) = parser.parse_args(args=args)
+ address = options.address
+ if ':' in address:
+ address, port = address.split(':', 1)
+ port = int(port)
+ else:
+ port = 9999
+ handler = options.handler or "SocketConnector"
-setupLog('NEOCTL', options.verbose)
-from neo.neoctl.app import Application
+ setupLog('NEOCTL', options.verbose)
+ from neo.neoctl.app import Application
-print Application(address, port, handler).execute(args)
+ print Application(address, port, handler).execute(args)
Copied: trunk/neo/scripts/neomaster.py (from r2191, trunk/neomaster)
==============================================================================
--- trunk/neomaster [iso-8859-1] (original)
+++ trunk/neo/scripts/neomaster.py [iso-8859-1] Sat Aug 28 19:12:01 2010
@@ -1,5 +1,3 @@
-#! /usr/bin/env python2.4
-#
# neomaster - run a master node of NEO
#
# Copyright (C) 2006 Nexedi SA
@@ -36,17 +34,6 @@ parser.add_option('-r', '--replicas', he
parser.add_option('-p', '--partitions', help = 'partitions number')
parser.add_option('-l', '--logfile', help = 'specify a logging file')
-# build configuration dict from command line options
-(options, args) = parser.parse_args()
-arguments = dict(
- uuid = options.uuid or None,
- bind = options.bind,
- name = options.name or options.section,
- cluster = options.cluster,
- masters = options.masters,
- replicas = options.replicas,
- partitions = options.partitions,
-)
defaults = dict(
name = 'master',
bind = '127.0.0.1:10000',
@@ -54,17 +41,31 @@ defaults = dict(
replicas = 0,
partitions = 100,
)
-config = ConfigurationManager(
- defaults,
- options.file,
- options.section or 'master',
- arguments,
-)
-# setup custom logging
-setupLog(config.getName(), options.logfile or None, options.verbose)
+def main(args=None):
+ # build configuration dict from command line options
+ (options, args) = parser.parse_args(args=args)
+ arguments = dict(
+ uuid = options.uuid or None,
+ bind = options.bind,
+ name = options.name or options.section,
+ cluster = options.cluster,
+ masters = options.masters,
+ replicas = options.replicas,
+ partitions = options.partitions,
+ )
+ config = ConfigurationManager(
+ defaults,
+ options.file,
+ options.section or 'master',
+ arguments,
+ )
+
+ # setup custom logging
+ setupLog(config.getName(), options.logfile or None, options.verbose)
+
+ # and then, load and run the application
+ from neo.master.app import Application
+ app = Application(config)
+ app.run()
-# and then, load and run the application
-from neo.master.app import Application
-app = Application(config)
-app.run()
Copied: trunk/neo/scripts/neomigrate.py (from r2191, trunk/neomigrate)
==============================================================================
--- trunk/neomigrate [iso-8859-1] (original)
+++ trunk/neo/scripts/neomigrate.py [iso-8859-1] Sat Aug 28 19:12:01 2010
@@ -33,36 +33,37 @@ parser.add_option('-s', '--source', help
parser.add_option('-d', '--destination', help = 'the destination database')
parser.add_option('-c', '--cluster', help = 'the NEO cluster name')
-# parse options
-(options, args) = parser.parse_args()
-source = options.source or None
-destination = options.destination or None
-cluster = options.cluster or None
-
-# check options
-if source is None or destination is None:
- raise RuntimeError('Source and destination databases must be supplied')
-if cluster is None:
- raise RuntimeError('The NEO cluster name must be supplied')
-
-# set up logging
-setupLog('neomigrate', None, options.verbose or False)
-
-# open storages
-from ZODB.FileStorage import FileStorage
-#from ZEO.ClientStorage import ClientStorage as ZEOStorage
-from neo.client.Storage import Storage as NEOStorage
-if os.path.exists(source):
- src = FileStorage(file_name=source)
- dst = NEOStorage(master_nodes=destination, name=cluster)
-else:
- src = NEOStorage(master_nodes=source, name=cluster)
- dst = FileStorage(file_name=destination)
-
-# do the job
-print "Migrating from %s to %s" % (source, destination)
-start = time.time()
-dst.copyTransactionsFrom(src, verbose=0)
-elapsed = time.time() - start
-print "Migration done in %3.5f" % (elapsed, )
+def main(args=None):
+ # parse options
+ (options, args) = parser.parse_args(args=args)
+ source = options.source or None
+ destination = options.destination or None
+ cluster = options.cluster or None
+
+ # check options
+ if source is None or destination is None:
+ raise RuntimeError('Source and destination databases must be supplied')
+ if cluster is None:
+ raise RuntimeError('The NEO cluster name must be supplied')
+
+ # set up logging
+ setupLog('neomigrate', None, options.verbose or False)
+
+ # open storages
+ from ZODB.FileStorage import FileStorage
+ #from ZEO.ClientStorage import ClientStorage as ZEOStorage
+ from neo.client.Storage import Storage as NEOStorage
+ if os.path.exists(source):
+ src = FileStorage(file_name=source)
+ dst = NEOStorage(master_nodes=destination, name=cluster)
+ else:
+ src = NEOStorage(master_nodes=source, name=cluster)
+ dst = FileStorage(file_name=destination)
+
+ # do the job
+ print "Migrating from %s to %s" % (source, destination)
+ start = time.time()
+ dst.copyTransactionsFrom(src, verbose=0)
+ elapsed = time.time() - start
+ print "Migration done in %3.5f" % (elapsed, )
Copied: trunk/neo/scripts/neostorage.py (from r2191, trunk/neostorage)
==============================================================================
--- trunk/neostorage [iso-8859-1] (original)
+++ trunk/neo/scripts/neostorage.py [iso-8859-1] Sat Aug 28 19:12:01 2010
@@ -41,34 +41,37 @@ parser.add_option('-m', '--masters', hel
parser.add_option('-a', '--adapter', help = 'database adapter to use')
parser.add_option('-d', '--database', help = 'database connections string')
-(options, args) = parser.parse_args()
-arguments = dict(
- uuid = options.uuid,
- bind = options.bind,
- name = options.name or options.section,
- cluster = options.cluster,
- masters = options.masters,
- database = options.database,
- reset = options.reset,
- adapter = options.adapter,
-)
defaults = dict(
name = 'storage',
bind = '127.0.0.1:20000',
masters = '127.0.0.1:10000',
adapter = 'MySQL',
)
-config = ConfigurationManager(
- defaults,
- options.file,
- options.section or 'storage',
- arguments,
-)
-# setup custom logging
-setupLog(config.getName(), options.logfile or None, options.verbose)
+def main(args=None):
+ (options, args) = parser.parse_args(args=args)
+ arguments = dict(
+ uuid = options.uuid,
+ bind = options.bind,
+ name = options.name or options.section,
+ cluster = options.cluster,
+ masters = options.masters,
+ database = options.database,
+ reset = options.reset,
+ adapter = options.adapter,
+ )
+ config = ConfigurationManager(
+ defaults,
+ options.file,
+ options.section or 'storage',
+ arguments,
+ )
+
+ # setup custom logging
+ setupLog(config.getName(), options.logfile or None, options.verbose)
+
+ # and then, load and run the application
+ from neo.storage.app import Application
+ app = Application(config)
+ app.run()
-# and then, load and run the application
-from neo.storage.app import Application
-app = Application(config)
-app.run()
Modified: trunk/neoadmin
==============================================================================
--- trunk/neoadmin [iso-8859-1] (original)
+++ trunk/neoadmin [iso-8859-1] Sat Aug 28 19:12:01 2010
@@ -18,48 +18,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-from optparse import OptionParser
-from neo import setupLog
-from neo.config import ConfigurationManager
+from neo.scripts.neoadmin import main
+main()
-parser = OptionParser()
-parser.add_option('-u', '--uuid', help='specify an UUID to use for this ' \
- 'process')
-parser.add_option('-v', '--verbose', action = 'store_true',
- help = 'print verbose messages')
-parser.add_option('-f', '--file', help = 'specify a configuration file')
-parser.add_option('-s', '--section', help = 'specify a configuration section')
-parser.add_option('-l', '--logfile', help = 'specify a logging file')
-parser.add_option('-c', '--cluster', help = 'the cluster name')
-parser.add_option('-m', '--masters', help = 'master node list')
-parser.add_option('-b', '--bind', help = 'the local address to bind to')
-parser.add_option('-n', '--name', help = 'the node name (improve logging)')
-
-# build configuration dict from command line options
-(options, args) = parser.parse_args()
-arguments = dict(
- uuid = options.uuid,
- name = options.name or options.section,
- cluster = options.cluster,
- masters = options.masters,
- bind = options.bind,
-)
-defaults = dict(
- name = 'admin',
- bind = '127.0.0.1:9999',
- masters = '127.0.0.1:10000',
-)
-config = ConfigurationManager(
- defaults,
- options.file,
- options.section or 'admin',
- arguments,
-)
-
-# setup custom logging
-setupLog(config.getName(), options.logfile or None, options.verbose)
-
-# and then, load and run the application
-from neo.admin.app import Application
-app = Application(config)
-app.run()
Modified: trunk/neoctl
==============================================================================
--- trunk/neoctl [iso-8859-1] (original)
+++ trunk/neoctl [iso-8859-1] Sat Aug 28 19:12:01 2010
@@ -18,28 +18,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-import sys
-from optparse import OptionParser
-from neo import setupLog
-
-parser = OptionParser()
-parser.add_option('-v', '--verbose', action = 'store_true',
- help = 'print verbose messages')
-parser.add_option('-a', '--address', help = 'specify the address (ip:port) ' \
- 'of an admin node', default = '127.0.0.1:9999')
-parser.add_option('--handler', help = 'specify the connection handler')
-
-(options, args) = parser.parse_args()
-address = options.address
-if ':' in address:
- address, port = address.split(':', 1)
- port = int(port)
-else:
- port = 9999
-handler = options.handler or "SocketConnector"
-
-setupLog('NEOCTL', options.verbose)
-from neo.neoctl.app import Application
-
-print Application(address, port, handler).execute(args)
+from neo.scripts.neoctl import main
+main()
Modified: trunk/neomaster
==============================================================================
--- trunk/neomaster [iso-8859-1] (original)
+++ trunk/neomaster [iso-8859-1] Sat Aug 28 19:12:01 2010
@@ -18,53 +18,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-from optparse import OptionParser
-from neo import setupLog
-from neo.config import ConfigurationManager
+from neo.scripts.neomaster import main
+main()
-parser = OptionParser()
-parser.add_option('-v', '--verbose', action = 'store_true',
- help = 'print verbose messages')
-parser.add_option('-f', '--file', help = 'specify a configuration file')
-parser.add_option('-s', '--section', help = 'specify a configuration section')
-parser.add_option('-u', '--uuid', help='the node UUID (testing purpose)')
-parser.add_option('-n', '--name', help = 'the node name (impove logging)')
-parser.add_option('-b', '--bind', help = 'the local address to bind to')
-parser.add_option('-c', '--cluster', help = 'the cluster name')
-parser.add_option('-m', '--masters', help = 'master node list')
-parser.add_option('-r', '--replicas', help = 'replicas number')
-parser.add_option('-p', '--partitions', help = 'partitions number')
-parser.add_option('-l', '--logfile', help = 'specify a logging file')
-
-# build configuration dict from command line options
-(options, args) = parser.parse_args()
-arguments = dict(
- uuid = options.uuid or None,
- bind = options.bind,
- name = options.name or options.section,
- cluster = options.cluster,
- masters = options.masters,
- replicas = options.replicas,
- partitions = options.partitions,
-)
-defaults = dict(
- name = 'master',
- bind = '127.0.0.1:10000',
- masters = '',
- replicas = 0,
- partitions = 100,
-)
-config = ConfigurationManager(
- defaults,
- options.file,
- options.section or 'master',
- arguments,
-)
-
-# setup custom logging
-setupLog(config.getName(), options.logfile or None, options.verbose)
-
-# and then, load and run the application
-from neo.master.app import Application
-app = Application(config)
-app.run()
Modified: trunk/neomigrate
==============================================================================
--- trunk/neomigrate [iso-8859-1] (original)
+++ trunk/neomigrate [iso-8859-1] Sat Aug 28 19:12:01 2010
@@ -18,51 +18,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-from optparse import OptionParser
-import logging
-import time
-import os
-
-from neo import setupLog
-
-# register options
-parser = OptionParser()
-parser.add_option('-v', '--verbose', action = 'store_true',
- help = 'print verbose messages')
-parser.add_option('-s', '--source', help = 'the source database')
-parser.add_option('-d', '--destination', help = 'the destination database')
-parser.add_option('-c', '--cluster', help = 'the NEO cluster name')
-
-# parse options
-(options, args) = parser.parse_args()
-source = options.source or None
-destination = options.destination or None
-cluster = options.cluster or None
-
-# check options
-if source is None or destination is None:
- raise RuntimeError('Source and destination databases must be supplied')
-if cluster is None:
- raise RuntimeError('The NEO cluster name must be supplied')
-
-# set up logging
-setupLog('neomigrate', None, options.verbose or False)
-
-# open storages
-from ZODB.FileStorage import FileStorage
-#from ZEO.ClientStorage import ClientStorage as ZEOStorage
-from neo.client.Storage import Storage as NEOStorage
-if os.path.exists(source):
- src = FileStorage(file_name=source)
- dst = NEOStorage(master_nodes=destination, name=cluster)
-else:
- src = NEOStorage(master_nodes=source, name=cluster)
- dst = FileStorage(file_name=destination)
-
-# do the job
-print "Migrating from %s to %s" % (source, destination)
-start = time.time()
-dst.copyTransactionsFrom(src, verbose=0)
-elapsed = time.time() - start
-print "Migration done in %3.5f" % (elapsed, )
+from neo.scripts.neomigrate import main
+main()
Modified: trunk/neostorage
==============================================================================
--- trunk/neostorage [iso-8859-1] (original)
+++ trunk/neostorage [iso-8859-1] Sat Aug 28 19:12:01 2010
@@ -18,57 +18,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-from optparse import OptionParser
-from neo import setupLog
-from neo.config import ConfigurationManager
+from neo.scripts.neostorage import main
+main()
-
-parser = OptionParser()
-parser.add_option('-v', '--verbose', action = 'store_true',
- help = 'print verbose messages')
-parser.add_option('-u', '--uuid', help='specify an UUID to use for this ' \
- 'process. Previously assigned UUID takes precedence (ie ' \
- 'you should always use -R with this switch)')
-parser.add_option('-f', '--file', help = 'specify a configuration file')
-parser.add_option('-s', '--section', help = 'specify a configuration section')
-parser.add_option('-l', '--logfile', help = 'specify a logging file')
-parser.add_option('-R', '--reset', action = 'store_true',
- help = 'remove an existing database if any')
-parser.add_option('-n', '--name', help = 'the node name (impove logging)')
-parser.add_option('-b', '--bind', help = 'the local address to bind to')
-parser.add_option('-c', '--cluster', help = 'the cluster name')
-parser.add_option('-m', '--masters', help = 'master node list')
-parser.add_option('-a', '--adapter', help = 'database adapter to use')
-parser.add_option('-d', '--database', help = 'database connections string')
-
-(options, args) = parser.parse_args()
-arguments = dict(
- uuid = options.uuid,
- bind = options.bind,
- name = options.name or options.section,
- cluster = options.cluster,
- masters = options.masters,
- database = options.database,
- reset = options.reset,
- adapter = options.adapter,
-)
-defaults = dict(
- name = 'storage',
- bind = '127.0.0.1:20000',
- masters = '127.0.0.1:10000',
- adapter = 'MySQL',
-)
-config = ConfigurationManager(
- defaults,
- options.file,
- options.section or 'storage',
- arguments,
-)
-
-# setup custom logging
-setupLog(config.getName(), options.logfile or None, options.verbose)
-
-# and then, load and run the application
-from neo.storage.app import Application
-app = Application(config)
-app.run()
More information about the Neo-report
mailing list