예제 #1
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 '*'
예제 #2
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 "*"
예제 #3
0
    def check_consistency(self, quick):
        # Check the server is not running
        pid = get_pid('%s/pid' % self.target)
        if pid is not None:
            print '[%s] The Web Server is already running.' % self.target
            return False

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

        # Check instance is up to date
        if not is_instance_up_to_date(self.target):
            print 'The instance is not up-to-date, please type:'
            print
            print '    $ icms-update.py %s' % self.target
            print
            return False
        return True
예제 #4
0
    def reindex_catalog(self, quiet=False, quick=False, as_test=False):
        if self.is_running_in_rw_mode():
            print 'Cannot proceed, the server is running in read-write mode.'
            return
        # Check for database consistency
        if quick is False and check_database(self.target) is False:
            return False
        # Create a temporary new catalog
        catalog_path = '%s/catalog.new' % self.target
        if lfs.exists(catalog_path):
            lfs.remove(catalog_path)
        catalog = make_catalog(catalog_path, get_register_fields())

        # Get the root
        root = self.root

        # Build a fake context
        context = self.get_fake_context()

        # Update
        t0, v0 = time(), vmsize()
        doc_n = 0
        error_detected = False
        if as_test:
            log = open('%s/log/update-catalog' % self.target, 'w').write
        for obj in root.traverse_resources():
            if not isinstance(obj, Resource):
                continue
            if not quiet:
                print doc_n, obj.abspath
            doc_n += 1
            context.resource = obj

            # Index the document
            try:
                catalog.index_document(obj)
            except Exception:
                if as_test:
                    error_detected = True
                    log('*** Error detected ***\n')
                    log('Abspath of the resource: %r\n\n' % str(obj.abspath))
                    log(format_exc())
                    log('\n')
                else:
                    raise

            # Free Memory
            del obj
            self.database.make_room()

        if not error_detected:
            if as_test:
                # Delete the empty log file
                remove('%s/log/update-catalog' % self.target)

            # Update / Report
            t1, v1 = time(), vmsize()
            v = (v1 - v0)/1024
            print '[Update] Time: %.02f seconds. Memory: %s Kb' % (t1 - t0, v)
            # Commit
            print '[Commit]',
            sys.stdout.flush()
            catalog.save_changes()
            # Commit / Replace
            old_catalog_path = '%s/catalog' % self.target
            if lfs.exists(old_catalog_path):
                lfs.remove(old_catalog_path)
            lfs.move(catalog_path, old_catalog_path)
            # Commit / Report
            t2, v2 = time(), vmsize()
            v = (v2 - v1)/1024
            print 'Time: %.02f seconds. Memory: %s Kb' % (t2 - t1, v)
            return True
        else:
            print '[Update] Error(s) detected, the new catalog was NOT saved'
            print ('[Update] You can find more infos in %r' %
                   join(self.target, 'log/update-catalog'))
            return False
예제 #5
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 '*'
예제 #6
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
예제 #7
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