Example #1
0
def update_catalog(parser, options, target):
    # Check the server is not started, or started in read-only mode
    server = Server(target, read_only=True, cache_size=options.cache_size)
    # Ask
    message = 'Update the catalog (y/N)? '
    if ask_confirmation(message, options.confirm) is False:
        return

    # Server reindex
    server.reindex_catalog(as_test=options.test,
                           quiet=options.quiet,
                           quick=options.quick)
def update_catalog(parser, options, target):
    # Check the server is not started, or started in read-only mode
    server = Server(target, read_only=True, cache_size=options.cache_size)
    # Ask
    message = 'Update the catalog (y/N)? '
    if ask_confirmation(message, options.confirm) is False:
        return

    # Server reindex
    server.reindex_catalog(
        as_test=options.test,
        quiet=options.quiet,
        quick=options.quick)
Example #3
0
 def setUp(self):
     global SERVER
     if SERVER is not None:
         return
     self.tearDown()
     path = DATABASE_TEST_PATH
     email = '*****@*****.**'
     password = '******'
     root = None
     modules = []
     listen_port = 8081
     create_server(path, email, password, root,  modules, listen_port)
     server = Server(path)
     server.start(detach=False, loop=False)
     SERVER = server
Example #4
0
 def setUp(self):
     global SERVER
     if SERVER is not None:
         return
     self.tearDown()
     path = DATABASE_TEST_PATH
     email = '*****@*****.**'
     password = '******'
     root = None
     modules = []
     listen_port = 8081
     create_server(path, email, password, root, modules, listen_port)
     server = Server(path)
     server.start(detach=False, loop=False)
     SERVER = server
Example #5
0
 def test_catalog_access(self):
     query = PhraseQuery('format', 'user')
     with Server('demo.hforge.org') as server:
         with server.database.init_context() as context:
             self.assertEqual(context.user, None)
             search = context.search(query)
             self.assertEqual(len(search), 0)
Example #6
0
 def test_plain_text(self):
     with Server('demo.hforge.org') as server:
         with server.database.init_context():
             server.dispatcher.add('/test/text', TestPlainText_View)
             retour = server.do_request('GET', '/test/text')
             self.assertEqual(retour['status'], 200)
             self.assertEqual(retour['entity'], 'hello world')
Example #7
0
 def test_server_unauthorized(self):
     with Server('demo.hforge.org') as server:
         with server.database.init_context():
             server.dispatcher.add('/test/unauthorized',
                                   TestPlainText_View(access=False))
             retour = server.do_request('GET', '/test/unauthorized')
             self.assertEqual(retour['status'], 401)
def update_catalog(parser, options, target):
    # Check the server is not started, or started in read-only mode
    try:
        server = Server(target, read_only=True, cache_size=options.cache_size)
    except LookupError:
        print('Error: {} instance do not exists'.format(target))
        exit(1)
    # Ask
    message = 'Update the catalog (y/N)? '
    if ask_confirmation(message, options.confirm) is False:
        return

    # Server reindex
    server.reindex_catalog(as_test=options.test,
                           quiet=options.quiet,
                           quick=options.quick)
Example #9
0
 def test_server_login_test_server(self):
     with Server('demo.hforge.org') as server:
         with server.database.init_context():
             server.dispatcher.add('/test/401',
                                   TestPlainText_View(access='is_admin'))
             retour = server.do_request('GET', '/test/401')
             self.assertEqual(retour['status'], 401)
Example #10
0
 def test_html(self):
     with Server('demo.hforge.org') as server:
         with server.database.init_context():
             server.dispatcher.add('/test/html', TestHTML_View)
             retour = server.do_request('GET', '/test/html')
             self.assertEqual(retour['status'], 200)
             self.assertEqual(retour['context'].content_type,
                              'text/html; charset=UTF-8')
Example #11
0
 def test_json(self):
     with Server('demo.hforge.org') as server:
         with server.database.init_context():
             server.dispatcher.add('/test/json', TestJson_View)
             retour = server.do_request('GET',
                                        '/test/json?name=world',
                                        as_json=True)
             self.assertEqual(retour['status'], 200)
             self.assertEqual(retour['entity'], {'text': 'hello world'})
Example #12
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]))
Example #13
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 '*'
Example #14
0
 def test_server_404(self):
     with Server('demo.hforge.org') as server:
         with server.database.init_context():
             # Error 404 json
             retour = server.do_request('GET', '/api/404', as_json=True)
             self.assertEqual(retour['status'], 404)
             self.assertEqual(retour['entity']['code'], 404)
             self.assertEqual(retour['context'].content_type,
                              'application/json')
             # Error 404 web
             retour = server.do_request('GET', '/api/404', as_json=False)
             self.assertEqual(retour['status'], 404)
             self.assertEqual(retour['context'].content_type,
                              'text/html; charset=UTF-8')
Example #15
0
 def test_action(self):
     with Server('demo.hforge.org') as server:
         with server.database.init_context():
             server.dispatcher.add('/test/json-action', TestJsonAction_View)
             body = {'action': 'hello', 'name': 'world'}
             retour = server.do_request('POST',
                                        '/test/json-action',
                                        body=body,
                                        as_json=True)
             self.assertEqual(retour['entity'], {'text': 'hello world'})
             body = {'action': 'hello', 'name': 'sylvain'}
             retour = server.do_request('POST',
                                        '/test/json-action',
                                        body=body,
                                        as_json=True)
             self.assertEqual(retour['entity'], {'text': 'hello sylvain'})
Example #16
0
 def test_commit(self):
     with Server('demo.hforge.org') as server:
         with server.database.init_context():
             server.dispatcher.add('/test/json-action', TestJsonAction_View)
             body = {'action': 'set_root_title', 'title': u'Sylvain'}
             retour = server.do_request('POST',
                                        '/test/json-action',
                                        body=body,
                                        as_json=True)
             self.assertEqual(retour['status'], 200)
             self.assertEqual(retour['entity']['success'], True)
             self.assertEqual(server.root.get_value('title', language='fr'),
                              u'Sylvain')
             body = {'action': 'set_root_title', 'title': u'Zidane'}
             retour = server.do_request('POST',
                                        '/test/json-action',
                                        body=body,
                                        as_json=True)
             self.assertEqual(retour['status'], 200)
             self.assertEqual(retour['entity']['success'], True)
             self.assertEqual(server.root.get_value('title', language='fr'),
                              u'Zidane')
Example #17
0
def update_catalog(parser, options, target):
    # Check the server is not started, or started in read-only mode
    server = Server(target, read_only=True, cache_size=options.cache_size)
    if server.is_running_in_rw_mode():
        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

    # Ask
    message = 'Update the catalog (y/N)? '
    if ask_confirmation(message, options.confirm) is False:
        return

    # Create a temporary new catalog
    catalog_path = '%s/catalog.new' % target
    if lfs.exists(catalog_path):
        lfs.remove(catalog_path)
    catalog = make_catalog(catalog_path, get_register_fields())

    # Get the root
    root = server.root

    # Build a fake context
    context = get_fake_context(server.database)
    context.server = server

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

        # Index the document
        try:
            catalog.index_document(obj)
        except Exception:
            if options.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
        server.database.make_room()

    if not error_detected:
        if options.test:
            # Delete the empty log file
            remove('%s/log/update-catalog' % 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' % 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)
    else:
        print '[Update] Error(s) detected, the new catalog was NOT saved'
        print('[Update] You can find more infos in %r' %
              join(target, 'log/update-catalog'))
Example #18
0
File: website.py Project: TZM/zmgc
 def _find_server_root(self, name):
     """
         We need a way to access the resources from site-packages/ikaaro also
         not just the tzm root.
     """
     return Server.find_site_root(self, name)
Example #19
0
# Import from the Standard Library
from optparse import OptionParser

# Import from itools
import itools

# Import from ikaaro
from ikaaro.server import Server

if __name__ == '__main__':
    # The command line parser
    usage = '%prog TARGET [TARGET]*'
    version = 'itools %s' % itools.__version__
    description = ('Stops the web server that is publishing the TARGET'
                   ' ikaaro instance (if it is running). Accepts'
                   ' several TARGETs at once, to stop several servers.')
    parser = OptionParser(usage, version=version, description=description)
    parser.add_option('--force',
                      action="store_true",
                      default=False,
                      help="Emits SIGTERM instead of SIGINT signal.")

    options, args = parser.parse_args()
    if len(args) == 0:
        parser.error('incorrect number of arguments')

    # Action!
    for target in args:
        server = Server(target)
        server.stop(force=options.force)
Example #20
0
def update_catalog(parser, options, target):
    # Check the server is not started, or started in read-only mode
    server = Server(target, read_only=True, cache_size=options.cache_size)
    if server.is_running_in_rw_mode():
        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

    # Ask
    message = 'Update the catalog (y/N)? '
    if ask_confirmation(message, options.confirm) is False:
        return

    # Create a temporary new catalog
    catalog_path = '%s/catalog.new' % target
    if lfs.exists(catalog_path):
        lfs.remove(catalog_path)
    catalog = make_catalog(catalog_path, get_register_fields())

    # Get the root
    root = server.root

    # Build a fake context
    context = get_fake_context(server.database)
    context.server = server

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

        # Index the document
        try:
            catalog.index_document(obj)
        except Exception:
            if options.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
        server.database.make_room()

    if not error_detected:
        if options.test:
            # Delete the empty log file
            remove('%s/log/update-catalog' % 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' % 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)
    else:
        print '[Update] Error(s) detected, the new catalog was NOT saved'
        print ('[Update] You can find more infos in %r' %
               join(target, 'log/update-catalog'))
Example #21
0
        '--profile-space',
        action="store_true",
        default=False,
        help="Enable remote monitoring by guppy, http://guppy-pe.sf.net/")

    # Parse arguments
    options, args = parser.parse_args()
    n_args = len(args)
    if n_args != 1 and n_args != 2:
        parser.error('Wrong number of arguments.')
    # Get target
    target = args[0]
    # Set-up the server
    try:
        server = Server(target,
                        read_only=options.read_only,
                        profile_space=options.profile_space,
                        port=options.port)
    except LookupError:
        print('Error: {} instance do not exists'.format(target))
        exit(1)
    except DatabaseLockError:
        print('Error: Database is already opened'.format(target))
        exit(1)
    # Check server
    successfully_init = server.check_consistency(options.quick)
    if not successfully_init:
        exit(1)
    # Start server
    server.start(detach=options.detach, profile=options.profile_time)
    # Ok
    exit(0)
Example #22
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
Example #23
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
Example #24
0
        '-r', '--read-only', action="store_true", default=False,
        help="Start the server in read-only mode.")
    parser.add_option(
        '--quick', action="store_true", default=False,
        help="Do not check the database consistency.")
    parser.add_option(
        '--profile-time', action="store_true", default=False,
        help="Write profile information tot the 'log/profile' file.")
    parser.add_option(
        '--profile-space', action="store_true", default=False,
        help="Enable remote monitoring by guppy, http://guppy-pe.sf.net/")

    # Parse arguments
    options, args = parser.parse_args()
    n_args = len(args)
    if n_args != 1:
        parser.error('Wrong number of arguments.')
    # Get target
    target = args[0]
    # Set-up the server
    server = Server(target, read_only=options.read_only,
                    profile_space=options.profile_space)
    # Check server
    successfully_init = server.check_consistency(options.quick)
    if not successfully_init:
        exit(1)
    # Start server
    server.start(detach=options.detach, profile=options.profile_time)
    # Ok
    exit(0)
Example #25
0
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Import from standard library
from pprint import pprint

# Import from ikaaro
from ikaaro.server import Server, create_server


path = 'www.hforge.org'
email = '*****@*****.**'
password = '******'
root = None
modules = []
listen_port = 8081

create_server(path, email, password, root,  modules, listen_port)
server = Server(path)
server.start(detach=False, loop=False)
print('Launch reindexation')
reindex_success = server.reindex_catalog(quiet=True)
if reindex_success:
    print('Reindex was successfull')
else:
    print('Error in reindexation')
retour = server.do_request('GET', '/;_ctrl')
pprint(retour)
server.stop()
Example #26
0
 def test_server_up(self):
     with Server('demo.hforge.org') as server:
         with server.database.init_context():
             retour = server.do_request('GET', '/api/status', as_json=True)
             self.assertEqual(retour['entity']['up'], True)
Example #27
0
 def test_server_ctrl(self):
     with Server('demo.hforge.org') as server:
         with server.database.init_context():
             # Test /;ctrl view
             retour = server.do_request('GET', '/;_ctrl')
             self.assertEqual(retour['status'], 200)