示例#1
0
def forget(parser, target, options):
    # Find out the commit to start from
    commits = get_commits(target)
    if len(commits) == 0:
        print 'There is nothing to forget.'
        return

    if options.commits is not None:
        if len(commits) > options.commits:
            since = commits[options.commits][0]
        else:
            print 'There is nothing to forget'
            return
    else:
        if commits[len(commits) - 1][1] <= options.days:
            print 'There is nothing to forget.'
            return
        for commit in commits:
            since, delta = commit
            if delta > options.days:
                break

    # Check the server is not running
    pid = get_pid('%s/pid' % target)
    if pid is not None:
        print 'The server is running. Stop it before running this command.'
        return

    # Export to new database
    print '* Make new branch with shorter history (may take a while)'
    cwd = '%s/database' % target
    command = (
        'git fast-export --no-data --progress=1000 %s.. | '
        'sed "s|refs/heads/master|refs/heads/new|" | '
        'git fast-import --quiet')
    # FIXME This does not work if the error comes from git-fast-export,
    # because execution continues and sed returns 0. See the hack just below.
    returncode = call(command % since, shell=True, cwd=cwd)
    if returncode:
        exit()

    # Verify the step before was fine
    try:
        get_pipe(['git', 'log', '-n', '0', 'new'], cwd=cwd)
    except EnvironmentError:
        print_exc()
        exit()

    # Backup old branch and deploy new one
    print '* Deploy new branch and backup old branch'
    now = datetime.now().strftime('%Y%m%d%H%M')
    command = ['git', 'branch', '-m', 'master', now]
    get_pipe(command, cwd=cwd)
    command = ['git', 'branch', '-m', 'new', 'master']
    get_pipe(command, cwd=cwd)
    command = ['git', 'checkout', 'master']
    get_pipe(command, cwd=cwd)

    # Ok
    print 'Done. Backup branch is %s' % now
示例#2
0
def forget(parser, target, options):
    # Find out the commit to start from
    commits = get_commits(target)
    if len(commits) == 0:
        print 'There is nothing to forget.'
        return

    if options.commits is not None:
        if len(commits) > options.commits:
            since = commits[options.commits][0]
        else:
            print 'There is nothing to forget'
            return
    else:
        if commits[len(commits) - 1][1] <= options.days:
            print 'There is nothing to forget.'
            return
        for commit in commits:
            since, delta = commit
            if delta > options.days:
                break

    # Check the server is not running
    pid = get_pid('%s/pid' % target)
    if pid is not None:
        print 'The server is running. Stop it before running this command.'
        return

    # Export to new database
    print '* Make new branch with shorter history (may take a while)'
    cwd = '%s/database' % target
    command = ('git fast-export --no-data --progress=1000 %s.. | '
               'sed "s|refs/heads/master|refs/heads/new|" | '
               'git fast-import --quiet')
    # FIXME This does not work if the error comes from git-fast-export,
    # because execution continues and sed returns 0. See the hack just below.
    returncode = call(command % since, shell=True, cwd=cwd)
    if returncode:
        exit()

    # Verify the step before was fine
    try:
        get_pipe(['git', 'log', '-n', '0', 'new'], cwd=cwd)
    except EnvironmentError:
        print_exc()
        exit()

    # Backup old branch and deploy new one
    print '* Deploy new branch and backup old branch'
    now = datetime.now().strftime('%Y%m%d%H%M')
    command = ['git', 'branch', '-m', 'master', now]
    get_pipe(command, cwd=cwd)
    command = ['git', 'branch', '-m', 'new', 'master']
    get_pipe(command, cwd=cwd)
    command = ['git', 'checkout', 'master']
    get_pipe(command, cwd=cwd)

    # Ok
    print 'Done. Backup branch is %s' % now
示例#3
0
def stop(parser, options, target):
    # Stop the Web Server
    pid = get_pid('%s/pid' % target)
    if pid is None:
        print '[%s] Web Server not running.' % target

        # XXX Obsolete code, remove by 0.70
        # Eventually stop the subprocess
        sub_pid = get_pid('%s/pid-subprocess' % target)
        if sub_pid is not None:
            kill(sub_pid, SIGTERM)
            print '[%s] Web Server subprocess is running, i kill it' % target
    else:
        signal = SIGTERM if options.force else SIGINT
        kill(pid, signal)
        if options.force:
            print '[%s] Web Server shutting down...' % target
        else:
            print '[%s] Web Server shutting down (gracefully)...' % target
示例#4
0
def stop(parser, options, target):
    # Stop the Web Server
    pid = get_pid('%s/pid' % target)
    if pid is None:
        print '[%s] Web Server not running.' % target

        # XXX Obsolete code, remove by 0.70
        # Eventually stop the subprocess
        sub_pid = get_pid('%s/pid-subprocess' % target)
        if sub_pid is not None:
            kill(sub_pid, SIGTERM)
            print '[%s] Web Server subprocess is running, i kill it' % target
    else:
        signal = SIGTERM if options.force else SIGINT
        kill(pid, signal)
        if options.force:
            print '[%s] Web Server shutting down...' % target
        else:
            print '[%s] Web Server shutting down (gracefully)...' % target
示例#5
0
def update(parser, options, target):
    # Check the server is not started, or started in read-only mode
    pid = get_pid('%s/pid' % target)
    if pid is not None:
        print('Cannot proceed, the server is running in read-write mode.')
        return
    # Load server
    server = Server(target)
    # Build a fake context
    with server.database.init_context() as context:
        print('STAGE 1: Find out the versions to upgrade (may take a while).')
        msgs = do_run_next_update_method(context, force=options.force)
        print(u'\n'.join([x.gettext() for x in msgs]))
示例#6
0
def update(parser, options, target):
    confirm = options.confirm

    # Check the server is not started, or started in read-only mode
    pid = get_pid('%s/pid' % target)
    if pid is not None:
        print 'Cannot proceed, the server is running in read-write mode.'
        return

    # Check for database consistency
    if options.quick is False and check_database(target) is False:
        return 1

    # Load the modules
    config = get_config(target)
    load_modules(config)

    #######################################################################
    # STAGE 1: Find out the versions to upgrade
    #######################################################################
    server = Server(target)
    database = server.database
    # Build a fake context
    context = get_fake_context(database)
    context.server = server
    context.init_context()
    # Local variables
    root = server.root

    print 'STAGE 1: Find out the versions to upgrade (may take a while).'
    version, paths = find_versions_to_update(root, options.force)
    while version:
        message = 'STAGE 1: Upgrade %d resources to version %s (y/N)? '
        message = message % (len(paths), version)
        if ask_confirmation(message, confirm) is False:
            abort()
        update_versions(target, database, version, paths, root, options.force)
        # Reset the state
        database.cache.clear()
        database.cache[root.metadata.key] = root.metadata
        print 'STAGE 1: Finish upgrading to version %s' % version
        version, paths = find_versions_to_update(root, options.force)

    print 'STAGE 1: Done.'

    # It is Done
    print '*'
    print '* To finish the upgrade process update the catalog:'
    print '*'
    print '*   $ icms-update-catalog.py %s' % target
    print '*'
示例#7
0
def update(parser, options, target):
    confirm = options.confirm

    # Check the server is not started, or started in read-only mode
    pid = get_pid("%s/pid" % target)
    if pid is not None:
        print "Cannot proceed, the server is running in read-write mode."
        return

    # Check for database consistency
    if options.quick is False and check_database(target) is False:
        return 1

    # Load the modules
    config = get_config(target)
    load_modules(config)

    #######################################################################
    # STAGE 1: Find out the versions to upgrade
    #######################################################################
    server = Server(target)
    database = server.database
    # Build a fake context
    context = get_fake_context(database)
    context.server = server
    context.init_context()
    # Local variables
    root = server.root

    print "STAGE 1: Find out the versions to upgrade (may take a while)."
    version, paths = find_versions_to_update(root, options.force)
    while version:
        message = "STAGE 1: Upgrade %d resources to version %s (y/N)? "
        message = message % (len(paths), version)
        if ask_confirmation(message, confirm) is False:
            abort()
        update_versions(target, database, version, paths, root, options.force)
        # Reset the state
        database.cache.clear()
        database.cache[root.metadata.key] = root.metadata
        print "STAGE 1: Finish upgrading to version %s" % version
        version, paths = find_versions_to_update(root, options.force)

    print "STAGE 1: Done."

    # It is Done
    print "*"
    print "* To finish the upgrade process update the catalog:"
    print "*"
    print "*   $ icms-update-catalog.py %s" % target
    print "*"
示例#8
0
def update(parser, options, target):
    confirm = options.confirm

    # Check the server is not started, or started in read-only mode
    pid = get_pid('%s/pid' % target)
    if pid is not None:
        print 'Cannot proceed, the server is running in read-write mode.'
        return

    # Check for database consistency
    if options.quick is False and check_database(target) is False:
        return 1

    # Load the modules
    config = get_config(target)
    load_modules(config)

    #######################################################################
    # STAGE 0: Set mtime/author
    # XXX Specific to the migration from 0.61 to 0.62
    #######################################################################
    server = Server(target)
    database = server.database
    # Build a fake context
    context = get_fake_context(database)
    context.server = server
    context.init_context()
    # Local variables
    root = server.root

    mtime = root.get_value('mtime')
    if mtime is None or options.mtime:
        message = 'STAGE 0: Set mtime and author in the metadata (y/N)? '
        if ask_confirmation(message, confirm) is False:
            abort()

        # Find out set of valid usernames
        usernames = root.get_names('users')
        usernames = set(usernames)

        print 'STAGE 0: Initializing mtime/author'
        # Load cache
        git_cache = {}
        for commit in database.worktree.git_log(include_files=True):
            if commit['author_name'] not in usernames:
                commit['author_name'] = None
            for path in commit['paths']:
                if path not in git_cache or not git_cache[path]['author_name']:
                    git_cache[path] = commit

        # Set mtime/author
        for resource in root.traverse_resources():
            if not isinstance(resource, DBResource):
                continue

            files = resource.get_files_to_archive()
            last_commit = None
            for file in files:
                commit = git_cache.get(file)
                if not commit:
                    continue
                if not last_commit or commit['author_date'] > last_commit['author_date']:
                    last_commit = commit
            metadata = resource.metadata
            metadata.set_property('mtime', last_commit['author_date'])
            metadata.set_property('last_author', last_commit['author_name'])

        # Commit
        context.git_message = u'Upgrade: set mtime/author'
        context.set_mtime = False # Do not override the mtime/author
        database.save_changes()


    #######################################################################
    # STAGE 1: Find out the versions to upgrade
    #######################################################################
    print 'STAGE 1: Find out the versions to upgrade (may take a while).'
    version, paths = find_versions_to_update(root, options.force)
    while version:
        message = 'STAGE 1: Upgrade %d resources to version %s (y/N)? '
        message = message % (len(paths), version)
        if ask_confirmation(message, confirm) is False:
            abort()
        update_versions(target, database, version, paths, root, options.force)
        # Reset the state
        database.cache.clear()
        database.cache[root.metadata.key] = root.metadata
        print 'STAGE 1: Finish upgrading to version %s' % version
        version, paths = find_versions_to_update(root, options.force)

    print 'STAGE 1: Done.'

    # It is Done
    print '*'
    print '* To finish the upgrade process update the catalog:'
    print '*'
    print '*   $ icms-update-catalog.py %s' % target
    print '*'
示例#9
0
def start(options, target):
    # Check the server is not running
    pid = get_pid('%s/pid' % target)
    if pid is not None:
        print '[%s] The Web Server is already running.' % target
        return 1
    # XXX Obsolete code, remove by 0.70
    sub_pid = get_pid('%s/pid-subprocess' % target)
    if sub_pid is not None:
        print(
            '[%s] The Web Server subprocess is running, please use '
            'icms-stop.py to stop it.') % target
        return 1

    # Check for database consistency
    if options.quick is False and check_database(target) is False:
        return 1

    # Check instance is up to date
    if not is_instance_up_to_date(target):
        print 'The instance is not up-to-date, please type:'
        print
        print '    $ icms-update.py %s' % target
        print
        return 1

    # Daemon mode
    if options.detach:
        become_daemon()

    # Set-up the server
    server = Server(target,
                    read_only=options.read_only,
                    profile_space=options.profile_space)

    # Update Git tree-cache, to speed things up
    server.database.worktree.update_tree_cache()

    # Find out the IP to listen to
    config = server.config
    address = config.get_value('listen-address').strip()
    if not address:
        raise ValueError, 'listen-address is missing from config.conf'
    if address == '*':
        address = None

    # Find out the port to listen
    port = config.get_value('listen-port')
    if port is None:
        raise ValueError, 'listen-port is missing from config.conf'

    server.listen(address, port)
    server.set_context('/', CMSContext)
    interval = config.get_value('cron-interval')
    if interval:
        cron(server.cron_manager, 1)

    # Run
    profile = options.profile_time
    profile = ('%s/log/profile' % target) if profile else None
    loop = Loop(pid_file='%s/pid' % target, profile=profile)
    loop.run()

    # Ok
    return 0
示例#10
0
def start(options, target):
    # Check the server is not running
    pid = get_pid('%s/pid' % target)
    if pid is not None:
        print '[%s] The Web Server is already running.' % target
        return 1
    # XXX Obsolete code, remove by 0.70
    sub_pid = get_pid('%s/pid-subprocess' % target)
    if sub_pid is not None:
        print ('[%s] The Web Server subprocess is running, please use '
               'icms-stop.py to stop it.') % target
        return 1

    # Check for database consistency
    if options.quick is False and check_database(target) is False:
        return 1

    # Check instance is up to date
    if not is_instance_up_to_date(target):
        print 'The instance is not up-to-date, please type:'
        print
        print '    $ icms-update.py %s' % target
        print
        return 1

    # Daemon mode
    if options.detach:
        become_daemon()

    # Set-up the server
    server = Server(target, read_only=options.read_only,
                    profile_space=options.profile_space)

    # Update Git tree-cache, to speed things up
    server.database.worktree.update_tree_cache()

    # Find out the IP to listen to
    config = server.config
    address = config.get_value('listen-address').strip()
    if not address:
        raise ValueError, 'listen-address is missing from config.conf'
    if address == '*':
        address = None

    # Find out the port to listen
    port = config.get_value('listen-port')
    if port is None:
        raise ValueError, 'listen-port is missing from config.conf'

    server.listen(address, port)
    server.set_context('/', CMSContext)
    interval = config.get_value('cron-interval')
    if interval:
        cron(server.cron_manager, 1)

    # Run
    profile = options.profile_time
    profile = ('%s/log/profile' % target) if profile else None
    loop = Loop(pid_file='%s/pid' % target, profile=profile)
    loop.run()

    # Ok
    return 0