Ejemplo n.º 1
0
def pushapp(webapp, webapp_path, sha1):
    remote_location = '%s:%s' % (fab.env.host_string, webapp_path)
    # Directories under htdocs/ are not under source control
    # except for static/css and static/js.
    shell_command([
        '/usr/bin/rsync',
        '--copy-links',
        '--exclude',
        '.git',
        '--exclude',
        'htdocs/*',
        '--exclude',
        'img/',  #'--exclude', '*.pyc',
        '--exclude',
        '.DS_Store',
        '--exclude',
        '*~',
        '-pthrRvz',
        '--rsync-path',
        '/usr/bin/rsync',
        '--delete',
        '.',
        './htdocs/static/css',
        './htdocs/static/js',
        remote_location
    ])
    upload(remote_location)
    LOGGER.info("pushapp %s %s %s", webapp, fab.env.host_string, sha1)
Ejemplo n.º 2
0
def package_theme(app_name, install_dir=None, build_dir=None,
                  excludes=None, includes=None):
    #pylint:disable=too-many-locals
    if not build_dir:
        build_dir = os.path.join(os.getcwd(), 'build')
    if not install_dir:
        install_dir = os.getcwd()
    build_dir = os.path.normpath(os.path.abspath(build_dir))
    install_dir = os.path.normpath(os.path.abspath(install_dir))
    templates_dest = os.path.join(build_dir, app_name, 'templates')
    resources_dest = os.path.join(build_dir, app_name, 'public')
    # override STATIC_URL to prefix APP_NAME.
    orig_static_url = django_settings.STATIC_URL
    if (app_name != django_settings.APP_NAME
        and not django_settings.STATIC_URL.startswith('/' + app_name)):
        django_settings.STATIC_URL = '/' + app_name + orig_static_url
    if not os.path.exists(templates_dest):
        os.makedirs(templates_dest)

    candidate_dir = os.path.join(
        settings.MULTITIER_THEMES_DIR, app_name, 'templates')
    if not os.path.isdir(candidate_dir):
        template_dirs = django_settings.TEMPLATE_DIRS
    else:
        template_dirs = [candidate_dir]
    for template_dir in template_dirs:
        # The first TEMPLATE_DIRS usually contains the most specialized
        # templates (ie. the ones we truely want to install).
        if (templates_dest
            and not os.path.samefile(template_dir, templates_dest)):
            install_templates(template_dir, templates_dest,
                excludes=excludes, includes=includes, app_name=app_name)

    # Copy local resources (not under source control) to resources_dest.
    excludes = ['--exclude', '*~', '--exclude', '.DS_Store']
    app_static_root = django_settings.STATIC_ROOT
    if not app_static_root.endswith(django_settings.STATIC_URL):
        static_url_parts = []
        for part in django_settings.STATIC_URL.split('/'):
            if part:
                static_url_parts += [part]
        if static_url_parts[0] == django_settings.APP_NAME:
            static_url = '/'.join(static_url_parts[1:])
        else:
            static_url = django_settings.STATIC_URL[1:]
        app_static_root = os.path.join(app_static_root, static_url)
    if app_static_root[-1] == os.sep:
        # If we have a trailing '/', rsync will copy the content
        # of the directory instead of the directory itself.
        app_static_root = app_static_root[:-1]
    shell_command(['/usr/bin/rsync']
        + excludes + ['-az', '--safe-links', '--rsync-path', '/usr/bin/rsync']
        + [app_static_root, resources_dest])
    zip_path = os.path.join(install_dir, '%s.zip' % app_name)
    with zipfile.ZipFile(zip_path, 'w') as zip_file:
        fill_package(zip_file, build_dir, prefix=app_name)
    return zip_path
Ejemplo n.º 3
0
 def handle(self, *args, **options):
     ResourceCommand.handle(self, *args, **options)
     excludes = ['--exclude=%s' % item for item in ['.git']]
     prefix = settings.MULTITIER_RESOURCES_ROOT
     for key in list_local([django_settings.STATIC_ROOT], prefix):
         filename = key['Key']
         mtime = key['LastModified']
         basename = os.path.basename(filename)
         try:
             shell_command(['grep', '-rq'] + excludes + [basename, '.'])
             found = 'Y'
         except subprocess.CalledProcessError:
             found = 'N'
         sys.stdout.write('%s %s %s\n' % (found, mtime, filename))
Ejemplo n.º 4
0
def pushapp(webapp, webapp_path, sha1):
    remote_location = '%s:%s' % (fab.env.host_string, webapp_path)
    # Directories under htdocs/ are not under source control
    # except for static/css and static/js.
    shell_command([
            '/usr/bin/rsync',
            '--copy-links', '--exclude', '.git', '--exclude', 'htdocs/*',
            '--exclude', 'img/', #'--exclude', '*.pyc',
            '--exclude', '.DS_Store', '--exclude', '*~',
            '-pthrRvz', '--rsync-path', '/usr/bin/rsync', '--delete',
            '.', './htdocs/static/css', './htdocs/static/js',
            remote_location])
    upload(remote_location)
    LOGGER.info("pushapp %s %s %s", webapp, fab.env.host_string, sha1)
 def handle(self, *args, **options):
     ResourceCommand.handle(self, *args, **options)
     excludes = ['--exclude=%s' % item for item in ['.git']]
     prefix = settings.MULTITIER_RESOURCES_ROOT
     for key in list_local([django_settings.STATIC_ROOT], prefix):
         filename = key['Key']
         mtime = key['LastModified']
         basename = os.path.basename(filename)
         try:
             shell_command(
               ['grep', '-rq'] + excludes + [basename, '.'])
             found = 'Y'
         except subprocess.CalledProcessError:
             found = 'N'
         sys.stdout.write('%s %s %s\n' % (found, mtime, filename))
Ejemplo n.º 6
0
def fetch_changes(repo_path, up_commit='master'):
    """
    Fetch latest changes from stage and touch .timestamp
    if any python sources have been modified.
    """
    last_up_commit = None
    prevcwd = os.getcwd()
    try:
        gitexe = 'git'
        os.chdir(repo_path)
        old_sources_timestamp = sources_latest_timestamp('.')
        shell_command([gitexe, 'pull'])
        last_up_commit = subprocess.check_output(['git', 'rev-parse', 'HEAD'])
        shell_command([gitexe, 'checkout', up_commit])
        up_commit = subprocess.check_output(['git', 'rev-parse', 'HEAD'])
        new_sources_timestamp = sources_latest_timestamp('.')
        if old_sources_timestamp < new_sources_timestamp:
            with open('.timestamp', 'w') as up_commit_file:
                up_commit_file.write(up_commit)
    finally:
        os.chdir(prevcwd)
    return last_up_commit, up_commit
Ejemplo n.º 7
0
def fetch_changes(repo_path, up_commit='master'):
    """
    Fetch latest changes from stage and touch .timestamp
    if any python sources have been modified.
    """
    last_up_commit = None
    prevcwd = os.getcwd()
    try:
        gitexe = 'git'
        os.chdir(repo_path)
        old_sources_timestamp = sources_latest_timestamp('.')
        shell_command([gitexe, 'pull'])
        last_up_commit = subprocess.check_output(['git', 'rev-parse', 'HEAD'])
        shell_command([gitexe, 'checkout', up_commit])
        up_commit = subprocess.check_output(['git', 'rev-parse', 'HEAD'])
        new_sources_timestamp = sources_latest_timestamp('.')
        if old_sources_timestamp < new_sources_timestamp:
            with open('.timestamp', 'w') as up_commit_file:
                up_commit_file.write(up_commit)
    finally:
        os.chdir(prevcwd)
    return last_up_commit, up_commit
Ejemplo n.º 8
0
def syncapp(webapp_path):
    shell_command(['ssh', fab.env.host_string,
        '/usr/local/bin/dpull', webapp_path])
Ejemplo n.º 9
0
def package_theme(app_name,
                  install_dir=None,
                  build_dir=None,
                  excludes=None,
                  includes=None):
    #pylint:disable=too-many-locals
    if not build_dir:
        build_dir = os.path.join(os.getcwd(), 'build')
    if not install_dir:
        install_dir = os.getcwd()
    build_dir = os.path.normpath(os.path.abspath(build_dir))
    install_dir = os.path.normpath(os.path.abspath(install_dir))
    templates_dest = os.path.join(build_dir, app_name, 'templates')
    resources_dest = os.path.join(build_dir, app_name, 'public')
    # override STATIC_URL to prefix APP_NAME.
    orig_static_url = django_settings.STATIC_URL
    if (app_name != django_settings.APP_NAME
            and not django_settings.STATIC_URL.startswith('/' + app_name)):
        django_settings.STATIC_URL = '/' + app_name + orig_static_url
    if not os.path.exists(templates_dest):
        os.makedirs(templates_dest)

    candidate_dir = os.path.join(settings.MULTITIER_THEMES_DIR, app_name,
                                 'templates')
    if not os.path.isdir(candidate_dir):
        template_dirs = django_settings.TEMPLATE_DIRS
    else:
        template_dirs = [candidate_dir]
    for template_dir in template_dirs:
        # The first TEMPLATE_DIRS usually contains the most specialized
        # templates (ie. the ones we truely want to install).
        if (templates_dest
                and not os.path.samefile(template_dir, templates_dest)):
            install_templates(template_dir,
                              templates_dest,
                              excludes=excludes,
                              includes=includes,
                              app_name=app_name)

    # Copy local resources (not under source control) to resources_dest.
    excludes = ['--exclude', '*~', '--exclude', '.DS_Store']
    app_static_root = django_settings.STATIC_ROOT
    if not app_static_root.endswith(django_settings.STATIC_URL):
        static_url_parts = []
        for part in django_settings.STATIC_URL.split('/'):
            if part:
                static_url_parts += [part]
        if static_url_parts[0] == django_settings.APP_NAME:
            static_url = '/'.join(static_url_parts[1:])
        else:
            static_url = django_settings.STATIC_URL[1:]
        app_static_root = os.path.join(app_static_root, static_url)
    if app_static_root[-1] == os.sep:
        # If we have a trailing '/', rsync will copy the content
        # of the directory instead of the directory itself.
        app_static_root = app_static_root[:-1]
    shell_command(['/usr/bin/rsync'] + excludes +
                  ['-az', '--safe-links', '--rsync-path', '/usr/bin/rsync'] +
                  [app_static_root, resources_dest])
    zip_path = os.path.join(install_dir, '%s.zip' % app_name)
    with zipfile.ZipFile(zip_path, 'w') as zip_file:
        fill_package(zip_file, build_dir, prefix=app_name)
    return zip_path