Commits

Denis Kulikov  committed 6ebcd23

fix ascii coding in python 2. Fix call encode in python 3

  • Participants
  • Parent commits c4d4025

Comments (0)

Files changed (1)

File sublime_tfs.py

-import sublime, sublime_plugin, re
+import sublime
+import sublime_plugin
 import threading
 import locale
-import shlex
 import subprocess
 import os
 import stat
 def is_python_3_version():
     return sys.hexversion > 0x03000000
 
-def get_unicode_filename(view):
-    file_name = view.file_name() if is_python_3_version() else unicode(view.file_name())
-    return file_name.encode(locale.getpreferredencoding()) if not file_name is None else None;
-
 class TfsManager(object):
     def __init__(self):
         self.name = 'sublime_tfs'
     def run_command(self, command, path, is_graph = False, is_tfpt = False):
         try:
             commands = [self.tfpt_path if is_tfpt else self.tf_path, command, path]
+            if (not is_python_3_version()):
+                commands = map(lambda s: s.encode(locale.getpreferredencoding()), commands)
             if (is_graph):
                 p = subprocess.Popen(commands, cwd=self.cwd)
             else:
 
 class TfsCheckoutCommand(sublime_plugin.TextCommand):
     def run(self, edit):
-        path = get_unicode_filename(self.view)
+        path = self.view.file_name()
         if not (path is None):
             manager = TfsManager()
             thread = TfsRunnerThread(path, manager.checkout)
 
 class TfsUndoCommand(sublime_plugin.TextCommand):
     def run(self, edit):
-        path = get_unicode_filename(self.view)
+        path = self.view.file_name()
         if not (path is None):
             manager = TfsManager()
             thread = TfsRunnerThread(path, manager.undo)
 
 class TfsCheckinCommand(sublime_plugin.TextCommand):
     def run(self, edit):
-        path = get_unicode_filename(self.view)
+        path = self.view.file_name()
         if not (path is None):
             if (not isReadonly(path)):
                 self.view.run_command('save')
 
 class TfsHistoryCommand(sublime_plugin.TextCommand):
     def run(self, edit):
-        path = get_unicode_filename(self.view)
+        path = self.view.file_name()
         if not (path is None):
             manager = TfsManager()
             thread = TfsRunnerThread(path, manager.history)
 
 class TfsAddCommand(sublime_plugin.TextCommand):
     def run(self, edit):
-        path = get_unicode_filename(self.view)
+        path = self.view.file_name()
         if not (path is None):
             manager = TfsManager()
             thread = TfsRunnerThread(path, manager.add)
 
 class TfsGetLatestCommand(sublime_plugin.TextCommand):
     def run(self, edit):
-        path = get_unicode_filename(self.view)
+        path = self.view.file_name()
         if not (path is None):
             if (not isReadonly(path)):
                 self.view.run_command('save')
 
 class TfsDifferenceCommand(sublime_plugin.TextCommand):
     def run(self, edit):
-        path = get_unicode_filename(self.view)
+        path = self.view.file_name()
         if not (path is None):
             if (not isReadonly(path)):
                 self.view.run_command('save')
 
 class TfsDeleteCommand(sublime_plugin.TextCommand):
     def run(self, edit):
-        path = get_unicode_filename(self.view)
+        path = self.view.file_name()
         if not (path is None):
             manager = TfsManager()
             thread = TfsRunnerThread(path, manager.delete)
 
 class TfsStatusCommand(sublime_plugin.TextCommand):
     def run(self, edit):
-        path = get_unicode_filename(self.view)
+        path = self.view.file_name()
         if not (path is None):
             manager = TfsManager()
             thread = TfsRunnerThread(path, manager.status)
 
 class TfsAnnotateCommand(sublime_plugin.TextCommand):
     def run(self, edit):
-        path = get_unicode_filename(self.view)
+        path = self.view.file_name()
         if not (path is None):
             manager = TfsManager()
             thread = TfsRunnerThread(path, manager.annotate)
     def on_modified(self, view):
         if not self.manager.auto_checkout_enabled:
             return
-        path = get_unicode_filename(view)
+        path = self.view.file_name()
         if not (path is None):
             if isReadonly(path):
                 thread = TfsRunnerThread(path, self.manager.auto_checkout)