Ejemplo n.º 1
0
 def __init__(self, __doc__=None, version=None):
     if __doc__:
         usage = __doc__ % (self.name, self.arguments,
                            self.__doc__.replace('    ', ''))
     else:
         usage = self.__doc__.replace('    ', '')
     Configuration.__init__(self, usage=usage, version=version)
Ejemplo n.º 2
0
 def bootstrap(self, cubes, automatic=False, inputlevel=0):
     """create an instance by copying files from the given cube and by asking
     information necessary to build required configuration files
     """
     config = self.config
     if not automatic:
         print(underline_title('Configuring the repository'))
         config.input_config('email', inputlevel)
         print('\n' + underline_title('Configuring the sources'))
     # hack to make Method('default_instance_id') usable in db option defs
     # (in native.py)
     sconfig = SourceConfiguration(config,
                                   options=SOURCE_TYPES['native'].options)
     if not automatic:
         sconfig.input_config(inputlevel=inputlevel)
         print()
     sourcescfg = {'system': sconfig}
     if automatic:
         # XXX modify a copy
         password = generate_password()
         print('-> set administrator account to admin / %s' % password)
         USER_OPTIONS[1][1]['default'] = password
         sconfig = Configuration(options=USER_OPTIONS)
     else:
         sconfig = Configuration(options=USER_OPTIONS)
         sconfig.input_config(inputlevel=inputlevel)
     sourcescfg['admin'] = sconfig
     config.write_sources_file(sourcescfg)
     # remember selected cubes for later initialization of the database
     config.write_bootstrap_cubes_file(cubes)
Ejemplo n.º 3
0
 def test_register_options_multiple_groups(self):
     """ensure multiple option groups can be registered at once"""
     config = Configuration()
     self.assertEqual(config.options, ())
     new_options = (
         ('option1', {
             'type': 'string',
             'help': '',
             'group': 'g1',
             'level': 2
         }),
         ('option2', {
             'type': 'string',
             'help': '',
             'group': 'g1',
             'level': 2
         }),
         ('option3', {
             'type': 'string',
             'help': '',
             'group': 'g2',
             'level': 2
         }),
     )
     config.register_options(new_options)
     self.assertEqual(config.options, new_options)
Ejemplo n.º 4
0
 def __init__(self, __doc__=None, version=None):
     if __doc__:
         usage = __doc__ % (self.name, self.arguments,
                            self.__doc__.replace('    ', ''))
     else:
         usage = self.__doc__.replace('    ', '')
     Configuration.__init__(self, usage=usage, version=version)
Ejemplo n.º 5
0
 def run(self):
     """ Start the SFTP server.
     """
     config = Configuration(options=self.options, name="twistedsftp")
     config.load_command_line_configuration()
     config.load_file_configuration(config.get("config-file"))
     reactor.listenTCP(config.get("port"), CubicWebSSHdFactory(config))
     print("Twisted server ready on port '{0}'".format(config.get("port")))
     reactor.run()
Ejemplo n.º 6
0
 def test_register_options_multiple_groups(self):
     """ensure multiple option groups can be registered at once"""
     config = Configuration()
     self.assertEqual(config.options, ())
     new_options = (
         ('option1', {'type': 'string', 'help': '',
                      'group': 'g1', 'level': 2}),
         ('option2', {'type': 'string', 'help': '',
                      'group': 'g1', 'level': 2}),
         ('option3', {'type': 'string', 'help': '',
                      'group': 'g2', 'level': 2}),
     )
     config.register_options(new_options)
     self.assertEqual(config.options, new_options)
Ejemplo n.º 7
0
 def run(self):
     """ Start the SFTP server.
     """
     config = Configuration(options=self.options, name="twistedsftp")
     config.load_command_line_configuration()
     config.load_file_configuration(config.get("config-file"))
     reactor.listenTCP(config.get("port"), CubicWebSSHdFactory(config))
     print("Twisted server ready on port '{0}'".format(config.get("port")))
     reactor.run()
Ejemplo n.º 8
0
def check_schema():
    config = Configuration(usage="yams-check [[[...] deps] deps] apps",
                           doc="Check the schema of an application.",
                           version=version)
    dirnames = config.load_command_line_configuration()
    if not dirnames:
        print(config.help(), file=sys.stderr)
        return 2
    for dir in dirnames:
        assert exists(dir), dir
    try:
        SchemaLoader().load(dirnames)
        return 0
    except Exception as ex:
        tb_offset = getattr(ex, 'tb_offset', 0)
        filename, lineno, func, text = extract_tb(sys.exc_traceback)[-1 -
                                                                     tb_offset]
        if hasattr(ex, "schema_files"):
            filename = ', '.join(ex.schema_files)
        _error(filename, lineno, "%s -> %s" % (ex.__class__.__name__, ex))
        return 2
Ejemplo n.º 9
0
 def run(self, args):
     """run the command with its specific arguments"""
     from cubicweb.server.utils import crypt_password, manager_userpasswd
     appid = args[0]
     config = ServerConfiguration.config_for(appid)
     sourcescfg = config.read_sources_file()
     try:
         adminlogin = sourcescfg['admin']['login']
     except KeyError:
         print('-> Error: could not get cubicweb administrator login.')
         sys.exit(1)
     cnx = source_cnx(sourcescfg['system'])
     driver = sourcescfg['system']['db-driver']
     dbhelper = get_db_helper(driver)
     cursor = cnx.cursor()
     # check admin exists
     cursor.execute("SELECT * FROM cw_CWUser WHERE cw_login=%(l)s",
                    {'l': adminlogin})
     if not cursor.fetchall():
         print("-> error: admin user %r specified in sources doesn't exist "
               "in the database" % adminlogin)
         print("   fix your sources file before running this command")
         cnx.close()
         sys.exit(1)
     if self.config.password is None:
         # ask for a new password
         msg = 'new password for %s' % adminlogin
         _, pwd = manager_userpasswd(adminlogin,
                                     confirm=True,
                                     passwdmsg=msg)
     else:
         pwd = self.config.password
     try:
         cursor.execute(
             "UPDATE cw_CWUser SET cw_upassword=%(p)s WHERE cw_login=%(l)s",
             {
                 'p': dbhelper.binary_value(crypt_password(pwd)),
                 'l': adminlogin
             })
         sconfig = Configuration(options=USER_OPTIONS)
         sconfig['login'] = adminlogin
         sconfig['password'] = pwd
         sourcescfg['admin'] = sconfig
         config.write_sources_file(sourcescfg)
     except Exception as ex:
         cnx.rollback()
         import traceback
         traceback.print_exc()
         print('-> an error occurred:', ex)
     else:
         cnx.commit()
         print('-> password reset, sources file regenerated.')
     cnx.close()
Ejemplo n.º 10
0
def configure_instance2(self, appid):
    configure_instance(self, appid)
    if self.config.db is not None:
        appcfg = ServerConfiguration.config_for(appid)
        srccfg = appcfg.read_sources_file()
        for key, value in self.config.db.items():
            if '.' in key:
                section, key = key.split('.', 1)
            else:
                section = 'system'
            try:
                srccfg[section][key] = value
            except KeyError:
                raise ConfigurationError(
                    'unknown configuration key "%s" in section "%s" for source'
                    % (key, section))
        admcfg = Configuration(options=USER_OPTIONS)
        admcfg['login'] = srccfg['admin']['login']
        admcfg['password'] = srccfg['admin']['password']
        srccfg['admin'] = admcfg
        appcfg.write_sources_file(srccfg)
Ejemplo n.º 11
0
 def persistent_options_configuration():
     return Configuration(options=PERSISTENT_OPTIONS)
Ejemplo n.º 12
0
def schema_image():
    options = [
        ('output-file', {
            'type': 'file',
            'default': None,
            'metavar': '<file>',
            'short': 'o',
            'help': 'output image file'
        }),
        ('viewer', {
            'type': 'string',
            'default': "rsvg-view",
            'short': "w",
            'metavar': '<cmd>',
            'help': 'command use to view the generated file (empty for none)'
        }),
        ('lib-dir', {
            'type': 'string',
            'short': "L",
            'metavar': '<dir>',
            'help': 'directory to look for schema dependancies'
        }),
    ]

    config = Configuration(
        options=options,
        usage="yams-view [-L <lib_dir> | [[[...] deps] deps]] apps",
        version=version)
    dirnames = config.load_command_line_configuration()

    lib_dir = config['lib-dir']
    assert lib_dir is not None
    if lib_dir is not None:
        app_dir = dirnames[-1]
        from cubicweb.cwconfig import CubicWebConfiguration as cwcfg
        packages = cwcfg.expand_cubes(dirnames)
        packages = cwcfg.reorder_cubes(packages)
        packages = [pkg for pkg in packages if pkg != app_dir]
    elif False:
        glob = globals().copy()
        execfile(join(app_dir, "__pkginfo__.py"), glob)
        #dirnames = [ join(lib_dir,dep) for dep in glob['__use__']]+dirnames
        packages = [dep for dep in glob['__use__']]

    for dir in dirnames:
        assert exists(dir), dir

    import cubicweb
    cubicweb_dir = dirname(cubicweb.__file__)

    schm_ldr = SchemaLoader()

    class MockConfig(object):
        def packages(self):
            return packages

        def packages_path(self):
            return packages

        def schemas_lib_dir(self):
            return join(cubicweb_dir, "schemas")

        #def apphome(self):
        #    return lib_dir
        apphome = dirnames[0]

        def appid(self):
            "bob"

    print(MockConfig().packages())

    schema = schm_ldr.load(MockConfig())

    out, viewer = config['output-file'], config['viewer']
    if out is None:
        tmp_file = NamedTemporaryFile(suffix=".svg")
        out = tmp_file.name
    schema2dot.schema2dot(
        schema,
        out,  #size=size,
        skiprels=("identity", ),
        skipentities=("Person", "AbstractPerson", "Card", "AbstractCompany",
                      "Company", "Division"))
    if viewer:
        p = Popen((viewer, out))
        p.wait()

    return 0
Ejemplo n.º 13
0
 def __init__(self, logger):
     usage = '%%prog %s %s\n\n%s' % (self.name, self.arguments,
                                     self.description())
     Configuration.__init__(self, usage=usage)
     self.logger = logger
Ejemplo n.º 14
0
 def __init__(self, name=None):
     BaseConfiguration.__init__(self, options=self.options,
                                config_file=self.config_file,
                                name=name)
     self.load_command_line_configuration()
     self.config_name = self['config-name']
Ejemplo n.º 15
0
 def __init__(self, name=None):
     BaseConfiguration.__init__(self, options=self.options,
                                config_file=self.config_file,
                                name=name)
Ejemplo n.º 16
0
 def __init__(self, name=None):
     BaseConfiguration.__init__(self, options=self.options, config_file=self.config_file, name=name)
     self.load_command_line_configuration()
     self.config_name = self["config-name"]
Ejemplo n.º 17
0
 def __init__(self):
     BaseConfiguration.__init__(self,
                                options=self.options,
                                config_file=self.config_file)
Ejemplo n.º 18
0
 def __init__(self, name=None):
     BaseConfiguration.__init__(self,
                                options=self.options,
                                config_file=self.config_file,
                                name=name)
Ejemplo n.º 19
0
 def __init__(self, logger):
     usage = '%%prog %s %s\n\n%s' % (self.name, self.arguments,
                                     self.description())
     Configuration.__init__(self, usage=usage)
     self.logger = logger
Ejemplo n.º 20
0
 def __init__(self):
     BaseConfiguration.__init__(self, options=self.options,
                                config_file=self.config_file)