当前位置: 首页>>代码示例>>Python>>正文


Python TagEngine.replace_tags方法代码示例

本文整理汇总了Python中tractags.api.TagEngine.replace_tags方法的典型用法代码示例。如果您正苦于以下问题:Python TagEngine.replace_tags方法的具体用法?Python TagEngine.replace_tags怎么用?Python TagEngine.replace_tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tractags.api.TagEngine的用法示例。


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

示例1: _update_tags

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import replace_tags [as 别名]
    def _update_tags(self, req, page):
        newtags = set([t.strip() for t in
                      _tag_split.split(req.args.get('tags')) if t.strip()])
        wikitags = TagEngine(self.env).tagspace.wiki
        oldtags = wikitags.get_tags([page.name])

        if oldtags != newtags:
            wikitags.replace_tags(req, page.name, newtags)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:10,代码来源:web_ui.py

示例2: download_created

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import replace_tags [as 别名]
    def download_created(self, download):
        tags = TagEngine(self.env).tagspace.downloads

        # Prepare tag names.
        self._resolve_ids(download)
        tag_names = [download['author'], download['component'],
          download['version'], download['architecture'],
          download['platform'], download['type']]
        if download['tags']:
            tag_names.extend(download['tags'].split(' '))

        # Add tags to download.
        self.log.debug(tag_names)
        tags.replace_tags(None, download['id'], list(sets.Set(tag_names)))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:16,代码来源:tags.py

示例3: _do_save

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import replace_tags [as 别名]
    def _do_save(self, req, db, page):
        # This method is overridden so the user doesn't get "Page not modified"
        # exceptions when updating tags but not wiki content.
        from tractags.api import TagEngine
        if 'tags' in req.args:
            newtags = set([t.strip() for t in
                          _tag_split.split(req.args.get('tags')) if t.strip()])
            wikitags = TagEngine(self.env).tagspace.wiki
            oldtags = wikitags.get_tags([page.name])

            if oldtags != newtags:
                wikitags.replace_tags(req, page.name, newtags)
                # No changes, just redirect
                if req.args.get('text') == page.text:
                    req.redirect(self.env.href.wiki(page.name))
                    return
        return WikiModule._do_save(self, req, db, page)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:19,代码来源:web_ui.py

示例4: execute

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import replace_tags [as 别名]

#.........这里部分代码省略.........
    page_example = hdf.getValue('args.example', '')
    page_type = hdf.getValue('args.type', 'plugin')
    page_tags = get_branch_values(hdf, 'args.tags')
    page_releases = get_branch_values(hdf, 'args.releases')
    page_preview = hdf.getValue('args.previewhack', '')
    page_create = hdf.getValue('args.createhack', '')

    def write_tags(out, tags, checked = (), name = "tags", type="checkbox"):
        count = 0
        for tag in sorted(tags):
            if tag.startswith('tags/'):
                continue
            (linktext,title,desc) = getInfo(db,tag)
            link = env.href.wiki(tag)
            check = ""
            if tag in checked:
                check = " checked"
            out.write('<input type="%s" name="%s" value="%s"%s/> <a href="%s" title="%s">%s</a>&nbsp;&nbsp;\n' % (type, name, tag, check, link, title, tag))
            count += 1
            if count % 8 == 0:
                out.write("<br/>\n")
        return count

    # Validation
    if page_preview or page_create:
        try:
            fetch_page(cursor, page_name)
        except:
            pass
        else:
            errors.append("Page name %s already exists" % page_name)
        if not re.match('^([A-Z][a-z]+){2,}$', page_name): errors.append('Invalid WikiName, only alpha characters are accepted and must be CamelCase')
        if not page_name: errors.append("No WikiName provided")
        if not page_title: errors.append("No page title provided")
        if not page_type: errors.append('No page type selected')
        if not page_description: errors.append("No description provided")
        if not page_example: errors.append("No example provided")
        if not page_releases: errors.append("No releases selected")

    if page_create and not errors:
        import subprocess
        repos_dir = env.config.get('trac', 'repository_dir')
        cursor.execute("SELECT name FROM component WHERE name=%s", (page_name,))
        row = cursor.fetchone()
        if row:
            errors.append("Component '%s' already exists" % page_name)
        if subprocess.call(["svn", "ls", "%s/%s" % (SVN_LOCAL_PATH, page_name.lower())]) == 0:
            errors.append("Repository path '%s' already exists" % page_name.lower())
        if not os.access(SVN_PERMISSIONS, os.W_OK):
            errors.append("Can't write to Subversion permissions file")

        lockfile = open("/var/tmp/newhack.lock", "w")
        try:
            rv = fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
            if rv:
                errors.append('Failed to acquire lock, received error code %i' % rv)
        except IOError:
            errors.append('A hack is currently being created by another user. Try again later.')

        if not errors:
            try:
                # Insert component
                cursor.execute('INSERT INTO component (name, owner) VALUES (%s, %s)', (page_name, authname))
                # Create page
                page = WikiPage(env, page_name, db = db)
                page.text = expand_vars(fetch_page(cursor, template), generate_vars(hdf))
                out.write('Created wiki page.<br>\n')
                # Creating SVN paths
                paths = ['%s/%s' % (SVN_LOCAL_PATH, page_name.lower())]
                for release in page_releases:
                    paths.append("%s/%s/%s" % (SVN_LOCAL_PATH, page_name.lower(), release))
                output = os.popen('/usr/bin/op create-hack %s "New hack %s, created by %s" %s 2>&1' % (authname, page_name, authname, ' '.join(paths))).readlines()
                if output:
                    raise Exception("Failed to create Subversion paths:\n%s" % ''.join(output))
                out.write("Created SVN layout.<br>\n")
                # Add SVN permissions
                perms = open(SVN_PERMISSIONS, "a")
                perms.write("\n[/%s]\n%s = rw\n" % (page_name.lower(), authname))
                out.write('Added SVN write permission.<br>\n')
                out.write('\nFinished.<p><h1>Hack Details</h1>\n')
                for release in page_releases:
                    svnpath = "%s%s/%s" % (SVN_URL, page_name.lower(), release)
                    out.write('The Subversion repository path for %s is <a href="%s">%s</a>.<br>\n' % (release, svnpath, svnpath))
                out.write('The page for your hack is <a href="%s">%s</a>.<br>\n' % (env.href.wiki(page_name), page_name))
                page.save(authname, 'New hack %s, created by %s' % (page_name, authname), None)
                db.commit()
                # Add tags
                env.log.debug(vars)
                tags = [page_type, authname] + page_tags + page_releases
                env.log.debug(tags)
                wikitags.replace_tags(None, page_name, tags)
                # Finish up
                rv = fcntl.flock(lockfile, fcntl.LOCK_UN)
                return out.getvalue()
            except Exception, e:
                # TODO Roll back changes to SVN_PERMISSIONS file
                db.rollback()
                rv = fcntl.flock(lockfile, fcntl.LOCK_UN)
                env.log.error(e, exc_info=True)
                raise TracError(str(e))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:104,代码来源:NewHack.py

示例5: screenshot_changed

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import replace_tags [as 别名]
 def screenshot_changed(self, screenshot, old_screenshot):
     # Add tags to screenshot.
     old_screenshot.update(screenshot)
     tags = TagEngine(self.env).tagspace.screenshots
     tag_names = self._get_tags(old_screenshot)
     tags.replace_tags(None, old_screenshot['id'], list(sets.Set(tag_names)))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:8,代码来源:tags.py

示例6: _do_actions

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import replace_tags [as 别名]
    def _do_actions(self, req, cursor, modes, component, version):
        for mode in modes:
            if mode == "get-file":
                req.perm.assert_permission("SCREENSHOTS_VIEW")

                # Get screenshot
                match = re.match(r"""^/screenshots/(\d+)/(small|medium|large)$""", req.path_info)
                if match:
                    id = match.group(1)
                    size = match.group(2)
                screenshot = self.api.get_screenshot(cursor, id)

                # Return screenshots image action.
                file = screenshot["%s_file" % (size,)]
                path = os.path.join(self.path, str(screenshot["id"]), file)
                self.log.debug("file: %s" % (file,))
                self.log.debug("path: %s" % (path,))
                type = mimetypes.guess_type(path)[0]
                req.send_file(path, type)

            elif mode == "add":
                req.perm.assert_permission("SCREENSHOTS_ADMIN")

            elif mode == "post-add":
                req.perm.assert_permission("SCREENSHOTS_ADMIN")

                # Get form values.
                new_name = Markup(req.args.get("name"))
                new_description = Markup(req.args.get("description"))
                new_author = req.authname
                file, filename = self._get_file_from_req(req)
                content = file.read()
                new_tags = req.args.get("tags")
                new_components = req.args.get("components")
                if not isinstance(new_components, list):
                    new_components = [new_components]
                new_versions = req.args.get("versions")
                if not isinstance(new_versions, list):
                    new_versions = [new_versions]

                # Check form values
                if not new_components or not new_versions:
                    raise TracError("You must select at least one component" " and version.")

                # Check correct file type.
                reg = re.compile(r"^(.*)[.](.*)$")
                result = reg.match(filename)
                if result:
                    if not result.group(2).lower() in self.ext.split(" "):
                        raise TracError("Unsupported uploaded file type.")
                else:
                    raise TracError("Unsupported uploaded file type.")

                # Prepare images filenames.
                large_filename = re.sub(reg, r"\1_large.\2", filename)
                medium_filename = re.sub(reg, r"\1_medium.\2", filename)
                small_filename = re.sub(reg, r"\1_small.\2", filename)

                # Add new screenshot.
                screenshot_time = int(time.time())
                self.api.add_screenshot(
                    cursor,
                    new_name,
                    new_description,
                    screenshot_time,
                    new_author,
                    new_tags,
                    large_filename,
                    medium_filename,
                    small_filename,
                )

                # Get inserted screenshot.
                screenshot = self.api.get_screenshot_by_time(cursor, screenshot_time)
                self.id = screenshot["id"]

                # Add components and versions to screenshot.
                for new_component in new_components:
                    self.api.add_component(cursor, screenshot["id"], new_component)
                for new_version in new_versions:
                    self.api.add_version(cursor, screenshot["id"], new_version)

                # Create screenshot tags.
                if is_tags:
                    tags = TagEngine(self.env).tagspace.screenshots
                    tag_names = new_components
                    tag_names.extend(new_versions)
                    tag_names.extend([screenshot["name"], screenshot["author"]])
                    if screenshot["tags"]:
                        tag_names.extend(screenshot["tags"].split(" "))
                    tags.replace_tags(req, screenshot["id"], tag_names)

                # Prepare file paths
                path = os.path.join(self.path, str(self.id))
                large_filepath = os.path.join(path, large_filename)
                medium_filepath = os.path.join(path, medium_filename)
                small_filepath = os.path.join(path, small_filename)
                self.log.debug("large_filepath: %s" % (large_filepath,))
                self.log.debug("medium_filepath: %s" % (medium_filepath,))
                self.log.debug("small_filepath: %s" % (small_filepath,))
#.........这里部分代码省略.........
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:103,代码来源:core.py


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