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


Python file_tools.FileTools类代码示例

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


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

示例1: run

  def run(self, edit):
    super(RubocopAutoCorrectCommand, self).run(edit)

    cancel_op = self.user_wants_to_cancel()
    if cancel_op:
      return

    view = self.view
    path = view.file_name()
    quoted_file_path = FileTools.quote(path)

    if view.is_read_only():
      sublime.message_dialog('RuboCop: Unable to run auto correction on a read only buffer.')
      return

    # Inform user about unsaved contents of current buffer
    if view.is_dirty():
      warn_msg = 'RuboCop: The curent buffer is modified. Save the file and continue?'
      cancel_op = not sublime.ok_cancel_dialog(warn_msg)

    if cancel_op:
      return
    else:
      view.run_command('save')

    RubocopEventListener.instance().clear_marks(view)

    quoted_file_path = FileTools.quote(path)

    # Run rubocop with auto-correction
    self.runner.run(quoted_file_path, '-a')

    sublime.status_message('RuboCop: Auto correction done.')
开发者ID:ayonkhan,项目名称:sublime_rubocop,代码行数:33,代码来源:rubocop_command.py

示例2: run

  def run(self, edit):
    super(RubocopAutoCorrectCommand, self).run(edit)

    cancel_op = self.warning_msg()
    if cancel_op:
      return

    view = self.view
    path = view.file_name()
    quoted_file_path = FileTools.quote(path)

    if view.is_read_only():
      sublime.message_dialog('RuboCop: Unable to run auto correction on a read only buffer.')
      return

    # Inform user about unsaved contents of current buffer
    if view.is_dirty():
      warn_msg = 'RuboCop: The curent buffer is modified. Save the file and continue?'
      cancel_op = not sublime.ok_cancel_dialog(warn_msg)

    if cancel_op:
      return
    else:
      view.run_command('save')

    RubocopEventListener.instance().clear_marks(view)

    # Copy the current file to a temp file
    content = view.substr(sublime.Region(0, view.size()))
    f = tempfile.NamedTemporaryFile()

    try:
      self.write_to_file(f, content, view)
      f.flush()

      # Create path for possible config file in the source directory
      quoted_file_path = FileTools.quote(path)
      config_opt = '-c ' + os.path.dirname(quoted_file_path) + '/.rubocop.yml'
      print(config_opt)

      # Run rubocop with auto-correction on temp file
      self.runner.run(f.name, '-a ' + config_opt)

      # Read contents of file
      f.seek(0)
      content = self.read_from_file(f, view)

      # Overwrite buffer contents
      rgn = sublime.Region(0, view.size())
      view.replace(edit, rgn, content)
    finally:
      # TempFile will be deleted here
      f.close()

    sublime.status_message('RuboCop: Auto correction done.')
开发者ID:Mondego,项目名称:pyreco,代码行数:55,代码来源:allPythonContent.py

示例3: open_ruby_files

 def open_ruby_files(self):
   files = []
   views = self.view.window().views()
   for vw in views:
     if FileTools.is_ruby_file(vw):
       files.append(vw.file_name())
   return files
开发者ID:pderichs,项目名称:sublime_rubocop,代码行数:7,代码来源:rubocop_command.py

示例4: run_rubocop

  def run_rubocop(self, view):
    s = sublime.load_settings(SETTINGS_FILE)

    use_rvm = view.settings().get('check_for_rvm', s.get('check_for_rvm'))
    use_rbenv = view.settings().get('check_for_rbenv', s.get('check_for_rbenv'))
    cmd = view.settings().get('rubocop_command', s.get('rubocop_command'))
    rvm_path = view.settings().get('rvm_auto_ruby_path', s.get('rvm_auto_ruby_path'))
    rbenv_path = view.settings().get('rbenv_path', s.get('rbenv_path'))
    cfg_file = view.settings().get('rubocop_config_file', s.get('rubocop_config_file'))
    chdir = view.settings().get('rubocop_chdir', s.get('rubocop_chdir'))

    if cfg_file:
      cfg_file = FileTools.quote(cfg_file)

    runner = RubocopRunner(
      {
        'use_rbenv': use_rbenv,
        'use_rvm': use_rvm,
        'custom_rubocop_cmd': cmd,
        'rvm_auto_ruby_path': rvm_path,
        'rbenv_path': rbenv_path,
        'on_windows': sublime.platform() == 'windows',
        'rubocop_config_file': cfg_file,
        'chdir': chdir,
        'is_st2': sublime.version() < '3000'
      }
    )
    output = runner.run([view.file_name()], ['--format', 'emacs']).splitlines()

    return output
开发者ID:TristinDavis,项目名称:sublime_rubocop,代码行数:30,代码来源:rubocop_listener.py

示例5: do_post_save_check

 def do_post_save_check(self, view):
   self.clear_marks(view)
   if not sublime.load_settings(SETTINGS_FILE).get('check_on_save'):
     return
   if not FileTools.is_ruby_file(view.file_name()):
     return
   results = self.run_rubocop(view.file_name())
   self.set_marks_by_results(view, results)
开发者ID:noahpatterson,项目名称:sublime_rubocop,代码行数:8,代码来源:event_listener.py

示例6: open_ruby_files

 def open_ruby_files(self):
   files = []
   views = self.view.window().views()
   for vw in views:
     file_path = vw.file_name()
     if FileTools.is_ruby_file(file_path):
       files.append(file_path)
   return files
开发者ID:ayonkhan,项目名称:sublime_rubocop,代码行数:8,代码来源:rubocop_command.py

示例7: run_rubocop_on

  def run_rubocop_on(self, path, file_list=False):
    if not path:
      return

    if not file_list:
      # Single item to check.
      quoted_file_path = FileTools.quote(path)
      working_dir = os.path.dirname(path)
    else:
      # Multiple files to check.
      working_dir = '.'
      quoted_file_path = ''
      for file in path:
        quoted_file_path += FileTools.quote(file) + ' '

    rubocop_cmd = self.runner.command_string(
      quoted_file_path, self.used_options()
    )
    self.run_shell_command(rubocop_cmd, working_dir)
开发者ID:ayonkhan,项目名称:sublime_rubocop,代码行数:19,代码来源:rubocop_command.py

示例8: run_rubocop_on

  def run_rubocop_on(self, path, file_list=False):
    if not path:
      return

    if not file_list:
      # Single item to check.
      quoted_file_path = FileTools.quote(path)
      working_dir = os.path.dirname(quoted_file_path)
    else:
      # Multiple files to check.
      working_dir = '.'
      quoted_file_path = ''
      for file in path:
        quoted_file_path += FileTools.quote(file) + ' '

    cop_command = self.command_with_options()
    rubocop_cmd = cop_command.replace('{path}', quoted_file_path)

    self.run_shell_command(rubocop_cmd, working_dir)
开发者ID:Mondego,项目名称:pyreco,代码行数:19,代码来源:allPythonContent.py

示例9: run_rubocop_on

    def run_rubocop_on(self, pathlist):
        if len(pathlist) == 0:
            return

        working_dir = self.current_project_folder()

        quoted_paths = []
        for path in pathlist:
            quoted_paths.append(FileTools.quote(path))

        rubocop_cmd = self.runner.command_string(quoted_paths, self.used_options())

        self.run_shell_command(rubocop_cmd, working_dir)
开发者ID:evgenii,项目名称:sublime_rubocop,代码行数:13,代码来源:rubocop_command.py

示例10: load_config

 def load_config(self):
   s = sublime.load_settings(SETTINGS_FILE)
   cfg_file = s.get('rubocop_config_file')
   if cfg_file:
     cfg_file = FileTools.quote(cfg_file)
   self.runner = RubocopRunner(
     {
       'use_rbenv': s.get('check_for_rbenv'),
       'use_rvm': s.get('check_for_rvm'),
       'custom_rubocop_cmd': s.get('rubocop_command'),
       'rvm_auto_ruby_path': s.get('rvm_auto_ruby_path'),
       'rbenv_path': s.get('rbenv_path'),
       'on_windows': (sublime.platform() == 'windows'),
       'rubocop_config_file': cfg_file
     }
   )
开发者ID:ayonkhan,项目名称:sublime_rubocop,代码行数:16,代码来源:rubocop_command.py

示例11: run

  def run(self, edit):
    super(RubocopOpenAllOffensiveFilesCommand, self).run(edit)

    folders = self.view.window().folders()
    if len(folders) <= 0:
      sublime.status_message('RuboCop: No project folder available.')
      return

    folder = FileTools.quote(folders[0])

    # Run rubocop with file formatter
    file_list = self.runner.run([folder], ['--format files']).splitlines()

    for path in file_list:
      self.view.window().open_file(path.decode(locale.getpreferredencoding()))

    sublime.status_message('RuboCop: Opened ' + str(len(file_list)) + ' files.')
开发者ID:pderichs,项目名称:sublime_rubocop,代码行数:17,代码来源:rubocop_command.py

示例12: load_config

 def load_config(self):
     s = sublime.load_settings(SETTINGS_FILE)
     cfg_file = s.get("rubocop_config_file")
     if cfg_file:
         cfg_file = FileTools.quote(cfg_file)
     self.runner = RubocopRunner(
         {
             "use_rbenv": s.get("check_for_rbenv"),
             "use_rvm": s.get("check_for_rvm"),
             "custom_rubocop_cmd": s.get("rubocop_command"),
             "rvm_auto_ruby_path": s.get("rvm_auto_ruby_path"),
             "rbenv_path": s.get("rbenv_path"),
             "on_windows": self.on_windows(),
             "rubocop_config_file": cfg_file,
             "is_st2": self.is_st2(),
         }
     )
开发者ID:evgenii,项目名称:sublime_rubocop,代码行数:17,代码来源:rubocop_command.py

示例13: run_rubocop

 def run_rubocop(self, path):
   s = sublime.load_settings(SETTINGS_FILE)
   use_rvm = s.get('check_for_rvm')
   use_rbenv = s.get('check_for_rbenv')
   cmd = s.get('rubocop_command')
   rvm_path = s.get('rvm_auto_ruby_path')
   rbenv_path = s.get('rbenv_path')
   cfg_file = s.get('rubocop_config_file')
   if cfg_file:
     cfg_file = FileTools.quote(cfg_file)
   runner = RubocopRunner(
     {
       'use_rbenv': use_rbenv,
       'use_rvm': use_rvm,
       'custom_rubocop_cmd': cmd,
       'rvm_auto_ruby_path': rvm_path,
       'rbenv_path': rbenv_path,
       'on_windows': sublime.platform() == 'windows',
       'rubocop_config_file': cfg_file
     }
   )
   output = runner.run(path, '--format emacs').splitlines()
   return output
开发者ID:ayonkhan,项目名称:sublime_rubocop,代码行数:23,代码来源:rubocop_listener.py

示例14: do_in_file_check

 def do_in_file_check(self, view):
   if not FileTools.is_ruby_file(view.file_name()):
     return
   mark = sublime.load_settings(SETTINGS_FILE).get('mark_issues_in_view')
   self.mark_issues(view, mark)
开发者ID:joshuapaling,项目名称:sublime_rubocop,代码行数:5,代码来源:rubocop_listener.py


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