• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python env.open_environment函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中trac.env.open_environment函数的典型用法代码示例。如果您正苦于以下问题:Python open_environment函数的具体用法?Python open_environment怎么用?Python open_environment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了open_environment函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: projects_from_directory

def projects_from_directory(directory):
    """returns list of projects from a directory"""
    projects = []
    for entry in os.listdir(directory):
        try:
            open_environment(os.path.join(directory, entry))
        except:
            continue
        projects.append(entry)
    return projects
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:10,代码来源:multiproject.py


示例2: load_intertrac_setting

 def load_intertrac_setting(self):
     # interTracの設定を取得します.
     self.intertracs0 = {}
     self.aliases = {}
     for key, value in self.config.options('intertrac'):
         # オプションの数のループを回り,左辺値の.を探します.
         idx = key.rfind('.')  
         if idx > 0: 
             prefix, attribute = key[:idx], key[idx+1:]
             intertrac = self.intertracs0.setdefault(prefix, {})
             intertrac[attribute] = value
             intertrac['name'] = prefix
         else:
             self.aliases[key] = value.lower()
             intertrac = self.intertracs0.setdefault(value.lower(), {})
             intertrac.setdefault('alias', []).append(key)
     keys = self.intertracs0.keys()
     for key in keys:
         intertrac = self.intertracs0[key]
         path = intertrac.get('path', '')
         label = intertrac.get('label', '')
         url = intertrac.get('url', '')
         if path == '' or url == '':
             del self.intertracs0[key]
         else:
             if label == '':
                 label = os.path.basename(self.env.path)
                 self.log.debug(IT_ERROR_MSG4, key, label)
                 self.config.set('intertrac', key + '.label', label)
             try:
                 if self.__get_current_project_name() != label:
                     project = open_environment(path, use_cache=True)
             except Exception, e:
                 self.log.error(IT_ERROR_MSG2, key)
                 del self.intertracs0[key]
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:35,代码来源:intertrac.py


示例3: __get_intertrac_ticket

 def __get_intertrac_ticket(self, ticket, dep_en):
     # 指定されたInterTrac形式のチケット名から情報を取得する
     # 問題があった場合はエラーを返す.
     if not ticket:
         return {'error' : None}
     project_name, id, dep = self.__split_itertrac_ticket_string(ticket)
     intertrac = self.__get_project_info(project_name)
     if intertrac is None:
         return {'error' : ERROE_MSG1 % project_name}
     if id == "": 
         return {'error' : ERROE_MSG5}
     # 依存関係を指定しているか確認する 例:(FF)
     idx = id.rfind('(')
     if dep:
         if dep_en == False:
             #依存関係を使用しない場合でカッコがあった場合は
             return {'error' : ERROE_MSG7}
         if          dep.startswith('FF')==False \
                 and dep.startswith('FS')==False \
                 and dep.startswith('SF')==False \
                 and dep.startswith('SS')==False:
             return {'error' : ERROE_MSG2}
     try:
         if self.__get_current_project_name() == project_name:
             tkt = Ticket(self.env, id)
         else:
             path = intertrac.get('path', '')
             project = open_environment(path, use_cache=True)
             tkt = Ticket(project, id)
         url = intertrac.get('url', '') + '/ticket/' + id
         dep_url = intertrac.get('url', '') + '/dependency/ticket/' + id
     except Exception, e:
         return {'error' : ERROE_MSG4 % (ticket, project_name, id)}
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:33,代码来源:intertrac.py


示例4: main

def main(args=sys.argv[1:]):
    parser = OptionParser('%prog [options] project <project2> <project3> ...')
    parser.add_option('-d', '--dict', dest='dict', default=None,
                      help="python file mapping of old user, new user")
    options, args = parser.parse_args(args)

    # if no projects, print usage
    if not args:
        parser.print_help()
        sys.exit(0)

    # get the environments
    envs = []
    for arg in args:
        env = open_environment(arg)
        envs.append(env)

    # get the users
    assert options.dict
    assert os.path.exists(options.dict)
    users = eval(file(options.dict).read())
    assert isinstance(users, dict)
    if not users:
        sys.exit(0) # nothing to do

    # change the permissions
    for env in envs:
        renamer = RenameTracUsers(env)
        renamer.rename_users(users)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:29,代码来源:main.py


示例5: main

def main():
    sys.stderr = codecs.getwriter('shift_jis')(sys.stderr)

    sys.stderr.write("Running "+sys.argv[0]+"..\n")
    env = open_environment(sys.argv[1])
    env.projkey=sys.argv[2]
    owner = sys.argv[3]
    ref = DummyRef()

    print '<?xml version="1.0"?>'
    print '<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib">'
    print '<jira:CreateProject key="'+env.projkey+'" name="' + env.config.get('project', 'descr') + '" lead="'+owner+'">'
    print '''
<jira:CreatePermissionScheme name="'''+env.projkey+'''-scheme">
<jira:AddPermission permissions="Assignable,Browse,Create,Assign,Resolve,Close,ModifyReporter,Attach,Comment"
group="jira-users"
type="group"/>
<jira:SelectProjectScheme/>
</jira:CreatePermissionScheme> 
	'''
    for c in Component(env).select(env):
    	createComponent(c.name,c.description,c.owner)
    for v in Version(env).select(env):
        createMilestone(v.name)
    tickets=[]
    for t in Query(env).execute(ref):
	tickets.append(int(t["id"]))
    tickets.sort()
    i = 0
    for t in tickets:

        processTicket(env, t, owner)
    print '</jira:CreateProject>'
    print '</JiraJelly>'
开发者ID:kenichiro22,项目名称:yatrac2jira-v3,代码行数:34,代码来源:yatrac2jira-v3.py


示例6: __init__

    def __init__(self, hook_name, options, config_path=None, debug=False):
        '''
        '''
        if not config_path:
            config_path = os.path.dirname(__file__) + '/hooks.config'
        self.config = TracGerritHookConfig(config_path)
        self.options = options
        self.options_dict = options.__dict__

        self.repo_name = self.options.project_name

        self.section = self.config.get_section_for_repo(self.repo_name)
        if self.config.has_option(self.section, 'comment_always'):
            self.comment_always = self.config.getboolean(self.section, 'comment_always')

        self.trac_env = self.config.get_env_for_repo(self.repo_name)
        if not self.trac_env:
            sys.exit(0)

	if self.trac_env.startswith("http"):
            self.trac_over_rpc = True
        else:
            self.trac_over_rpc = False
            self.env = open_environment(self.trac_env)

        self.hook_name = hook_name
        self.debug = debug

        self.commit_msg = ""

        ## make sure PYTHON_EGG_CACHE is set
        if not 'PYTHON_EGG_CACHE' in os.environ:
            os.environ['PYTHON_EGG_CACHE'] = self.config.\
                                                get('hook-settings',
                                                    'python_egg_cache')
开发者ID:xx4h,项目名称:gerrit-trac-hooks,代码行数:35,代码来源:trac_update.py


示例7: project_information

    def project_information(self):
        # interTracの設定を取得します.
        intertracs0 = {}
        for key, value in self.config.options("intertrac"):
            # オプションの数のループを回り,左辺値の.を探します.
            idx = key.rfind(".")
            if idx > 0:  # .が無い場合はショートカットでので無視します
                prefix, attribute = key[:idx], key[idx + 1 :]  # 左辺値を分割します
                intertrac = intertracs0.setdefault(prefix, {})
                intertrac[attribute] = value  # 左辺値のピリオド以降をキーで右辺値を登録
                intertrac["name"] = prefix  # プロジェクト名を設定します.

        intertracs = []
        # 取得したinterTrac設定の名前が小文字になっているので元に戻します.
        # ついでに,プロジェクトの一覧表示用のデータを作成しておきます.
        # 結局はintertrac['label'] 設定することにしたので意味はないのですが,つくっちゃったのでこのままにします.
        for prefix in intertracs0:
            intertrac = intertracs0[prefix]
            # Trac.iniのパスを取得します
            path = intertrac.get("path", "")
            # trac.iniをオープンする
            project = open_environment(path, use_cache=True)
            # 名前をtrac.iniのプロジェクト名で置き換えます.
            intertrac["name"] = intertrac["label"]
            # プロジェクトの一覧表示用のデータを作成します.
            url = intertrac.get("url", "")
            title = intertrac.get("title", url)
            name = project.project_name
            intertracs.append({"name": name, "title": title, "url": url, "path": path})
        return intertracs
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:30,代码来源:admin_webui.py


示例8: get_sorted_dicts

def get_sorted_dicts (env, table, other_env=None):
    if other_env:
        from trac.env import open_environment
        env_path = os.path.join(os.path.dirname(env.path), 'ncs')
        env = open_environment(env_path, use_cache=True)

    return CustomDBTableSystem(env).sorted_dicts(table)
开发者ID:kzhamaji,项目名称:TracCustomDBTablePlugin,代码行数:7,代码来源:api.py


示例9: expand_macro

    def expand_macro(self, formatter, name, text, args):
        projects_dir = args.get('path', os.environ.get('TRAC_ENV_PARENT_DIR', '/env/trac/projects'))
	match = args.get('match', '.*')
	rawhtml = args.get('rawhtml', 'false')
	
	if not os.path.isdir(projects_dir):
	  return sys.stderr
	
        from StringIO import StringIO
        out = StringIO()
	
	for f in os.listdir(projects_dir):
	  project_dir = projects_dir + '/'+ f
	  if os.path.isdir(project_dir) and f != '.egg-cache' and re.match(match,f):
	    from trac.env import open_environment
	    selfenv = open_environment(project_dir)

	    import copy
	    context = copy.copy(formatter.context)
	    href = '/projects/' + f + '/'
	    context.href = Href(href)
	    context.req.href = context.href
	    
	    wikitext = text
	    wikitext = wikitext.replace('$dir',project_dir)
	    wikitext = wikitext.replace('$basedir',f)
	    wikitext = wikitext.replace('$name',selfenv.project_name)
	    wikitext = wikitext.replace('$href', href)
	    if rawhtml == 'false':
	      Formatter(selfenv, context).format(wikitext, out)
	    else:
	      out.write(wikitext)
	    
        return out.getvalue()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:34,代码来源:ProjectLoop.py


示例10: __init__

 def __init__(self, env=None):
     if not env:
         self.env = open_environment()
     else:
         self.env = env
     
     self._init_db()
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:7,代码来源:db.py


示例11: get_project_events

    def get_project_events(self, project, days, minutes):
        """ List all events in project that happened in a given time span.
        """
        events = []
        project_href = Href(conf.url_projects_path + "/" + project.env_name)

        req = DummyReq('user', 'password', 'method', 'uri', 'args')
        req.permissions = (
        'TICKET_VIEW', 'CHANGESET_VIEW', 'WIKI_VIEW', 'ATTACHMENT_VIEW', 'DISCUSSION_VIEW', 'MILESTONE_VIEW')
        req.authname = 'authname'
        req.abs_href = project_href

        project_env = open_environment(conf.getEnvironmentSysPath(project.env_name), use_cache=True)
        event_provider = ProjectTimelineEvents(project_env)
        last_events = event_provider.get_timeline_events(req,
            time_in_days=days,
            time_in_minutes=minutes)

        for event in last_events:
            context = Context(resource=Resource(), href=project_href)
            context.req = req
            context.perm = req.perm
            events.append([project, event, context])

        events.sort(lambda x, y: cmp(y[1]['date'], x[1]['date']))
        return events
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:26,代码来源:watchlist_events.py


示例12: _expire_cookie

    def _expire_cookie(self, req):
        """Instruct the user agent to drop the auth_session cookie by setting
        the "expires" property to a date in the past.

        Basically, whenever "trac_auth" cookie gets expired, expire
        "trac_auth_session" too.
        """
        # First of all expire trac_auth_session cookie, if it exists.
        if 'trac_auth_session' in req.incookie:
            self._expire_session_cookie(req)
        # Capture current cookie value.
        cookie = req.incookie.get('trac_auth')
        if cookie:
            trac_auth = cookie.value
        else:
            trac_auth = None
        # Then let auth.LoginModule expire all other cookies.
        auth.LoginModule._expire_cookie(self, req)
        # And finally revoke distributed authentication data too.
        if trac_auth:
            for path in self.auth_share_participants:
                env = open_environment(path, use_cache=True)
                db = env.get_db_cnx()
                cursor = db.cursor()
                cursor.execute("""
                    DELETE FROM auth_cookie
                    WHERE  cookie=%s
                    """, (trac_auth,))
                db.commit()
                env.log.debug('Auth data revoked from: ' + \
                              req.environ.get('SCRIPT_NAME', 'unknown'))
开发者ID:lkraav,项目名称:trachacks,代码行数:31,代码来源:web_ui.py


示例13: on_published

    def on_published(self, review_request=None, **kwargs):

        # Information about the review
        review_id = review_request.display_id
        ticket_ids = review_request.get_bug_list()

        # Connect to trac
        try:
            tracenv = env.open_environment(self.settings['tracsite'])
        except core.TracError:
            logging.error('Unable to open Trac site')
            return

        # Add the review to each trac ticket
        for ticket_id in ticket_ids:
            try:
                tracticket = ticket.Ticket(tracenv,tkt_id=ticket_id)
                addTracLink(tracticket, 
                        review_request.display_id,
                        review_request.submitter)
            except resource.ResourceNotFound:
                # Ticket doesn't exist
                pass
        
        # Cleanup
        tracenv.shutdown()
开发者ID:ScottWales,项目名称:reviewboard-trac-link,代码行数:26,代码来源:extension.py


示例14: globally_get_command_help

    def globally_get_command_help(self, *args):
        sys_home_project_name = self.config.get('multiproject', 'sys_home_project_name')
        for env_name, in self.projects_iterator(['env_name'], batch_size=1):
            if env_name == sys_home_project_name:
                continue
            env = None

            try:
                env_path = safe_path(self.config.get('multiproject', 'sys_projects_root'),
                    env_name)
                env = open_environment(env_path, True)
            except TracError as e:
                printout(_('ERROR: Opening environment %(env_name)s failed', env_name=env_name))
                continue

            try:
                command_manager = AdminCommandManager(env)
                helps = command_manager.get_command_help(list(args))
                if not args:
                    TracAdmin.print_doc(helps, short=True)
                elif len(helps) == 1:
                    TracAdmin.print_doc(helps, long=True)
                else:
                    TracAdmin.print_doc(helps)

            except AdminCommandError as e:
                printout(_('ERROR: Getting command help in environment %(env_name)s failed: ',
                    env_name=env_name) + e)
            break
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:29,代码来源:console.py


示例15: __init__

    def __init__(self, options):
        """
        Initialization and check of the options
        
        :param options: an object that holds all the info needed for the hook to proceed
        :type options: class

        options needs to have all these properties

        :param bugzilla: The bugzilla server URL (without the rest uri)
        :type bugzilla: string
        :param rest_uri: The REST part of the url
        :type rest_uri: string
        :param chglog: The changelog message (extracted from debian/changelog)
        :type chglog: string
        :param commentonly: Do only comment
        :type commentonly: bool
        :param msg: The commit message
        :type msg: string
        :param netrc: The netrc file location
        :type netrc: string
        :param proxy: Overrides the proxy in case you don't like the ENV one
        :type proxy: string
        :param rev: The revision number / commit hash
        :type rev: string
        :param tm: Whether to add the target milestone to the bug (as the current week)
        :type tm: bool
        :param user: The user that did the commit (coming from the VCS)
        :type user: string
        :param vcstype: What VCS are we working with (HG/GIT/SVN)
        :type vcstype: string
        :param vcsurl: the base url of the VCS (this is not trivial to guess, look at the code)
        :type vcsurl: string
        """
        supported_vcstypes = ['hg', 'git', 'trac', 'svn']
        if options.vcstype not in supported_vcstypes:
            print >> sys.stderr, "Unsupported vcs type. Supported types are %s " % supported_vcstypes
        self.options = options
        self.config = self.parse_config()
        if self.options.vcstype == 'svn':
            self.finalurl = os.path.join(self.options.vcsurl, self.config['svn_commiturl'], self.options.rev)
        elif self.options.vcstype == 'git':
            self.finalurl = self.options.vcsurl + self.config['git_commit_url'] % self.options.rev
        elif self.options.vcstype == 'hg':
            self.finalurl = os.path.join(self.options.vcsurl, self.config['hg_commit_url'], '%s' % self.options.rev)
        elif self.options.vcstype == 'trac':
            from trac.env import open_environment
            env = open_environment(self.options.vcsurl)
            self.finalurl = os.path.join(env.config.get('project', 'url'), self.config['trac_commit_url'], self.options.rev)
        else:
            print >> sys.stderr, 'Configuration is not complete: please check the options passed'
            sys.exit(1)

        if self.options.tm:
            year, week = datetime.now().isocalendar()[0:2]
            self.target_milestone = '%d-%02d' % (year, week)
        else:
            self.target_milestone = None
        self.open_statuses = [ 'NEW', 'ASSIGNED', 'REOPENED', 'WAITING', 'NEED_INFO' ]
开发者ID:bayoteers,项目名称:python-vcs-commit,代码行数:59,代码来源:vcscommit.py


示例16: _get_env

 def _get_env(self):
     if not self._env:
         assert self.exists, "Can't use a non-existant project"
         try:
             self._env = open_environment(self.env_path, use_cache=True)
             self._valid = True
         except Exception, e:
             self._env = BadEnv(self.env_path, e)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:8,代码来源:model.py


示例17: get_projects

 def get_projects(self, db=None):
     """Return an iterable of (shotname, env) for all known projects."""
     db = db or self.env.get_db_cnx()
     cursor = db.cursor()
     cursor.execute('SELECT name, env_path FROM tracforge_projects')
     for name, path in cursor:
         env = open_environment(path, use_cache=True)
         yield name, env
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:8,代码来源:api.py


示例18: import_project

 def import_project(self, sourcepath, destinationpath, name=None, **kwargs):
     if name is None:
         raise KeyError("This importer requires a Trac project to already exist. Use --name to specify it's dir name.")
     boxqueue = Queue()
     env_path = os.path.join(destinationpath, name)
     self.env = open_environment(env_path)
     import logging
     self.env.log.setLevel(logging.WARNING)
     self.log = logging.getLogger(self.env.path + '.' + self.__class__.__name__)
     self.log.setLevel(logging.DEBUG)
     
     if os.path.isdir(sourcepath):
         self.log.info('Importing directory %s', sourcepath)
         entries = os.listdir(sourcepath)
         for entry in entries:
             fullpath = os.path.join(sourcepath, entry)
             if not os.path.isfile(fullpath):
                 continue
             boxqueue.put((fullpath, None))
     else:
         self.log.info('Importing from %s', sourcepath)
         if sourcepath.endswith('.xml'):
             mlists = self.get_listdata_from_xml(sourcepath)
         elif sourcepath.endswith('.json'):
             mlists = self.get_listdata_from_json(sourcepath)
         importdir = os.path.dirname(sourcepath)
         for mlist in mlists:
             path = os.path.join(importdir, mlist.pop('mailbox'))
             if not os.path.exists(path):
                 self.log.error("Can't find mailbox %s from %s", path, sourcepath)
                 continue
             if mlist.get('mailboxmd5'):
                 self.log.debug('Checking MD5 sum of %s...', path)
                 md5digest = md5(open(path, 'r').read()).hexdigest()
                 if md5digest != mlist['mailboxmd5']:
                     self.log.error("%s's md5 (%s) doesn't match %s from %s. Skipping it", path, md5digest, mlist['mailboxmd5'], sourcepath)
                     continue
                 self.log.debug('MD5 of %s ok', path)
             else:
                 self.log.warning("No md5 found for %s in %s", path, sourcepath)
             boxqueue.put((path, mlist))
         else:
             boxqueue.put((sourcepath, None))
     def worker(queue):
         while True:
             mbox, metadata = queue.get()
             try:
                 self.read_file(mbox, metadata)
             except:
                 self.log.exception("Error in %s", mbox)
             queue.task_done()
     for _ in range(min(boxqueue.qsize(), 5)):
         t = Thread(target=worker, args=(boxqueue,))
         t.daemon = True
         t.start()
     boxqueue.join()
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-mailinglist,代码行数:56,代码来源:importers.py


示例19: _open_environment

def _open_environment(env_path, run_once=False):
    if run_once:
        return open_environment(env_path)

    global env_cache, env_cache_lock
    env = None
    env_cache_lock.acquire()
    try:
        if not env_path in env_cache:
            env_cache[env_path] = open_environment(env_path)
        env = env_cache[env_path]
    finally:
        env_cache_lock.release()

    # Re-parse the configuration file if it changed since the last the time it
    # was parsed
    env.config.parse_if_needed()

    return env
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:19,代码来源:main.py


示例20: trac_projects

 def trac_projects(self):
     """returns existing Trac projects"""
     proj = {}
     for i in os.listdir(self.directory):
         try:
             env = open_environment(os.path.join(self.directory, i))
         except:
             continue
         proj[i] = env
     return proj
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:10,代码来源:web.py



注:本文中的trac.env.open_environment函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python env.Environment类代码示例发布时间:2022-05-27
下一篇:
Python api.DatabaseManager类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap