Exemplo n.º 1
0
def loadfixtures(type_='system'):
    """
    load fixtures (system and test).
    usage:
      fab load_fixtures  ->  loads all files which name ends with
                             '_fixtures.json' inside the fixtures folder
                             (except for 'test_fixtures.json')
      fab load_fixtures:test  -> load only the fixtures/test_fixtures.json file
    """
    if type_ == 'test':
        fixtures = ""
        folder = 'fixtures/test'
        for fixture in os.listdir(folder):
            if (fixture.endswith('.json') and
                    fixture != 'contenttypes_fixtures.json'):

                fixtures += "{}/{} ".format(folder, fixture)
        with virtualenv(), env.cd('mootiro_maps'):
            env.run('python manage.py loaddata {} --settings={}'.format(
                fixtures, env.komoo_django_settings))
    else:
        for fixture in os.listdir('fixtures'):
            if fixture.endswith('_fixtures.json'):
                with virtualenv(), env.cd('mootiro_maps'):
                    env.run('python manage.py loaddata fixtures/{} --settings={}'.format(
                        fixture, env.komoo_django_settings))
Exemplo n.º 2
0
def loadfixtures(type_='system'):
    """
    load fixtures (system and test).
    usage:
      fab load_fixtures  ->  loads all files which name ends with
                             '_fixtures.json' inside the fixtures folder
                             (except for 'test_fixtures.json')
      fab load_fixtures:test  -> load only the fixtures/test_fixtures.json file
    """
    if type_ == 'test':
        fixtures = ""
        folder = 'fixtures/test'
        for fixture in os.listdir(folder):
            if (fixture.endswith('.json')
                    and fixture != 'contenttypes_fixtures.json'):

                fixtures += "{}/{} ".format(folder, fixture)
        with virtualenv(), env.cd('mootiro_maps'):
            env.run('python manage.py loaddata {} --settings={}'.format(
                fixtures, env.komoo_django_settings))
    else:
        for fixture in os.listdir('fixtures'):
            if fixture.endswith('_fixtures.json'):
                with virtualenv(), env.cd('mootiro_maps'):
                    env.run(
                        'python manage.py loaddata fixtures/{} --settings={}'.
                        format(fixture, env.komoo_django_settings))
Exemplo n.º 3
0
def install(keystone_path=settings.KEYSTONE_ROOT):
    """Download and install the Back-end and its dependencies."""
    if env.exists(keystone_path[:-1]):
        print 'Already downloaded.'
    else:
        env.run(('git clone https://github.com/ging/keystone.git '
                 '{0}').format(keystone_path))
    with env.cd(keystone_path):
        dependencies = ' '.join(settings.UBUNTU_DEPENDENCIES['keystone'])
        
        env.run('sudo apt-get install {0}'.format(dependencies))
        env.run('sudo cp etc/keystone.conf.sample etc/keystone.conf')
        env.run('sudo python tools/install_venv.py')

        # Uncomment config file
        with env.cd('etc/'):
            env.run(("sudo sed -i "
                "'s/#admin_token=ADMIN/admin_token={0}/g' " 
                "keystone.conf").format(settings.KEYSTONE_ADMIN_TOKEN))
            env.run(("sudo sed -i "
                "'s/#admin_port=35357/admin_port={0}/g' "
                "keystone.conf").format(settings.KEYSTONE_ADMIN_PORT))
            env.run(("sudo sed -i "
                "'s/#public_port=5000/public_port={0}/g' "
                "keystone.conf").format(settings.KEYSTONE_PUBLIC_PORT))
    print 'Done!'
Exemplo n.º 4
0
def django(port=False):
    if not port:
        port = env.komoo_port
    if 'dev' not in env.komoo_django_settings:
        with virtualenv(), env.cd('mootiro_maps'):
                env.run('python manage.py run_gunicorn --workers=2 '
                    '--bind=127.0.0.1:{} --settings={}'.format(
                        port, env.komoo_django_settings)
                    )
    else:
        with virtualenv(), env.cd('mootiro_maps'):
            env.run('python manage.py runserver 0.0.0.0:{} --settings={}'
                    .format(port, env.komoo_django_settings))
Exemplo n.º 5
0
def django(port=False):
    if not port:
        port = env.komoo_port
    if 'dev' not in env.komoo_django_settings:
        with virtualenv(), env.cd('mootiro_maps'):
            env.run('python manage.py run_gunicorn --workers=2 '
                    '--bind=127.0.0.1:{} --settings={}'.format(
                        port, env.komoo_django_settings))
    else:
        with virtualenv(), env.cd('mootiro_maps'):
            env.run(
                'python manage.py runserver 0.0.0.0:{} --settings={}'.format(
                    port, env.komoo_django_settings))
Exemplo n.º 6
0
  def restore_latest_backup(self):
    '''
    Restores a drush archive dump backup of a site.
    '''
    print(cyan('Restoring latest site backup...'))

    # Make the backup directory if for some reason it doesn't already exist.
    if not env.exists(env.node['backup_directory']):
      self.drubs_run('mkdir -p %s' % (env.node['backup_directory']))

    with env.cd(env.node['backup_directory']):

      # Get a list of available backup files sorted with newest first.
      backup_files = self.drubs_run("ls -1 %s | grep -E '%s_%s_[0-9]{4}\-[0-9]{2}\-[0-9]{2}_[0-9]{2}\-[0-9]{2}\-[0-9]{2}\.tar\.gz' | awk '{print \"%s/\" $0}'" % (
        env.node['backup_directory'],
        env.config['project_settings']['project_name'],
        env.node_name,
        env.node['backup_directory'],
      ), capture=True)
      backup_files = backup_files.splitlines()
      backup_files.sort(reverse=True)

      # If backup files exist, restore the latest backup file.
      if len(backup_files) > 0:
        latest_backup_file = backup_files[0]
        if env.exists(latest_backup_file):
          if not env.exists(env.node['site_root']):
            self.drubs_run('mkdir -p %s' % (env.node['site_root']))
          with env.cd(env.node['site_root']):
            self.drush('archive-restore %s --overwrite --destination="%s"' % (
              latest_backup_file,
              env.node['site_root'],
            ))
            self.drush('cc all')
            print(green("Latest backup '%s' restored to '%s' on node '%s'..." % (
              latest_backup_file,
              env.node['site_root'],
              env.node_name,
            )))
        else:
          print(red("Latest backup file does not exist or cannot be read in '%s' on node '%s'..." % (
            env.node['backup_directory'],
            env.node_name,
          )))
      else:
        print(red("No backup files found in '%s' on node '%s'.  Cannot restore..." % (
          env.node['backup_directory'],
          env.node_name,
        )))
Exemplo n.º 7
0
def index_all():
    """ Reindex all objects """
    with virtualenv(), env.cd('mootiro_maps'):
        setup_django()

        from organization.models import Organization
        from komoo_resource.models import Resource
        from need.models import Need
        from community.models import Community
        from authentication.models import User
        from komoo_project.models import Project
        from search.utils import (reset_index, create_mapping, refresh_index,
                                  index_object)

        model_list = [Organization, Resource, Need, Community, User, Project]

        logging.info('Recreating index ... ')
        reset_index()

        logging.info('Create mappings ... ')
        create_mapping()

        logging.info('Indexing each object ... ')
        for model in model_list:
            for obj in model.objects.all():
                index_object(obj)

        logging.info('refreshing index ... ')
        refresh_index()

        logging.info('ES indexes rebuilt.')
Exemplo n.º 8
0
def index_all():
    """ Reindex all objects """
    with virtualenv(), env.cd("mootiro_maps"):
        setup_django()

        from organization.models import Organization
        from komoo_resource.models import Resource
        from need.models import Need
        from community.models import Community
        from authentication.models import User
        from komoo_project.models import Project
        from search.utils import reset_index, create_mapping, refresh_index, index_object

        model_list = [Organization, Resource, Need, Community, User, Project]

        logging.info("Recreating index ... ")
        reset_index()

        logging.info("Create mappings ... ")
        create_mapping()

        logging.info("Indexing each object ... ")
        for model in model_list:
            for obj in model.objects.all():
                index_object(obj)

        logging.info("refreshing index ... ")
        refresh_index()

        logging.info("ES indexes rebuilt.")
Exemplo n.º 9
0
def compilemessages():
    """
    compile messages file
    """
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py compilemessages --settings={}'
                .format(env.komoo_django_settings))
Exemplo n.º 10
0
def stop():
    '''Stop remote application server.'''
    _setup_supervisor()
    with virtualenv(), env.cd('mootiro_maps'):
        env.run(
            'supervisorctl -c {dir}/supervisor/{env}.conf stop {env}:'.format(
                env=env.komoo_env, dir=env.komoo_project_folder))
Exemplo n.º 11
0
  def drush_sql(self, sql):
    '''
    Runs a drush-sql command with the provided sql query.

    This function was historically necessary to be able to write one query that
    could be escaped properly in order to be performed successfully on both
    local and remote nodes.  Between python, fabric, shell, and drush, escaping
    is difficult to grok.

    This function is included as-is for now to accomodate already written config
    files for existing projects, but it should be rewritten when escaping can
    be properly understood.  (Encoding queries with base64 in transit may be
    helpful.)
    '''
    if env.host_is_local:
      sql = sql.replace('"', '\\"')
    else:
      sql = sql.replace('"', '\\\\\"')
    options = str()
    if env.verbose:
      options += ' -v'
    if env.debug:
      options += ' -d'
    with env.cd(env.node['site_root']):
      self.drubs_run(r'drush sql-query "%s" %s -y' % (sql, options))
Exemplo n.º 12
0
def compilemessages():
    """
    compile messages file
    """
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py compilemessages --settings={}'.format(
            env.komoo_django_settings))
Exemplo n.º 13
0
Arquivo: git.py Projeto: Frojd/Fabrik
def copy():
    branch = None
    repro_url = None

    if "repro_url" in env:
        repro_url = env.repro_url

    if not repro_url:
        sys.exit("repro_url is missing in configuration")

    if "branch" in env:
        branch = env.branch

    if not branch and gitext.get_reverse_path():
        path = gitext.get_reverse_path()
        branch = gitext.get_git_branch(path)

    if not branch:
        logger.warn("Git branch not set, using master instead")
        branch = "master"

    with apply_settings(), env.cd(env.app_path):
        env.run("git clone  --depth 1 -b %(branch)s %(repro)s %(path)s" % {
            "branch": branch,
            "repro": repro_url,
            "path": env.current_release,
        })
Exemplo n.º 14
0
def install(horizon_path=settings.HORIZON_ROOT):
    """Download and install the Front-end and its dependencies."""
    if os.path.isdir(horizon_path[:-1]):
        print 'Already downloaded.'
    else:
        env.run('git clone https://github.com/ging/horizon.git \
            {0}'.format(horizon_path))

    with env.cd(horizon_path):
        dependencies = ' '.join(settings.UBUNTU_DEPENDENCIES['horizon'])
        env.run('sudo apt-get install {0}'.format(dependencies))
        env.run('sudo python tools/install_venv.py')

    path = horizon_path + '/openstack_dashboard/local/'
    class Template(string.Template):
        delimiter = '$$'
    template_settings = Template(open(path + 'local_settings.py.example').read())
    out_file = open(path + "local_settings.py", "w")
    out_file.write(
        template_settings.substitute({
            'IDM_NAME': settings.IDM_USER_CREDENTIALS['username'],
            'IDM_PASS': settings.IDM_USER_CREDENTIALS['password'],
            'IDM_PROJECT': settings.IDM_USER_CREDENTIALS['project'],
            'KEYSTONE_ADDRESS': settings.CONTROLLER_INTERNAL_ADDRESS,
            'KEYSTONE_PUBLIC_PORT':settings.KEYSTONE_PUBLIC_PORT,
        }))
    out_file.close()
Exemplo n.º 15
0
Arquivo: git.py Projeto: Frojd/Fabrik
def copy():
    branch = None
    repro_url = None

    if "repro_url" in env:
        repro_url = env.repro_url

    if not repro_url:
        sys.exit("repro_url is missing in configuration")

    if "branch" in env:
        branch = env.branch

    if not branch and gitext.get_reverse_path():
        path = gitext.get_reverse_path()
        branch = gitext.get_git_branch(path)

    if not branch:
        logger.warn("Git branch not set, using master instead")
        branch = "master"

    with apply_settings(), env.cd(env.app_path):
        env.run("git clone  --depth 1 -b %(branch)s %(repro)s %(path)s" % {
            "branch": branch,
            "repro": repro_url,
            "path": env.current_release,
        })
Exemplo n.º 16
0
def dev_server(address=settings.HORIZON_DEV_ADDRESS,
               horizon_path=settings.HORIZON_ROOT):
    """Run horizon server for development purposes"""
    with env.cd(horizon_path):
        env.run(('sudo tools/with_venv.sh python manage.py runserver '
                 '{0}').format(address))
        
Exemplo n.º 17
0
def _setup_supervisor():
    # make sure supervisord is running
    sock_file = ('{}/supervisor/supervisor.sock').format(
        env.komoo_project_folder)
    if not exists(sock_file):
        with virtualenv(), env.cd('mootiro_maps'):
            env.run('supervisord -c {}/supervisor/{}.conf'.format(
                env.komoo_project_folder, env.komoo_env))
Exemplo n.º 18
0
def _setup_supervisor():
    # make sure supervisord is running
    sock_file = ('{}/supervisor/supervisor.sock'
                 ).format(env.komoo_project_folder)
    if not exists(sock_file):
        with virtualenv(), env.cd('mootiro_maps'):
            env.run('supervisord -c {}/supervisor/{}.conf'.format(
                env.komoo_project_folder, env.komoo_env))
Exemplo n.º 19
0
def initial_revisions():
    """
    load initial revisions for django-revisions module
    should run only once when installed/or when loaded a new app/model
    """
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py createinitialrevisions --settings={}'
                .format(env.komoo_django_settings))
Exemplo n.º 20
0
def initial_revisions():
    """
    load initial revisions for django-revisions module
    should run only once when installed/or when loaded a new app/model
    """
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py createinitialrevisions --settings={}'.format(
            env.komoo_django_settings))
Exemplo n.º 21
0
def makemessages(lang='pt_BR'):
    """create translations messages file"""
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py makemessages --all -l {} --settings={}'.format(
            lang, env.komoo_django_settings))
        env.run('python manage.py makemessages'
                ' --all -d djangojs -l {} --settings={}'.format(
                    lang, env.komoo_django_settings))
Exemplo n.º 22
0
def virtualenv():
    if not 'komoo_activate' in env or not 'komoo_project_folder' in env:
        abort('Missing remote destination.\n\n'
              'Usage: fab remote:<env> <command>')
    env.komoo_using_virtualenv = True
    activate = env.komoo_activate
    with env.cd(env.komoo_project_folder), prefix(activate):
        yield
Exemplo n.º 23
0
def virtualenv():
    if not 'komoo_activate' in env or not 'komoo_project_folder' in env:
        abort('Missing remote destination.\n\n'
              'Usage: fab remote:<env> <command>')
    env.komoo_using_virtualenv = True
    activate = env.komoo_activate
    with env.cd(env.komoo_project_folder), prefix(activate):
        yield
Exemplo n.º 24
0
def makemessages(lang='pt_BR'):
    """create translations messages file"""
    with virtualenv(), env.cd('mootiro_maps'):
        env.run(
            'python manage.py makemessages --all -l {} --settings={}'.format(
                lang, env.komoo_django_settings))
        env.run('python manage.py makemessages'
                ' --all -d djangojs -l {} --settings={}'.format(
                    lang, env.komoo_django_settings))
Exemplo n.º 25
0
 def enable(self):
   '''
   Enables a site by disabling Drupal's maintenance mode.
   '''
   print(cyan('Enabling site...'))
   with env.cd(env.node['site_root']):
     self.drush('vset maintenance_mode 0')
     self.drush('cc all')
   self.print_elapsed_time()
Exemplo n.º 26
0
 def secure(self):
   '''
   Performs some security best-practices.
   '''
   print(cyan('Performing security practices...'))
   with env.cd(env.node['site_root']):
     # Remove all txt files in site root (except robots.txt)
     self.drubs_run('ls | grep .txt | grep -v "robots.txt" | xargs rm -rf')
     # Ensure restrictive settings on settings.php
     self.drubs_run('chmod 444 sites/default/settings.php')
Exemplo n.º 27
0
 def drush(self, cmd):
   '''
   Runs the specified drush command.
   '''
   if env.verbose:
     cmd += ' -v'
   if env.debug:
     cmd += ' -d'
   with env.cd(env.node['site_root']):
     self.drubs_run('drush %s -y' % (cmd))
Exemplo n.º 28
0
def update(install_path=None):
    if not install_path:
        install_path = paths.get_source_path(env.current_release)

    flags = default_flags

    if "composer_flags" in env:
        flags = env.composer_flags

    with(env.cd(install_path)):
        env.run("php composer.phar install {}".format(" ".join(flags)))
Exemplo n.º 29
0
Arquivo: d7.py Projeto: komlenic/drubs
def pre(*args, **kwargs):
  with env.cd(env.node['site_root']):
    print(cyan("Beginning pre-install configuration tasks for project..."))
    '''
    Enter any pre-install configuration tasks below.
    Typically you will not need to execute tasks prior to installing.

    Any tasks specified here will only be executed prior to installing, and will
    not be executed at any time during update.
    '''
    print(cyan("End of pre-install configuration tasks..."))
Exemplo n.º 30
0
Arquivo: d7.py Projeto: komlenic/drubs
def post(*args, **kwargs):
  with env.cd(env.node['site_root']):
    print(cyan("Beginning post-install configuration tasks for project..."))
    '''
    Enter any post-install configuration tasks below (examples provided).

    Typically this is where you will enable and disable modules/themes/etc.
    Generally you will be using drubs_run(), drush(), and drush_sql() functions.

    Some examples:

    drush('vset [variable_name] [variable_value]')
    drubs_run('cp somefile someplace')
    drush('en [module_name]')
    drush('en [module1_name,module2_name,module3_name]')
    drush('dis [module]')
    drush_sql(<triple single quotes here>UPDATE some_table...<triple single quotes here>)

    See http://drush.ws/ for more examples of drush commands you may wish to
    use.

    Almost always, you will want to execute these postinstall tasks after
    installing AND after updating a project.  In rare circumstances, you may
    need a task to ONLY be executed during install, or only during update.
    The appropriate sections for each of these types of tasks are below.
    '''
    # Regular tasks to be executed during install AND update below this line.

    drush('en module_filter,admin_menu,admin_menu_toolbar,ctools,views,wysiwyg,libraries')
    drush('dis toolbar,overlay')

    # Set error reporting in Drupal.  Drupal 7 overrides whatever
    # error_reporting that is set in php.ini with E_ALL, then handles reporting
    # levels inside Drupal with this setting.  Values:
    # 0 = none, 1 = errors and warnings, 2 = all messages.  Production
    # environments should use 0.
    drush('vset error_level 2')

    # Revert all features.  Remember that "features revert" is code -> database,
    # and "features update" is database -> code.  You may wish to uncomment this
    # line if the features module is enabled in this project.
    # drush('features-revert-all')

    if env.command in ('install_project', 'install'):
      # Tasks to be executed only on install below this line.
      pass # Replace/remove this line if adding other code.

    elif env.command in ('update_project', 'update'):
      # Tasks to be executed only on update below this line.
      pass # Replace/remove this line if adding other code.

    print(cyan("End of post-install configuration tasks..."))
Exemplo n.º 31
0
def database_create(keystone_path=settings.KEYSTONE_ROOT, verbose=True):
    add_verbose = '-v' if verbose else ''
    with env.cd(keystone_path):
        env.run(('sudo tools/with_venv.sh bin/keystone-manage {v}'
            ' db_sync').format(v=add_verbose))
        env.run(('sudo tools/with_venv.sh bin/keystone-manage {v}'
            ' db_sync --extension endpoint_filter').format(v=add_verbose))
        env.run(('sudo tools/with_venv.sh bin/keystone-manage {v}'
            ' db_sync --extension=oauth2').format(v=add_verbose))
        env.run(('sudo tools/with_venv.sh bin/keystone-manage {v}'
            ' db_sync --extension=roles').format(v=add_verbose))
        env.run(('sudo tools/with_venv.sh bin/keystone-manage {v}'
            ' db_sync --extension=user_registration').format(v=add_verbose))
Exemplo n.º 32
0
def start():
    '''Start remote application server.'''
    _setup_supervisor()
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('supervisorctl -c {dir}/supervisor/{env}.conf start {env}:'
                .format(env=env.komoo_env, dir=env.komoo_project_folder))

    # maintenance page goes down
    #sudo('a2dissite {komoo_maintenance_apache_conf}; '
    #     'a2ensite {komoo_apache_conf}; '
    #     'service apache2 reload'.format(**env))

    print yellow('Success, but it may take 1 minute for the server to go up.')
Exemplo n.º 33
0
  def site_bootstrapped(self):
    '''
    Determines if a bootstrapped drupal site exists.

    Returns 1 if the site is bootstrapped, 0 otherwise.
    '''
    if not env.exists(env.node['site_root']):
      return 0
    with env.cd(env.node['site_root']):
      result = self.drubs_run('drush status --fields=bootstrap --no-field-labels', capture=True)
      if (result.find('Successful') != -1):
        return 1
      else:
        return 0
Exemplo n.º 34
0
def start():
    '''Start remote application server.'''
    _setup_supervisor()
    with virtualenv(), env.cd('mootiro_maps'):
        env.run(
            'supervisorctl -c {dir}/supervisor/{env}.conf start {env}:'.format(
                env=env.komoo_env, dir=env.komoo_project_folder))

    # maintenance page goes down
    #sudo('a2dissite {komoo_maintenance_apache_conf}; '
    #     'a2ensite {komoo_apache_conf}; '
    #     'service apache2 reload'.format(**env))

    print yellow('Success, but it may take 1 minute for the server to go up.')
Exemplo n.º 35
0
def loadjson(fixture_file=None):
    """
    load a single fixture file
    usage:
        fab loaddata:fixture_file_path -> loads the given fixture file to db
    """
    if fixture_file:
        with virtualenv(), env.cd('mootiro_maps'):
            env.run('python manage.py loaddata {} --settings={}'.format(
                fixture_file, env.komoo_django_settings))
    else:
        logging.info("""
        Please provide a fixture file
        usage:
          fab loaddata:fixture_file_path -> loads the given fixture file to db
        """)
Exemplo n.º 36
0
def loadjson(fixture_file=None):
    """
    load a single fixture file
    usage:
        fab loaddata:fixture_file_path -> loads the given fixture file to db
    """
    if fixture_file:
        with virtualenv(), env.cd('mootiro_maps'):
            env.run('python manage.py loaddata {} --settings={}'.format(
                fixture_file, env.komoo_django_settings))
    else:
        logging.info("""
        Please provide a fixture file
        usage:
          fab loaddata:fixture_file_path -> loads the given fixture file to db
        """)
Exemplo n.º 37
0
def app(
        apps=" ".join([
            'community', 'need', 'organization', 'proposal', 'komoo_resource',
            'investment', 'main', 'authentication', 'moderation']),
        recreate_db=False):
    """Run application tests"""

    warn('Some tests are broken and should be fixed.')

    # TODO: Hard coded values are evil. Make db name configurable.
    if recreate_db:
        env.run('dropdb test_mootiro_maps')
    else:
        logging.info("Reusing old last test DB...")
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('REUSE_DB=1 python manage.py test {} --settings={} --verbosity=1'
                .format(apps, env.komoo_django_settings))
Exemplo n.º 38
0
def app(apps=" ".join([
    'community', 'need', 'organization', 'proposal', 'komoo_resource',
    'investment', 'main', 'authentication', 'moderation'
]),
        recreate_db=False):
    """Run application tests"""

    warn('Some tests are broken and should be fixed.')

    # TODO: Hard coded values are evil. Make db name configurable.
    if recreate_db:
        env.run('dropdb test_mootiro_maps')
    else:
        logging.info("Reusing old last test DB...")
    with virtualenv(), env.cd('mootiro_maps'):
        env.run(
            'REUSE_DB=1 python manage.py test {} --settings={} --verbosity=1'.
            format(apps, env.komoo_django_settings))
Exemplo n.º 39
0
 def create_backup(self):
   '''
   Creates a drush archive dump backup of a site.
   '''
   if self.site_bootstrapped():
     print(cyan('Creating site backup...'))
     with env.cd(env.node['site_root']):
       if not env.exists(env.node['backup_directory']):
         self.drubs_run('mkdir -p %s' % (env.node['backup_directory']))
       self.drush('cc all')
       self.drush('archive-dump --destination="%s/%s_%s_%s.tar.gz" --preserve-symlinks' % (
         env.node['backup_directory'],
         env.config['project_settings']['project_name'],
         env.node_name,
         time.strftime("%Y-%m-%d_%H-%M-%S"),
       ))
   else:
     print(cyan('No pre-existing properly-functioning site found.  Skipping backup...'))
Exemplo n.º 40
0
 def provision(self):
   '''
   Creates database and site root.
   '''
   print(cyan('Creating database...'))
   self.drubs_run('mysql -h%s -u%s -p%s -e "DROP DATABASE IF EXISTS %s;CREATE DATABASE %s;"' % (
     env.node['db_host'],
     env.node['db_user'],
     env.node['db_pass'],
     env.node['db_name'],
     env.node['db_name'],
   ))
   print(cyan('Creating site root location...'))
   if env.exists(env.node['site_root'] + '/sites/default'):
     with env.cd(env.node['site_root']):
       self.drubs_run('chmod u+w sites/default')
       self.drubs_run('ls -A | grep -v ".htaccess.drubs" | xargs rm -rf')
   self.drubs_run('mkdir -p %s' % (env.node['site_root']))
Exemplo n.º 41
0
def urls():
    """Creates a javascript file containing urls"""
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py js_urls --settings={}'.format(
            env.komoo_django_settings))

    # remove trailing interrogations
    logging.info('removing trailing "?" from urls')
    import os
    s = ''
    with open(
            os.path.abspath(
                './mootiro_maps/static/lib/django-js-utils/dutils.conf.urls.js'
            ), 'r') as f:
        s = f.read()
        s = s.replace('?', '')
    with open(
            os.path.abspath(
                './mootiro_maps/static/lib/django-js-utils/dutils.conf.urls.js'
            ), 'w') as f:
        f.write(s)
Exemplo n.º 42
0
 def site_install(self):
   '''
   Runs drush site install.
   '''
   db_url = 'mysql://%s:%s@%s/%s' % (
     env.node['db_user'],
     env.node['db_pass'],
     env.node['db_host'],
     env.node['db_name'],
   )
   with env.cd(env.node['site_root']):
     print(cyan('Beginning drush site-install...'))
     self.drush('si --account-name="%s" --account-pass="******" --account-mail="%s" --site-mail="%s" --db-url="%s" --site-name="%s"' % (
       env.node['account_name'],
       env.node['account_pass'],
       env.node['account_mail'],
       env.node['site_mail'],
       db_url,
       env.node['site_name'],
     ))
     self.drubs_run('chmod 775 sites/default/files')
Exemplo n.º 43
0
def urls():
    """Creates a javascript file containing urls"""
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py js_urls --settings={}'.format(
            env.komoo_django_settings))

    # remove trailing interrogations
    logging.info('removing trailing "?" from urls')
    import os
    s = ''
    with open(
            os.path.abspath(
            './mootiro_maps/static/lib/django-js-utils/dutils.conf.urls.js'),
            'r') as f:
        s = f.read()
        s = s.replace('?', '')
    with open(
            os.path.abspath(
            './mootiro_maps/static/lib/django-js-utils/dutils.conf.urls.js'),
            'w') as f:
        f.write(s)
Exemplo n.º 44
0
def sync_remote_to_local(force="no"):
    """
    Replace your remote db with your local

    Example:
        sync_remote_to_local:force=yes
    """

    assert "local_wp_dir" in env, "Missing local_wp_dir in env"

    if force != "yes":
        message = "This will replace your local database with your "\
            "remote, are you sure [y/n]"
        answer = prompt(message, "y")

        if answer != "y":
            logger.info("Sync stopped")
            return

    init_tasks()  # Bootstrap fabrik

    remote_file = "sync_%s.sql" % int(time.time()*1000)
    remote_path = "/tmp/%s" % remote_file

    with env.cd(paths.get_current_path()):
        env.run("wp db export %s" % remote_path)

    local_wp_dir = env.local_wp_dir
    local_path = "/tmp/%s" % remote_file

    # Download sync file
    get(remote_path, local_path)

    with lcd(local_wp_dir):
        elocal("wp db import %s" % local_path)

    # Cleanup
    env.run("rm %s" % remote_path)
    elocal("rm %s" % local_path)
Exemplo n.º 45
0
def sync_remote_to_local(force="no"):
    """
    Replace your remote db with your local

    Example:
        sync_remote_to_local:force=yes
    """

    assert "local_wp_dir" in env, "Missing local_wp_dir in env"

    if force != "yes":
        message = "This will replace your local database with your "\
            "remote, are you sure [y/n]"
        answer = prompt(message, "y")

        if answer != "y":
            logger.info("Sync stopped")
            return

    init_tasks()  # Bootstrap fabrik

    remote_file = "sync_%s.sql" % int(time.time() * 1000)
    remote_path = "/tmp/%s" % remote_file

    with env.cd(paths.get_current_path()):
        env.run("wp db export %s" % remote_path)

    local_wp_dir = env.local_wp_dir
    local_path = "/tmp/%s" % remote_file

    # Download sync file
    get(remote_path, local_path)

    with lcd(local_wp_dir):
        elocal("wp db import %s" % local_path)

    # Cleanup
    env.run("rm %s" % remote_path)
    elocal("rm %s" % local_path)
Exemplo n.º 46
0
def deploy():
    '''
    Pull latest image and restart containers
    '''
    images = env.image
    compose_file = env.compose_files[0]

    if not isinstance(env.image, list):
        images = [env.image]

    with env.cd(env.path):
        # Update images
        for image in images:
            repository = image.get('repository')
            release_tag = image.get('tag', 'latest')

            # Trigger before deploy hooks
            ext.dispatch("before_deploy", image)

            # Pull latest repro changes
            env.run("docker pull {0}:{1}".format(repository['url'],
                                                 release_tag))

        # Stop all containers
        env.run("docker-compose -f {0} -p {1} stop".format(
            compose_file, env.project))
        # Start all containers
        env.run("docker-compose -f {0} -p {1} up -d".format(
            compose_file, env.project))

        # Trigger after deploy hooks
        for image in images:
            ext.dispatch("after_deploy", image)

    # Remove dangeling images
    env.run("docker images --quiet --filter=dangling=true"
            " | xargs --no-run-if-empty docker rmi")
Exemplo n.º 47
0
def install(install_path=None):
    if not install_path:
        install_path = paths.get_source_path(env.current_release)

    with(env.cd(install_path)):
        env.run("curl -sS https://getcomposer.org/installer | php")
Exemplo n.º 48
0
def _migrate():
    with (env.cd(paths.get_source_path(env.current_release))):
        env.run("python manage.py migrate --noinput")
Exemplo n.º 49
0
def _collectstatic():
    with (env.cd(paths.get_source_path(env.current_release))):
        env.run("python manage.py collectstatic --noinput", warn_only=True)
Exemplo n.º 50
0
def shell():
    """runs shell with the django env loaded"""
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py shell --settings={}'.format(
            env.komoo_django_settings))
Exemplo n.º 51
0
def compile_coffee():
    """Compiles coffeescript to javascript"""
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('../scripts/coffee_compiler.js --all')
Exemplo n.º 52
0
def compile_sass():
    """Compiles sass to css"""
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('sass --update ./')
Exemplo n.º 53
0
def requirements():
    with virtualenv_cm(), env.cd('mootiro_maps'):
        env.run('pip install -r settings/requirements.txt')
Exemplo n.º 54
0
def collectstatic():
    '''Runs static files collector'''
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py collectstatic --settings={}'.format(
            env.komoo_django_settings))
Exemplo n.º 55
0
Arquivo: node.py Projeto: Frojd/Fabrik
def deploy():
    envfile.symlink_env()

    with (env.cd(paths.get_source_path(env.current_release))):
        npm.install()
Exemplo n.º 56
0
def sync(create_superuser=""):
    """Runs syncdb (with no input flag by default)"""
    noinput = "" if create_superuser else "--noinput"
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py syncdb {} --settings={}'.format(
            noinput, env.komoo_django_settings))
Exemplo n.º 57
0
def after_deploy():
    with (env.cd(paths.get_current_path())):
        forever.restart()
Exemplo n.º 58
0
def dumpjson():
    """Dump DB data, for backup purposes """
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py dumpdata --settings={} > backupdb_{}.json'.
                format(env.komoo_django_settings,
                       datetime.now().strftime('%Y_%m_%d_%H_%M')))
Exemplo n.º 59
0
def shell():
    """Launches Django interactive shell"""
    with virtualenv(), env.cd('mootiro_maps'):
        env.run('python manage.py shell --settings={}'.format(
            env.komoo_django_settings))