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


Python Project.do方法代码示例

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


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

示例1: main

# 需要导入模块: from rope.base.project import Project [as 别名]
# 或者: from rope.base.project.Project import do [as 别名]
def main():
    prj = Project(os.path.realpath("../shuup/core/models"))
    rst = Restructure(prj, "_(${str})", "")
    rst.template = LanguageTwist("./shuup_fi_to_en.po")

    twist_set = rst.get_changes()

    for chg in twist_set.changes:
        print(chg.get_description())

    prj.do(twist_set)
开发者ID:NamiStudio,项目名称:shuup,代码行数:13,代码来源:language_twister.py

示例2: Agent

# 需要导入模块: from rope.base.project import Project [as 别名]
# 或者: from rope.base.project.Project import do [as 别名]
class Agent(object):
    def __init__(self, target_file, dry_run):
        self.project = Project(os.getcwd())
        self.target_file = target_file
        self.dry_run = dry_run
        self.commands = []

    @property
    def resource(self):
        return File(self.project, self.target_file)

    def add_command_class(self, command_class):
        self.commands.append(command_class)

    def do(self):
        commands = [
            command_class(self.project, self.target_file, self.dry_run)
            for command_class in self.commands
        ]
        changesets = filter(
            lambda x: x is not None,
            [
                command.get_changeset()
                for command in commands
            ]
        )

        # merge changesets
        def merge_changesets(aggregated_changeset, next_changeset):
            for change in next_changeset.changes:
                aggregated_changeset.add_change(change)
            aggregated_changeset.description += next_changeset.description
            return aggregated_changeset

        new_changeset = reduce(
            merge_changesets,
            changesets,
            ChangeSet('')
        )

        if not new_changeset.changes:
            return

        if self.dry_run:
            print new_changeset.get_description()
        else:
            self.project.do(new_changeset)
开发者ID:kevinjqiu,项目名称:imporganizer,代码行数:49,代码来源:cli.py

示例3: __init__

# 需要导入模块: from rope.base.project import Project [as 别名]
# 或者: from rope.base.project.Project import do [as 别名]
class rename:

    def __init__(self, project_path=None, module_path=None):
        """ initialize using project path and optional sub module path to limit rename scope """
        if project_path:
            self.project = Project(project_path)
        self.module_path = module_path
        self.words = set()
        self.files = []
        self.namemap = {}
        self.classname_regex = re.compile('class\s+(?P<name>[a-zA-Z0-9_]+)')
        self.methodname_regex = re.compile('def\s+(?P<name>[a-zA-Z0-9_]+)')

    def load_words(self):
        """ load all known words """
        with open('words') as f:
            for line in f:
                self.words.add(line.strip().lower())

    def load_dict(self, dictionary_path):
        """ load a custom dict with new (recognized) and restricted (unrecognized) words """
        doc = etree.parse(dictionary_path)
        for recognized in doc.xpath('/dictionary/recognized/word'):
            self.words.add(recognized.text)
        for unrecognized in doc.xpath('/dictionary/unrecognized/word'):
            if unrecognized.text in self.words:
                self.words.remove(unrecognized.text)

    def wash_word(self, string):
        """ clean up word by separating prefix, suffix and word without underscores """
        prefix = string[:string.find(string.lstrip('_'))]
        suffix = string[len(string.rstrip('_')):]
        word = string.lower().replace('_', '')
        return (prefix, word, suffix)

    def find_word(self, string, index):
        """ find the longest word from index """
        word = ''
        i = index + 1
        while i <= len(string):
            if string[index:i] in self.words:
                word = string[index:i]
            i += 1
        return word

    def reverse_find_word(self, string, index):
        """ backwards find the longest word from index """
        word = ''
        i = index - 1
        while i >= 0:
            if string[i:index] in self.words:
                word = string[i:index]
            i -= 1
        return word

    def find_words(self, string, index=-1):
        """ find all known words in a string """
        words = []
        if index == -1:
            index = len(string)
        if index == 0:
            return words
        word = self.reverse_find_word(string, index)
        if word:
            words.insert(0, word)
            index -= len(word)
        else:
            index -= 1
        w = self.find_words(string, index)
        w.extend(words)
        words = w
        #words.extend(self.find_words(string, index))
        return words

    def rename(self, string):
        """ rename string to PEP8 standard """
        index = 0
        last_index = 0
        new_name = ''
        prefix, old_name, suffix = self.wash_word(string)
        for word in self.find_words(old_name):
            index = old_name.find(word, index)
            if last_index != index:
                new_name += old_name[last_index: index]
            if len(new_name) > 0:
                new_name += '_'
            new_name += word
            index += len(word)
            last_index = index
        if last_index != len(old_name):
            if len(new_name) > 0:
                new_name += '_'
            new_name += old_name[last_index:]
        return '%s%s%s' % (prefix, new_name, suffix)

    def index_file(self, content):
        """ get all indexes for methods to rename in context
            return list of old name, position and new name """
        index = 0
        methods = []
#.........这里部分代码省略.........
开发者ID:patrikha,项目名称:pyrename,代码行数:103,代码来源:pyrename.py

示例4: Project

# 需要导入模块: from rope.base.project import Project [as 别名]
# 或者: from rope.base.project.Project import do [as 别名]
from rope.base.project import Project
from rope.refactor.rename import Rename
from rope.contrib import generate
project = Project('.')
pycore = project.pycore
package = pycore.find_module('sindice')
changes = Rename(project, package).get_changes('core')
project.do(changes)
开发者ID:muratarslan,项目名称:eice,代码行数:10,代码来源:renamer.py


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