Exemplo n.º 1
0
def remote_initdb_from_fixture(project_dir, virtualenv_name):
    """initialize a remote database from fixtures in the remote
    project_dir with virtual environment virtualenv_name"""

    fabhelp.progress("initialize a remote database from the fixture")

    # infer the REMOTE relative path from the project root to the
    # dbstate filaname from the (possibly LOCAL) settings
    dbstate = None
    if fabhelp.is_dbvcs_installed():
        from common.apps.dbvcs.conf import settings as dbvcs_settings
        from django.conf import settings as django_settings
        dbstate = os.path.relpath(dbvcs_settings.DBVCS_STATE_FILENAME, 
                                  django_settings.PROJECT_ROOT)

    with cd(project_dir):
        run("./common/bin/setup_mysql.py") # get the mysql stuff setup
        run("./manage.py setup_virtualenv")
        syncdb_flags = "--noinput"
        if fabhelp.is_dbvcs_installed():
            run("./manage.py setup_dbvcs_hooks")
            syncdb_flags += " --ignore-dbstate"
        run("./manage.py syncdb %s" % syncdb_flags)
        if fabhelp.is_dbvcs_installed():
            run("./manage.py fixture2database")
Exemplo n.º 2
0
def update_remote(hg_revision='tip'):
    """update remote repository"""

    change_owner()
    group_writable_permissions()

    # get a list of all of the django projects in this 
    rel_django_project_dirs = []
    hg_root = fabhelp.get_hg_root()
    for root, dirs, files in os.walk(hg_root):
        d = os.path.join(hg_root, root)
        try:
            dirs.remove('.hg') # ignore mercurial repositories
        except ValueError:
            pass # .hg is not in dirs
        if fabhelp.is_django_project(d):
            rel_django_project_dirs.append(os.path.relpath(d, hg_root))
            dirs[:] = [] # no need to decend any further... save time!

    # get the remote directory from the apache file
    fabhelp.progress("updating remote repository")
    remote_repo_dir = get_remote_repo_dir()
    with cd(remote_repo_dir):
        with fabric_settings(warn_only = True):
            run("hg pull")

        # run database2fixture for each django repository in this repository
        for rel_django_project_dir in rel_django_project_dirs:
            with cd(rel_django_project_dir):
                if fabhelp.is_dbvcs_installed():
                    run("./manage.py database2fixture")

        run("hg update -r %s"%hg_revision)

    remote_project_dir = get_remote_project_dir()
    with cd(remote_project_dir):
        run("./manage.py setup_virtualenv") # add new packages when necessary
        group_writable_permissions()
Exemplo n.º 3
0
def pull_remote_to_localhost(remotehost):
    """pull remotehost changes into local repository and update. this
    includes all subrepositories
    """

    assert remotehost in ("poisson", "noether",)
    
    # dump database and check in as necessary
    fabhelp.progress("dump remote database and auto check-in")
    remote_project_dir = get_remote_project_dir()
    with cd(remote_project_dir):
        if fabhelp.is_dbvcs_installed():
            run("./manage.py database2fixture")
        cmd="hg ci -m 'auto-checkin: adding data for pull_remote_to_localhost'"
        with fabric_settings(warn_only=True):
            result = run(cmd)
            if result.failed:
                # there were no changes to check in
                if result.return_code==1:
                    pass 
                # something else happened. this is a problem, so abort
                else:
                    abort("hg ci failed. see above output for details")

    # recursively get all of the subrepository directories. breadth
    # first search here
    fabhelp.progress("find all of the subrepository directories")
    from django.conf import settings as django_settings
    with lcd(django_settings.PROJECT_ROOT):
        local_repo_dir = fabhelp.get_hg_root()
    remote_repo_dir = get_remote_repo_dir()
    hgsub_directories=collections.deque([local_repo_dir])
    subrepo_directory_list = [local_repo_dir]
    while len(hgsub_directories):
        hgsub_directory = hgsub_directories.popleft()
        hgsub_filename = os.path.join(hgsub_directory, '.hgsub')
        if os.path.exists(hgsub_filename):
            hgsub = open(hgsub_filename)
            for line in hgsub:
                l = line.split('=')
                if len(l)==2:
                    directory = l[0].strip()
                    subrepo_directory = os.path.join(hgsub_directory,directory)
                    subrepo_directory_list.append(subrepo_directory)
                    hgsub_directories.append(subrepo_directory)
                elif line.strip(): # this is a non-empty line
                    raise TypeError("%s has unexpected format"%hgsub_filename)
            hgsub.close()

    # reorder subrepo reldir list to always get subdirectories first 
    subrepo_directory_list.reverse()

    # pull changes into base repository and all
    # subrepositories. iterate over all of the subrepo reldir's and
    # pull in the new information so that there aren't any problems
    # with remote heads, etc.
    fabhelp.progress("recursively pull subrepos and the base repo")
    for subrepo_directory in subrepo_directory_list:
        with lcd(subrepo_directory):
            subrepo_reldir = os.path.relpath(subrepo_directory, local_repo_dir)
            remote_dir = os.path.join(remote_repo_dir, subrepo_reldir)

            # if remote dir exists, pull from that
            # subrepository. remote_dir may not exist if there are
            # locally added subrepos that have not been put on
            # production yet.
            with fabric_settings(warn_only=True):
                exists = run("test -d %s"%remote_dir)
                if exists.succeeded:
                    local("hg pull ssh://%s/%s"%(remotehost, remote_dir))

    # # XXXX THIS IS CAUSING WIERD ERROR WITH PARAMIKO ?!?!
    # # locally update
    # fabhelp.progress("update local repository (or at least try)")
    # with lcd(local_repo_dir):
    #     with fabric_settings(warn_only=True):
    #         result = local("hg up", capture=True)
    #         if result.failed:
    #             pass # nothing to update
    msg="next: update your local repository to get all incoming change sets"
    fabhelp.progress(msg)
Exemplo n.º 4
0
def add_dsa_app(app_name=None):
    """add an app from the DjangoApps collection of repositories"""
    
    # make sure project name is provided 
    if app_name is None:
        app_name = prompt("Please enter an app name: ")

    # remember some directories
    cur_dir, bin_dir, src_dir = fabhelp.get_cur_bin_src_directories()

    # make sure we are in the root of the django project
    if not fabhelp.is_django_project(cur_dir, in_root_dir=True):
        abort("This command must be run from root of django project")

    # abort if local changes to .hgignore or .hgsub
    hg_root = fabhelp.get_hg_root()
    hg_modified_files = [
        os.path.join(hg_root, ".hgsub"),
        os.path.join(cur_dir, "conf", "settings_modules.txt"),
    ]
    fabhelp.abort_if_local_changes(hg_modified_files)

    # clone the subrepository in the right place
    clone_subrepository(
        "ssh://poisson//srv/hg/DjangoApps/%s"%app_name, 
        os.path.join(cur_dir, "apps", app_name),
    )

    # create the settings file
    fabhelp.progress("creating the conf/%s.py settings for project"%app_name)
    from django.conf import settings as django_settings
    from django.template.loader import render_to_string
    try:
        django_settings.configure(
            DEBUG=True, 
            TEMPLATE_DEBUG=True,
            TEMPLATE_DIRS=(
                os.path.join(cur_dir, 'templates'),
            ),
        )
    except RuntimeError:
        pass # this is being run from the setup_dsa_app django command
             # --- hopefully
    f = open(os.path.join(cur_dir, "conf", "%s.py"%app_name), 'w')
    f.write(render_to_string(".settings_template.py", {
        "app_name": app_name,
        "is_dbvcs_installed": fabhelp.is_dbvcs_installed(),
    }))
    f.close()
    
    # add the settings to the settings_modules.txt file
    fabhelp.progress("add the settings file to conf/settings_modules.txt")
    f = open(os.path.join(cur_dir, "conf", "settings_modules.txt"), 'a')
    f.write("""
# automatically including %s
conf/%s.py
"""%(app_name, app_name))
    f.close()

    # add the media soft links
    fabhelp.progress("soft links for media")
    with lcd(".media"):
        local("ln -s ../apps/%s/media/%s %s"%(app_name, app_name, app_name))
    with lcd(".static"):
        local("ln -s ../apps/%s/static/%s %s"%(app_name, app_name, app_name))

    # synchronize the database and dump the database
    fabhelp.progress("syncdb and database2fixture (as necessary)!")
    local("./manage.py syncdb --noinput")
    if fabhelp.is_dbvcs_installed():
        local("./manage.py database2fixture --all")

    # add these fixtures to the repository. make sure to change into
    # the local directory first in case the dbvcs data directory is a
    # subrepository
    if fabhelp.is_dbvcs_installed():
        result = local("./manage.py listfixtures apps.%s" % app_name, 
                       capture=True)
        for filename in result.split():
            d, f = os.path.split(filename)
            with lcd(d):
                local("hg add %s"%f)

    # run hg add
    fabhelp.progress("add everything to the mercurial repository")
    local("hg add %s"%' '.join([
        os.path.join(cur_dir, "conf", "%s.py"%app_name),
        os.path.join(cur_dir, ".media", app_name),
        os.path.join(cur_dir, ".static", app_name),
    ]))