示例#1
0
def db_view_from_dirname(dirname):
    instance = 'instance'
    upstream = 'master'
    root = create_tmpdir('root')
    repo_git = {}
    repo_local = {'local': dirname}
    hi = HostInstance(instance, upstream, root, repo_git, repo_local)

    db_view = hi.db_view
    db_view.set_root()
    return db_view
示例#2
0
文件: main.py 项目: rusi/mcdp
    def __init__(self, options, settings):
        self.options = options
        self.settings = settings

        # display options
        for k in sorted(self.options._values):
            v = self.options._values[k]
            logger.debug('option %20s = %r ' % (k, v))
        # display settings
        for k in sorted(self.settings):
            v = self.settings[k]
            logger.debug('setting %20s = %r ' % (k, v))

        WebApp.singleton = self

        dirname = options.libraries
        if dirname is None:
            package = dir_from_package_name('mcdp_data')
            default_libraries = os.path.join(package, 'libraries')
            msg = (
                'Option "-d" not passed, so I will open the default libraries '
                'shipped with PyMCDP. These might not be writable depending on your setup.'
            )
            logger.info(msg)
            dirname = default_libraries

        self.dirname = dirname

        AppVisualization.__init__(self)
        AppQR.__init__(self)
        AppSolver.__init__(self)
        AppInteractive.__init__(self)
        AppSolver2.__init__(self)
        AppEditorFancyGeneric.__init__(self)
        WebAppImages.__init__(self)

        # name -> dict(desc: )
        self.views = {}
        self.exceptions = []

        self.add_model_view('syntax', 'Source code display')
        self.add_model_view('edit_fancy', 'Editor')
        # self.add_model_view('edit', 'Simple editor for IE')
        self.add_model_view('solver2', desc='Solver interface')
        self.add_model_view('ndp_graph', 'NDP Graph representation')
        self.add_model_view('ndp_repr', 'NDP Text representation')
        self.add_model_view('dp_graph', 'DP graph representation')
        self.add_model_view('dp_tree', 'DP tree representation')
        self.add_model_view('images', 'Other image representations')
        self.add_model_view('solver', 'Graphical solver [experimental]')

        # csfr_token -> Session
        self.sessions = OrderedDict()

        config_repos = yaml_load(self.options.repos_yaml)
        logger.info('Config:\n' + indent(self.options.repos_yaml, '>'))
        logger.info(config_repos)
        instance = self.options.instance
        #root= 'out/root'
        root = create_tmpdir('HostInstance_root')
        logger.debug('Tmp dir: %s' % root)

        if not 'local' in config_repos:
            config_repos['local'] = {}
        if not 'remote' in config_repos:
            config_repos['remote'] = {}

        # add the bundled repository
        bundled_repo_dir = os.path.join(dir_from_package_name('mcdp_data'),
                                        'bundled.mcdp_repo')
        config_repos['local']['bundled'] = bundled_repo_dir

        self.hi = HostInstance(instance=instance,
                               upstream='master',
                               root=root,
                               repo_git=config_repos['remote'],
                               repo_local=config_repos['local'])

        if self.options.allow_anonymous_write:
            logger.warning(
                'Note: because allow_anonymous_write anonymous users can admin the repos.'
            )
            self.hi.set_local_permission_mode()
            from pyramid.security import Allow, Everyone, ALL_PERMISSIONS
            MCDPResourceRoot.__acl__.append((Allow, Everyone, ALL_PERMISSIONS))
示例#3
0
 def __init__(self, instance, upstream, root, repo_git, repo_local):
     self.hi = HostInstance(instance=instance,
                            upstream=upstream,
                            root=root,
                            repo_git=repo_git,
                            repo_local=repo_local)