Commits

Docta Jay  committed 19f8393

Still broken, so be careful

  • Participants
  • Parent commits acc5cf7

Comments (0)

Files changed (1)

File djaboto/management/commands/checkmix.py

 from subprocess import check_call
 from getpass import getuser
 from socket import gethostname
+from fabric import api as fab_api
+from fabric.contrib.files import exists as fab_exists
 
 class Command(BaseCommand):
     help = ("Check the status of your soupmix.")
     ###TODO: Add segment to generate, as well as source, the local database environment variables.
     DIR_BIN_OLD = os.path.join(DIR_PROJECT, args.site_name, 'bin')
     print DIR_BIN_OLD
-    DIR_BIN_NEW = os.path.join('/home', getuser(), '.soupmix', args.site_name)
-    if not os.path.exists(DIR_BIN_NEW):
-        print DIR_BIN_NEW
-        check_call(['mkdir', '-p', DIR_BIN_NEW])
-        check_call(['mv', '%s/grape_data' % DIR_BIN_OLD, DIR_BIN_NEW])
-        check_call(['mv', '%s/nymph_data' % DIR_BIN_OLD, DIR_BIN_NEW])
-    localhost_datafile = os.path.join(DIR_BIN_NEW, '%s_data' % gethostname())
+    DIR_DATACONF_NEW = os.path.join('/home', getuser(), '.soupmix', args.site_name)
+    if not os.path.exists(DIR_DATACONF_NEW):
+        print DIR_DATACONF_NEW
+        check_call(['mkdir', '-p', DIR_DATACONF_NEW])
+        check_call(['mv', '%s/grape_data' % DIR_BIN_OLD, DIR_DATACONF_NEW])
+        check_call(['mv', '%s/nymph_data' % DIR_BIN_OLD, DIR_DATACONF_NEW])
+    localhost_datafile = os.path.join(DIR_DATACONF_NEW, '%s_data' % gethostname())
+    fab_api.env.host_string = 'localhost'
     if os.path.exists(localhost_datafile):
         print localhost_datafile
         print os.path.exists(localhost_datafile)
-        check_call(['source', localhost_datafile])
+        with fab_api.settings(
+                fab_api.cd('~/django/%s' % args.site_name),
+                fab_api.prefix('source ~/django/python/bin/activate'),
+                fab_api.prefix('source %s' % localhost_datafile)):
+
+            # Update the database and link all media files
+            fab_api.run('python manage.py syncdb --noinput --verbosity=0')
+            fab_api.local('python manage.py migrate --verbosity=0')
     else:
         raise Exception("Create a local database config file for the site at %s/%s_data" % (DIR_BIN_NEW, gethostname()))
 
-    print '...running syncdb via manage.py'
-    check_call(['./manage.py','syncdb'])
+    DIR_BIN_NEW = os.path.join(DIR_PROJECT, 'bin')
+    print DIR_BIN_NEW
+    check_call(['mv', DIR_BIN_OLD, DIR_BIN_NEW])
 
-    print '...running migrate via manage.py with no input'
-    check_call(['./manage.py','migrate','--noinput'])
+    with fab_api.settings(
+            fab_api.cd('~/django/%s' % args.site_name),
+            fab_api.prefix('source ~/django/python/bin/activate'),
+            fab_api.prefix('source %s' % localhost_datafile)):
 
-    print '...running collectstatic -l via manage.py with no input'
-    check_call(['./manage.py','collectstatic','-l','--noinput'])
+        print '...running syncdb via manage.py'
+        check_call(['./manage.py','syncdb'])
+
+        print '...running migrate via manage.py with no input'
+        check_call(['./manage.py','migrate','--noinput'])
+
+        print '...running collectstatic -l via manage.py with no input'
+        check_call(['./manage.py','collectstatic','-l','--noinput'])
 
     print '...fixing static directory permissions'
     check_call(['sudo', 'chown', '-R', ':www-data', DIR_STATIC])