Permalink
Browse files

Remove custom commands and just use django commands

  • Loading branch information...
1 parent 2fefdf3 commit 9cfa753b270af897ff545f98745696e078fd6b2f @mvantellingen mvantellingen committed Mar 24, 2012
@@ -1,3 +0,0 @@
-from localshop.commands.manage import manage
-from localshop.commands.control import start, stop, restart
-from localshop.commands.upgrade import upgrade
@@ -1,103 +0,0 @@
-import os
-import os.path
-
-from localshop.commands.utils import options, opt, consume_args
-from localshop.services import http, worker, daemon
-
-
-services = {
- 'http': http.LocalShopHTTPServer,
- 'worker': worker.LocalShopWorker,
-}
-
-
-def get_service_from_args(args):
- if len(args) == 2:
- service = args[1]
- else:
- service = 'http'
-
- if service not in services:
- raise ValueError(service)
-
- return service
-
-
-def get_daemon_for_service(service, daemonize=True, **options):
- from localshop.conf import settings
-
- service_class = services[service]
-
- app = service_class(**options)
-
- kwargs = {
- 'app': app,
- 'detach_process': daemonize,
- }
- if daemonize:
- log = open(os.path.join(settings.LOG_DIR, '%s.log' % (service,)), 'w+')
- kwargs.update({
- 'pidfile': os.path.join(settings.RUN_DIR, '%s.pid' % (service,)),
- 'stderr': log,
- 'stdout': log,
- })
-
- proc = daemon.Daemon(**kwargs)
-
- return proc
-
-
-@options(
- opt('--daemon', '-d', action='store_true', default=False, dest='daemonize'),
- opt('--no-daemon', '-f', action='store_false', default=False, dest='daemonize'),
- opt('--debug', action='store_true', default=False, dest='debug'),
-)
-@consume_args
-def start(args, daemonize=False, debug=False):
- from localshop.conf import settings
-
- if not os.path.exists(settings.LOG_DIR):
- os.makedirs(settings.LOG_DIR)
-
- if not os.path.exists(settings.RUN_DIR):
- os.makedirs(settings.RUN_DIR)
-
- # Ensure we force an environment upgrade before we start the server
-
- service = get_service_from_args(args)
-
- # Special handling for http
- if args[0] == 'http':
- proc = service(
- debug=debug,
- daemonize=daemonize,
- pidfile=os.path.join(settings.RUN_DIR, '%s.pid' % (args[0],)),
- logfile=os.path.join(settings.LOG_DIR, '%s.log' % (args[0],)),
- )
- else:
- proc = get_daemon_for_service(service, daemonize, debug=debug)
-
- proc.start()
-
-
-@consume_args
-def stop(args):
- # TODO: we should improve upon this so it just discovers the PID
- # for an app and sends the signal
- service = get_service_from_args(args)
-
- proc = get_daemon_for_service(service)
-
- proc.stop()
-
-
-@consume_args
-def restart(args):
- # TODO: we should improve upon this so it just discovers the PID
- # for an app and sends the signal
- service = get_service_from_args(args)
-
- proc = get_daemon_for_service(service)
-
- proc.restart()
-
@@ -1,18 +0,0 @@
-from localshop.commands.utils import consume_args
-
-
-@consume_args
-def manage(args):
- from django.core.management import ManagementUtility
- utility = ManagementUtility(args)
- utility.execute()
-
-
-def update_migrations():
- """
- Creates schemamigrations for localshop.
- """
- from django.core.management import ManagementUtility
- args = 'manage.py schemamigration localshop --auto'.split(' ')
- utility = ManagementUtility(args)
- utility.execute()
@@ -1,16 +0,0 @@
-from django.core.management import call_command
-from django.conf import settings
-
-from localshop.commands.utils import options, opt
-
-
-@options(
- opt('--interactive', default=False, action='store_true'),
- opt('--delete-ghost-migrations', default=True, dest='delete_ghosts'),
-)
-def upgrade(interactive=True, delete_ghosts=True):
- call_command('syncdb', database='default', interactive=interactive)
-
- if 'south' in settings.INSTALLED_APPS:
- call_command('migrate', database='default', interactive=interactive,
- delete_ghosts=delete_ghosts)
@@ -1,16 +0,0 @@
-from optparse import make_option
-
-opt = make_option
-
-
-def options(*options):
- def wrapped(func):
- func.options = options
- return func
- return wrapped
-
-
-def consume_args(func):
- func.consume_args = True
- return func
-
View
@@ -139,6 +139,7 @@
'djcelery',
'south',
+ 'localshop',
'localshop.apps.packages',
'localshop.apps.permissions',
]
No changes.
No changes.
@@ -0,0 +1,13 @@
+from django.core.management import call_command
+from django.core.management.base import BaseCommand
+from django.conf import settings
+
+
+class Command(BaseCommand):
+
+ def handle(self, *args, **kwargs):
+ call_command('syncdb', database='default', interactive=False)
+
+ if 'south' in settings.INSTALLED_APPS:
+ call_command('migrate', database='default', interactive=False,
+ delete_ghosts=True)

0 comments on commit 9cfa753

Please sign in to comment.