changeset 83:8a5be4814a48

use console_script entry point - setup.py now installs a "moin" script for the platform loading the config file now works like this: - from given file (-c path/filename) - from env variable MOINCFG - from current directory: wikiconfig_local.py, wikiconfig.py (in that order)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 06 Mar 2011 22:47:02 +0100
parents df1fc8a424e8
children 2f9b41699a7f
files MoinMoin/app.py MoinMoin/script/__init__.py moin moin.bat setup.py
diffstat 5 files changed, 48 insertions(+), 98 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/app.py	Sun Mar 06 21:40:22 2011 +0100
+++ b/MoinMoin/app.py	Sun Mar 06 22:47:02 2011 +0100
@@ -66,7 +66,16 @@
     if flask_config_file:
         app.config.from_pyfile(flask_config_file)
     else:
-        app.config.from_envvar('MOINCFG', silent=True)
+        if not app.config.from_envvar('MOINCFG', silent=True):
+            # no MOINCFG env variable set, try stuff in cwd:
+            from os import path
+            flask_config_file = path.abspath('wikiconfig_local.py')
+            if not path.exists(flask_config_file):
+                flask_config_file = path.abspath('wikiconfig.py')
+                if not path.exists(flask_config_file):
+                    flask_config_file = None
+            if flask_config_file:
+                app.config.from_pyfile(flask_config_file)
     if flask_config_dict:
         app.config.update(flask_config_dict)
     Config = moin_config_class
--- a/MoinMoin/script/__init__.py	Sun Mar 06 21:40:22 2011 +0100
+++ b/MoinMoin/script/__init__.py	Sun Mar 06 22:47:02 2011 +0100
@@ -3,5 +3,41 @@
 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
 
 """
-    MoinMoin - Extension Script Package
+MoinMoin - Extension Script Package
 """
+
+import sys
+
+
+def main(default_command='moin', wiki_config=None):
+    """
+    console_script entry point
+    """
+    from MoinMoin.app import create_app
+    from flaskext.script import Manager, Server
+
+    manager = Manager(create_app)
+    manager.add_option('-c', '--config', dest='config', required=False, default=wiki_config)
+    manager.add_command("moin", Server(host='127.0.0.1', port=8080))
+
+    from MoinMoin.script.account.create import Create_User
+    manager.add_command("account_create", Create_User())
+    from MoinMoin.script.account.disable import Disable_User
+    manager.add_command("account_disable", Disable_User())
+    from MoinMoin.script.account.resetpw import Set_Password
+    manager.add_command("account_password", Set_Password())
+    from MoinMoin.script.maint.reduce_revisions import Reduce_Revisions
+    manager.add_command("maint_reduce_revisions", Reduce_Revisions())
+    from MoinMoin.script.maint.set_meta import Set_Meta
+    manager.add_command("maint_set_meta", Set_Meta())
+    from MoinMoin.script.maint.create_item import Create_Item
+    manager.add_command("maint_create_item", Create_Item())
+    from MoinMoin.script.maint.xml import XML
+    manager.add_command("maint_xml", XML())
+
+    return manager.run(default_command=default_command)
+
+
+def fatal(msg):
+    sys.exit(msg)
+
--- a/moin	Sun Mar 06 21:40:22 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-#!/usr/bin/env python
-"""
-moin script - issue moin commands (including starting the builtin server)
-
-Usage:
-
-start server on 127.0.0.1:8080 (using wikiconfig_local.py / wikiconfig.py
-from same directory then):
-$ moin moin
-$ moin            # works also
-$ moin runserver  # works also, but port 5000
-
-start server with some specific config:
-$ moin moin -c configfile
-
-start server without debugger / reloader and on different host/port:
-$ moin moin --host=0.0.0.0 --port=8888 --no-debug --no-reload
-
-start shell:
-$ moin shell
-
-@copyright: 2010 MoinMoin:ThomasWaldmann
-@license: GNU GPL, see COPYING for details.
-"""
-
-import sys
-from os import path
-
-MANUALLY = False # use True and adjust values below if False doesn't work for you
-
-if MANUALLY:
-    # hint: use None as value if the code already is in sys.path
-    moin_code = '/path/to/code'
-    wiki_config = '/path/to/configs/wikiconfig.py'
-
-else:
-    # try magic for users who just unpack the moin archive or
-    # developers who just run wikiserver.py from their workdir
-
-    # directory where THIS file is located
-    here = path.abspath(path.dirname(__file__))
-
-    # moin's own code:
-    moin_code = here
-    if not path.exists(path.join(moin_code, 'MoinMoin')):
-        moin_code = None # no idea where it is
-
-    # wiki configuration:
-    wiki_config = path.join(here, 'wikiconfig_local.py') # for development
-    if not path.exists(wiki_config):
-        wiki_config = path.join(here, 'wikiconfig.py') # normal usage
-
-
-if moin_code:
-    # add the parent dir of the MoinMoin code to sys.path,
-    # to make import work:
-    sys.path.insert(0, moin_code)
-
-
-from MoinMoin.app import create_app
-from flaskext.script import Manager, Server
-
-manager = Manager(create_app)
-manager.add_option('-c', '--config', dest='config', required=False, default=wiki_config)
-manager.add_command("moin", Server(host='127.0.0.1', port=8080))
-
-from MoinMoin.script.account.create import Create_User
-manager.add_command("account_create", Create_User())
-from MoinMoin.script.account.disable import Disable_User
-manager.add_command("account_disable", Disable_User())
-from MoinMoin.script.account.resetpw import Set_Password
-manager.add_command("account_password", Set_Password())
-from MoinMoin.script.maint.reduce_revisions import Reduce_Revisions
-manager.add_command("maint_reduce_revisions", Reduce_Revisions())
-from MoinMoin.script.maint.set_meta import Set_Meta
-manager.add_command("maint_set_meta", Set_Meta())
-from MoinMoin.script.maint.create_item import Create_Item
-manager.add_command("maint_create_item", Create_Item())
-from MoinMoin.script.maint.xml import XML
-manager.add_command("maint_xml", XML())
-
-if __name__ == "__main__":
-    if sys.argv == ['./moin'] or sys.argv == ['moin']:
-        manager.run(default_command='moin')
-    else:
-        manager.run(default_command=sys.argv[1])
--- a/moin.bat	Sun Mar 06 21:40:22 2011 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-echo off
-echo.
-echo This executes the "moin" file under Windows.  Read the "moin" file for options.
-echo.
-
-echo Starting server... Press Ctrl-c keys to stop server.
-python moin %*
-
-
--- a/setup.py	Sun Mar 06 21:40:22 2011 +0100
+++ b/setup.py	Sun Mar 06 22:47:02 2011 +0100
@@ -103,7 +103,7 @@
         'hg': ["mercurial"], # used by mercurial backend
     },
     entry_points = dict(
-        console_scripts = ['moin = MoinMoin.cmdline:main'], # TODO
+        console_scripts = ['moin = MoinMoin.script:main'], # TODO
     ),
 
     # stuff for babel: