python类error_message()的实例源码

command_base.py 文件源码 项目:ElectricImp-Sublime 作者: electricimp 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def entered_filename(self, filename):
        # Check if valid root specified for windows.
        if PLATFORM == "windows":
            if re.match(WIN_ROOT_REGEX, filename):
                root = filename[0:3]
                if not os.path.isdir(root):
                    sublime.error_message(root + " is not a valid root.")
                    self.clear()
                    return

        base, path = self.split_path(filename)
        file_path = generate_creation_path(self.settings, base, path, True)
        # Check for invalid alias specified.
        is_valid = (TOP_LEVEL_SPLIT_CHAR in filename and
                    not self.platform.is_absolute_path(base))
        if is_valid:
            if base == "":
                error_message = "Current file cannot be resolved."
            else:
                error_message = "'" + base + "' is an invalid alias."
            sublime.error_message(error_message)

        self.entered_file_action(file_path)
delete_file_command.py 文件源码 项目:ElectricImp-Sublime 作者: electricimp 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _delete_file(self, filepath):
        if not filepath:
            return
        elif not os.path.isfile(filepath):
            sublime.error_message("%s is not a file" % filepath)
            return

        if not sublime.ok_cancel_dialog("Delete this file?\n%s" % filepath):
            return

        vcs_tracking = (self.file_tracked_by_git(filepath) and
                        self.settings.get(VCS_MANAGEMENT_SETTING))

        self.close_view(filepath)

        if vcs_tracking:
            self._git_rm(filepath)
        else:
            self._execute_delete_file(filepath)

        self.refresh_sidebar()
set_target.py 文件源码 项目:CMakeBuilder 作者: rwols 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def run(self, index=None, name=None):
        if self.server.is_configuring:
            sublime.error_message("CMake is configuring, please wait.")
            return
        if not self.server.targets:
            sublime.error_message("No targets found! "
                                  "Did you configure the project?")
            return
        if name is not None:
            self._on_done(name)
        elif not index:
            self.items = [
                [t.name, t.type, t.directory] for t in self.server.targets]
            self.window.show_quick_panel(self.items, self._on_done)
        else:
            self._on_done(index)
new_project.py 文件源码 项目:CMakeBuilder 作者: rwols 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _create_project(self):
        os.makedirs(self.project_dir, exist_ok=True)
        if not os.path.exists(self.project_dir):
            sublime.error_message("Could not create directory %s" % self.project_dir)
        os.makedirs(os.path.join(self.project_dir, "src"), exist_ok=True)
        with open(os.path.join(self.project_dir, "CMakeLists.txt"), "w") as f:
            f.write(CMAKELISTS_FILE.format(self.project_name, self.type))
        with open(os.path.join(self.project_dir, "src", "main." + self.suffix), "w") as f:
            if self.type == "C":
                f.write(CFILE)
            else:
                f.write(CXXFILE)
        with open(os.path.join(self.project_dir, "src", "CMakeLists.txt"), "w") as f:
            f.write(CMAKELISTS_SRC_FILE.format(self.suffix))
        project_file = os.path.join(self.project_dir, self.project_name + ".sublime-project")
        with open(project_file, "w") as f:
            f.write(PROJECTFILE)
        if sublime.ok_cancel_dialog('Select the file %s in "%s" in the upcoming prompt...' % (self.project_name + ".sublime-project", self.project_dir)):
            sublime.run_command("prompt_open_project_or_workspace")
dired.py 文件源码 项目:sublime-dired 作者: Twizzledrizzle 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _on_done(self, which, value):
        value = value.strip()
        if not value:
            return

        fqn = join(self.path, value)
        if exists(fqn):
            sublime.error_message('{} already exists'.format(fqn))
            return

        if which == 'directory':
            os.makedirs(fqn)
        else:
            open(fqn, 'wb')

        self.view.run_command('dired_refresh', {'goto': value})
dired.py 文件源码 项目:sublime-dired 作者: Twizzledrizzle 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _move(self, path):
        if path == self.path:
            return

        files = self.get_marked() or self.get_selected()

        if not isabs(path):
            path = join(self.path, path)
        if not isdir(path):
            sublime.error_message('Not a valid directory: {}'.format(path))
            return

        # Move all items into the target directory.  If the target directory was also selected,
        # ignore it.
        files = self.get_marked() or self.get_selected()
        path = normpath(path)
        for filename in files:
            fqn = normpath(join(self.path, filename))
            if fqn != path:
                shutil.move(fqn, path)
        self.view.run_command('dired_refresh')
solium-gutter.py 文件源码 项目:sublime-solium-gutter 作者: sey 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def run_script_on_file(self, temp_file_path):
    try:
      node_path = PluginUtils.get_node_path()
      script_path = PLUGIN_FOLDER + "/scripts/run.js"
      file_path = self.view.file_name()
      cmd = [node_path, script_path, temp_file_path, file_path or "?"]
      output = SoliumGutterCommand.get_output(cmd)
      print(output)
      if output.find(OUTPUT_VALID) != -1:
        output = output.decode('utf-8');
        return output
      print(output)
      raise Exception(output)
    except:
      # Something bad happened.
      print("Unexpected error({0}): {1}".format(sys.exc_info()[0], sys.exc_info()[1]))

      # Usually, it's just node.js not being found. Try to alleviate the issue.
      msg = "Node.js was not found in the default path. Please specify the location."
      if not sublime.ok_cancel_dialog(msg):
        msg = "You won't be able to use this plugin without specifying the path to node.js."
        sublime.error_message(msg)
      else:
        PluginUtils.open_sublime_settings(self.view.window())
pico_setup_path.py 文件源码 项目:sublime-PICO-8 作者: Neko250 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def run(self, edit):
        def done(path):
            settings = sublime.load_settings("PICO-8.sublime-settings")
            settings.set("pico-8_path", path)
            sublime.save_settings("PICO-8.sublime-settings")
            return

        platform = sublime.platform()
        if platform == "linux":
            self.view.window().show_input_panel("PICO-8 Path", "/path/to/pico8", done, None, None)
        elif platform == "osx":
            self.view.window().show_input_panel("PICO-8 Path", "/path/to/PICO-8.app/Contents/MacOS/pico8", done, None, None)
        elif platform == "windows":
            self.view.window().show_input_panel("PICO-8 Path", "C:\\Program Files (x86)\\PICO-8\\pico8.exe", done, None, None)
        else:
            sublime.error_message("Error: could not resolve platform\n\n[\"linux\", \"osx\", \"windows\"]")
            return
main.py 文件源码 项目:Codeforces-Sublime-Plugin 作者: karunk 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run(self):
        head, tail = os.path.split(self.window.active_view().file_name())
        CurrentWindowFileName = self.window.active_view().file_name().split('/')[-1].split('.')[0]
        CurrentWindowFileType = self.window.active_view().file_name().split('/')[-1].split('.')[-1]

        if os.path.isfile(CurrentWindowFileName) == False:
            sublime.error_message("You have not complied your solution! Build the executable using sublime text")
            return

        inputFile = CurrentWindowFileName+"_input.in"
        outputFile = CurrentWindowFileName+"_output.out"

        if os.path.isfile(inputFile) == False:
            print(os.path.isfile(inputFile), inputFile)
            sublime.error_message("Initialize the input first! Enter your custom testcases here")
            self.window.open_file(inputFile)
            return


        cmd = QuoteFunc(head + '/' + tail.split('.')[0])+"<"+QuoteFunc(head + '/' + inputFile)+">"+QuoteFunc(head + '/' + outputFile)
        command = Command(cmd)
        command.run(timeout = 3)
        self.window.open_file(outputFile)
RemoteCpp.py 文件源码 项目:RemoteCpp 作者: ruibm 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def show_file_input(view, title, on_done):
  file = STATE.file(view.file_name())
  if file == None:
    path = s_cwd()
    path = path + os.sep
  else:
    path = file.remote_path()
  def on_done_callback(new_file):
    log('The user has chosen: ' + new_file)
    cwd = s_cwd()
    if not new_file.startswith(cwd):
      sublime.error_message('File must be under CWD:\n\n' + cwd)
      return
    path = new_file[len(cwd) + 1:]
    file = File(cwd=cwd, path=path)
    on_done(file)
  view.window().show_input_panel(
      caption=title,
      initial_text=path,
      on_done=on_done_callback,
      on_change=None,
      on_cancel=None,
  )
RemoteCpp.py 文件源码 项目:RemoteCpp 作者: ruibm 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _run_in_the_background(self, view, src_file, dst_file):
    try:
      ssh_cmd('mv "{src}" "{dst}"'.format(
          src=src_file.remote_path(),
          dst=dst_file.remote_path()))
    except:
      log_exception('Failed to mv remote files.')
      sublime.error_message(
          'Failed to move files remotely.\n\nSRC={src}\n\nDST={dst}'.format(
                src=src_file.remote_path(),
                dst=dst_file.remote_path()))
      return
    self._rm_local_file(src_file.local_path())
    self._rm_local_file(dst_file.local_path())
    Commands.open_file(self.view, dst_file.to_args())
    log(dir(self.view))
    view.close()
    STATE.update_list(cwd=s_cwd(view),
                      files_to_add=[dst_file],
                      files_to_rm=[src_file])
ESLint-Formatter.py 文件源码 项目:ESLint-Formatter 作者: TheSavior 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def run_script_on_file(self, data):
    try:
      dirname = os.path.dirname(data)
      node_path = PluginUtils.get_node_path()
      eslint_path = PluginUtils.get_eslint_path(dirname)

      if eslint_path == False:
        sublime.error_message('ESLint could not be found on your path')
        return;

      cmd = [node_path, eslint_path, '--fix', data]

      config_path = PluginUtils.get_pref("config_path")

      if os.path.isfile(config_path):
        # If config file path exists, use as is
        full_config_path = config_path
      else:
        # Find config gile relative to project path
        project_path = PluginUtils.project_path()
        full_config_path = os.path.join(project_path, config_path)

      if os.path.isfile(full_config_path):
        print("Using configuration from {0}".format(full_config_path))
        cmd.extend(["--config", full_config_path])

      if self.view.file_name():
          cdir = os.path.dirname(self.view.file_name())
      else:
          cdir = "/"

      output = PluginUtils.get_output(cmd, cdir, data)

      return output;

    except:
      # Something bad happened.
      msg = str(sys.exc_info()[1])
      print("Unexpected error({0}): {1}".format(sys.exc_info()[0], msg))
      sublime.error_message(msg)
run_elixir_test.py 文件源码 项目:sublime-text-elixir-tests 作者: tarzan 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def run(self, args):
    self.load_config()
    self.save_all()
    file = self.file_type(self.view.file_name())
    command = file.run_all_tests_command()
    if self.run_shell_command(command, file.get_project_root()):
      pass
    else:
      sublime.error_message("Only *.exs files supported!")
run_elixir_test.py 文件源码 项目:sublime-text-elixir-tests 作者: tarzan 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def file_name_input(self, file_name):
      full_path = os.path.join(self.selected_dir, file_name)

      if os.path.lexists(full_path):
          sublime.error_message('File already exists:\n%s' % full_path)
          return
      else:
          self.create_and_open_file(full_path)
TerminalView.py 文件源码 项目:TerminalView 作者: Wramberg 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def run(self,
            cmd="/bin/bash -l",
            title="Terminal",
            cwd=None,
            syntax=None,
            keep_open=False):
        """
        Open a new terminal view

        Args:
            cmd (str, optional): Shell to execute. Defaults to 'bash -l.
            title (str, optional): Terminal view title. Defaults to 'Terminal'.
            cwd (str, optional): The working dir to start out with. Defaults to
                                 either the currently open file, the currently
                                 open folder, $HOME, or "/", in that order of
                                 precedence. You may pass arbitrary snippet-like
                                 variables.
            syntax (str, optional): Syntax file to use in the view.
            keep_open (bool, optional): Keep view open after cmd exits.
        """
        if sublime.platform() not in ("linux", "osx"):
            sublime.error_message("TerminalView: Unsupported OS")
            return

        st_vars = self.window.extract_variables()
        if not cwd:
            cwd = "${file_path:${folder}}"
        cwd = sublime.expand_variables(cwd, st_vars)
        if not cwd:
            cwd = os.environ.get("HOME", None)
        if not cwd:
            # Last resort
            cwd = "/"

        args = {"cmd": cmd, "title": title, "cwd": cwd, "syntax": syntax, "keep_open": keep_open}
        self.window.new_file().run_command("terminal_view_activate", args=args)
sublime_terminal_buffer.py 文件源码 项目:TerminalView 作者: Wramberg 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def run(self, _, **kwargs):
        # Lookup the sublime buffer instance for this view the first time this
        # command is called
        if self._sub_buffer is None:
            self._sub_buffer = SublimeBufferManager.load_from_id(self.view.id())

        if type(kwargs["key"]) is not str:
            sublime.error_message("Terminal View: Got keypress with non-string key")
            return

        if "meta" in kwargs and kwargs["meta"]:
            sublime.error_message("Terminal View: Meta key is not supported yet")
            return

        if "meta" not in kwargs:
            kwargs["meta"] = False
        if "alt" not in kwargs:
            kwargs["alt"] = False
        if "ctrl" not in kwargs:
            kwargs["ctrl"] = False
        if "shift" not in kwargs:
            kwargs["shift"] = False

        # Lookup the sublime buffer instance for this view
        sublime_buffer = SublimeBufferManager.load_from_id(self.view.id())
        keypress_cb = sublime_buffer.keypress_callback()
        app_mode = sublime_buffer.terminal_emulator().application_mode_enabled()
        if keypress_cb:
            keypress_cb(kwargs["key"], kwargs["ctrl"], kwargs["alt"],
                        kwargs["shift"], kwargs["meta"], app_mode)
BaseCommand.py 文件源码 项目:sublime-commandbox 作者: Ortus-Solutions 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def error_message(self, text):
        sublime.error_message("%s: %s" % (self.package_name, text))

    # Output view
commands.py 文件源码 项目:sublime-text-3-packages 作者: nickjj 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def copy_linter(self, name):
        """Copy the template linter to a new linter with the given name."""

        self.name = name
        self.fullname = 'SublimeLinter-contrib-{}'.format(name)
        self.dest = os.path.join(sublime.packages_path(), self.fullname)

        if os.path.exists(self.dest):
            sublime.error_message('The plugin “{}” already exists.'.format(self.fullname))
            return

        src = os.path.join(sublime.packages_path(), persist.PLUGIN_DIRECTORY, 'linter-plugin-template')
        self.temp_dir = None

        try:
            self.temp_dir = tempfile.mkdtemp()
            self.temp_dest = os.path.join(self.temp_dir, self.fullname)
            shutil.copytree(src, self.temp_dest)

            self.get_linter_language(name, self.configure_linter)

        except Exception as ex:
            if self.temp_dir and os.path.exists(self.temp_dir):
                shutil.rmtree(self.temp_dir)

            sublime.error_message('An error occurred while copying the template plugin: {}'.format(str(ex)))
commands.py 文件源码 项目:sublime-text-3-packages 作者: nickjj 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def configure_linter(self, language):
        """Fill out the template and move the linter into Packages."""

        try:
            if language is None:
                return

            if not self.fill_template(self.temp_dir, self.name, self.fullname, language):
                return

            git = util.which('git')

            if git:
                subprocess.call((git, 'init', self.temp_dest))

            shutil.move(self.temp_dest, self.dest)

            util.open_directory(self.dest)
            self.wait_for_open(self.dest)

        except Exception as ex:
            sublime.error_message('An error occurred while configuring the plugin: {}'.format(str(ex)))

        finally:
            if self.temp_dir and os.path.exists(self.temp_dir):
                shutil.rmtree(self.temp_dir)
util.py 文件源码 项目:sublime-text-3-packages 作者: nickjj 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def create_tempdir():
    """Create a directory within the system temp directory used to create temp files."""
    try:
        if os.path.isdir(tempdir):
            shutil.rmtree(tempdir)

        os.mkdir(tempdir)

        # Make sure the directory can be removed by anyone in case the user
        # runs ST later as another user.
        os.chmod(tempdir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

    except PermissionError:
        if sublime.platform() != 'windows':
            current_user = pwd.getpwuid(os.geteuid())[0]
            temp_uid = os.stat(tempdir).st_uid
            temp_user = pwd.getpwuid(temp_uid)[0]
            message = (
                'The SublimeLinter temp directory:\n\n{0}\n\ncould not be cleared '
                'because it is owned by \'{1}\' and you are logged in as \'{2}\'. '
                'Please use sudo to remove the temp directory from a terminal.'
            ).format(tempdir, temp_user, current_user)
        else:
            message = (
                'The SublimeLinter temp directory ({}) could not be reset '
                'because it belongs to a different user.'
            ).format(tempdir)

        sublime.error_message(message)

    from . import persist
    persist.debug('temp directory:', tempdir)


问题


面经


文章

微信
公众号

扫码关注公众号