guillermooo avatar guillermooo committed c792ca0

start porting to s3

Comments (0)

Files changed (13)

+# This script ensures that we abort pushing if we have unfinzalied Mercurial patches.
+#
+# hg-git has bug that will break the local repository if we do all the following things:
+#	1. we push changes in A.patch to Github without finalizing the patch first
+#	2. we make further changes to the patch locally and refresh
+#	3. we finalize and push A.patch to Github again
+
+if (& hg qseries) {
+	write-host "Cannot push: unfinalized patches!" -foregroundcolor RED
+	exit
+}
+
+# Override .hg/hgrc
+& hg --config "alias.push=push" push bb
+& hg --config "alias.push=push" push git

SublimeHG.sublime-commands

+[
+	{ "caption": "SublimeHg: Open Menu", "command": "show_sublime_hg_menu" },
+	{ "caption": "SublimeHg: Open CLI", "command": "show_sublime_hg_cli" },
+	{ "caption": "SublimeHg: Kill Current Server", "command": "kill_hg_server" }
+]
+param([switch]$Release)
+
+$script:thisDir = split-path $MyInvocation.MyCommand.Path -parent
+
+$publishRelease = join-path $script:thisDir "Publish.ps1"
+
+get-process "sublime_text" | stop-process
+
+# XXX: Use @boundparams instead?
+& $publishRelease -Release:$Release
+
+sss

bin/MakeRelease.ps1

-param([switch]$DontUpload=$False)
+param([switch]$Release)
 
-$here = $MyInvocation.MyCommand.Definition
-$here = split-path $here -parent
-$root = resolve-path (join-path $here "..")
+$script:thisDir = split-path $MyInvocation.MyCommand.Path -parent
 
-push-location $root
-	# rename all .tmLanguage so they don't show up in syntax menu
-	get-childitem ".\Support\*.tmLanguage" | `
-						foreach-object { copy-item $_ ($_ -replace '.tmLanguage','.hidden-tmLanguage') }
-	if (-not (test-path (join-path $root "Doc"))) {
-		new-item -itemtype "d" -name "Doc" > $null
-		copy-item ".\Data\main.css" ".\Doc"
-	}
+$mainDir = resolve-path (join-path $thisDir "..")
+$distDir = join-path $mainDir "dist"
 
-	# Generate docs in html from rst.
-	push-location ".\Doc"
-		get-childitem "..\*.rst" | foreach-object {
-									& "rst2html.py" `
-											"--template" "..\data\html_template.txt" `
-											"--stylesheet-path" "main.css" `
-											"--link-stylesheet" `
-											$_.fullname "$($_.basename).html"
-								}
-	pop-location
 
-	# Ensure MANIFEST reflects all changes to file system.
-	remove-item ".\MANIFEST" -erroraction silentlycontinue
-	start-process "python" -argumentlist ".\setup.py","spa" -NoNewWindow -Wait
+$includeFiles = @(
+        "*.py",
+        "*.sublime-keymap",
+        "*.sublime-settings",
+        "LICENSE.txt"
+    )
 
-	(get-item ".\dist\SublimeHg.sublime-package").fullname | clip.exe
+$excludeFiles = @(
+        "test_runner.py"
+    )
+
+$includeDirs = @(
+        "tests",
+        "shglib",
+        "Support"
+    )
+
+$excludeDirs = @(
+        "tests"
+    )
+
+
+if (test-path $distDir) {remove-item $distDir -recurse -force}
+
+push-location $mainDir
+    if (-not (test-path $distDir)) {[void] (new-item -itemtype 'd' $distDir)}
+
+    $includeFiles | foreach-object { get-childitem $_ } | foreach-object { copy-item $_ $distDir }
+    copy-item $includeDirs $distDir -recurse
+
+    if ($Release) {
+        get-childitem "$distDir/*" -include $excludeFiles -recurse | remove-item
+        $excludeDirs | foreach-object { get-childitem $distDir -Attribute Directory -filter $_ } | remove-item -recurse
+    }
+
+    push-location $distDir
+        & "7z.exe" "a" "-r" "-tzip" "SublimeHg.sublime-package" "."
+    pop-location
 pop-location
-
-if (-not $DontUpload) {
-	start-process "https://bitbucket.org/guillermooo/sublimehg/downloads"
-}
+param([switch]$Release, [switch]$DontUpload)
+
+$script:thisDir = split-path $MyInvocation.MyCommand.Path -parent
+$script:distDir = resolve-path((join-path $thisDir "../dist"))
+
+& (join-path $script:thisDir ".\MakeRelease.ps1") -Release:$Release
+
+$targetDir = resolve-path "~\Utilities\Sublime Text 3\Data\Installed Packages"
+
+copy-item (join-path $distDir "SublimeHg.sublime-package") $targetDir -force
+
+# clean up so that we don't clutter ST's files and folders.
+remove-item "$distDir/*" -exclude "*.sublime-package" -recurse
+
+if ($Release -and (! $DontUpload)) {
+	start-process "https://bitbucket.org/guillermooo/SublimeHg/downloads"
+	($distDir).path | clip.exe
+}
 import sublime
 import sublime_plugin
 
-from sublime_hg import run_hg_cmd
-from sublime_hg import running_servers
+from SublimeHg.sublime_hg import run_hg_cmd
+from SublimeHg.sublime_hg import running_servers
 
 
 class SublimeHgDiffSelectedCommand(sublime_plugin.TextCommand):
         text, exit_code = run_hg_cmd(running_servers[path], "status")
         if text:
             msg = "SublimeHg: Don't update to a different revision with uncommited changes. Aborting."
-            print msg
+            print(msg)
             sublime.status_message(msg)
             return
 
 
             try:
                 self.filelist.process_template_line(line)
-            except DistutilsTemplateError, msg:
+            except DistutilsTemplateError as msg:
                 self.warn("%s, line %d: %s" % (template.filename,
                                                template.current_line,
                                                msg))
         pass
 
     def run(self):
-        print NotImplementedError("Command not implemented yet.")
+        print(NotImplementedError("Command not implemented yet."))
 
 
 class test(Command):
 import struct
 import os
 
-import parsing
+from SublimeHg.shglib import parsing
 
 CH_DEBUG = 'd'
 CH_ERROR = 'e'
         startup_info = subprocess.STARTUPINFO()
         startup_info.dwFlags = subprocess.STARTF_USESHOWWINDOW
 
-    return subprocess.Popen([hg_bin, "serve", "--cmdserver", "pipe",
-                             "--repository", repo_root,
-                             "--config", "ui.interactive=False"],
-                             stdin=subprocess.PIPE,
-                             stdout=subprocess.PIPE,
-                             # If we don't redirect stderr and the server does
-                             # not support an enabled extension, we won't be
-                             # able to read stdout.
-                             stderr=subprocess.PIPE,
-                             startupinfo=startup_info)
+    try:
+        return subprocess.Popen([hg_bin, "serve", "--cmdserver", "pipe",
+                                 "--repository", repo_root,
+                                 "--config", "ui.interactive=False"],
+                                 stdin=subprocess.PIPE,
+                                 stdout=subprocess.PIPE,
+                                 # If we don't redirect stderr and the server does
+                                 # not support an enabled extension, we won't be
+                                 # able to read stdout.
+                                 stderr=subprocess.PIPE,
+                                 startupinfo=startup_info)
+    except Exception as e:
+        print(e)
+        raise
 
 
 def init_repo(root):
         fmt = '>cI'
         ch, length = struct.unpack(fmt,
                                    self.server.stdout.read(struct.calcsize(fmt)))
+
         assert len(ch) == 1, "Expected channel name of length 1."
-        if ch in 'LI':
+        if ch.decode('ascii') in 'LI':
             raise NotImplementedError("Can't provide more data to server.")
 
-        return ch, self.server.stdout.read(length)
+        text = self.server.stdout.read(length)
+        return ch, text
 
     def read_greeting(self):
         _, ascii_txt = self.read_channel()
+        ascii_txt = ascii_txt.decode('ascii')
         assert ascii_txt, "Expected hello message from server."
 
         # Parse hello message.
         # Encoding won't work well on Windows:
         # http://mercurial.selenic.com/wiki/CharacterEncodingOnWindows
         encoded_data = [x.encode(self.encoding) for x in data]
-        encoded_data = '\0'.join(encoded_data)
-        preamble = struct.pack(">I", len(encoded_data))
-        self.server.stdin.write(preamble + encoded_data)
+
+        new_data = b''
+        for i, d in enumerate(encoded_data):
+            if i != 0:
+                d = '\0' + d
+            new_data += d
+
+        preamble = struct.pack(">I", len(new_data))
+        self.server.stdin.write(preamble + new_data)
         self.server.stdin.flush()
 
     def run_command(self, cmd):
         args = list(parsing.CommandLexer(cmd))
         if args[0] == 'hg':
-            print "SublimeHg:inf: Stripped superfluous 'hg' from command."
+            print ("SublimeHg:inf: Stripped superfluous 'hg' from command.")
             args = args[1:]
 
-        print "SublimeHg:inf: Sending command '%s' as %s" % (args, args)
-        self.server.stdin.write('runcommand\n')
+        print ("SublimeHg:inf: Sending command '%s' as %s" % (args, args))
+        self.server.stdin.write('runcommand\n'.encode('ascii'))
         self._write_block(args)
 
     def receive_data(self):
         lines = []
         while True:
             channel, data = self.read_channel()
+            channel = channel.decode('ascii')
             if channel == CH_OUTPUT:
                 lines.append(data.decode(self.encoding))
             elif channel == CH_RETVAL:
                 return (''.join(lines)[:-1], struct.unpack(">l", data)[0])
             elif channel == CH_DEBUG:
-                print "debug:", data
+                print ("debug:", data)
             elif channel == CH_ERROR:
                 lines.append(data.decode(self.encoding))
-                print "error:", data
+                print ("error:", data)
             elif channel in (CH_INPUT, CH_LINE_INPUT):
-                print "More data requested, can't satisfy."
+                print ("More data requested, can't satisfy.")
                 self.shut_down()
                 return
             else:
                 self.shut_down()
-                print "Didn't expect such channel."
+                print ("Didn't expect such channel.")
                 return

shglib/commands.py

 
 def format_for_display(extension):
     all_cmds = []
-    for name, cmd_data in HG_COMMANDS[extension].iteritems():
+    for name, cmd_data in HG_COMMANDS[extension].items():
         if cmd_data.invocations:
-            for display_name, invocation in cmd_data.invocations.iteritems():
+            for display_name, invocation in cmd_data.invocations.items():
                 all_cmds.append([display_name, cmd_data.help])
         else:
             all_cmds.append([name, cmd_data.help])
     extensions.insert(0, 'default')
     for ext in extensions:
         cmds = HG_COMMANDS[ext]
-        for name, cmd_data in cmds.iteritems():
+        for name, cmd_data in cmds.items():
             if search_term in cmd_data.invocations:
                 return cmd_data.invocations[search_term], cmd_data
                 break

shglib/parsing.py

             "foo -b -c",
             "foo -b 100",
             "foo -b200",
-            "foo -b 'this is a string'",
-            "foo -b 'this is a string' --cmd \"whatever and ever\"",
-            "foo -b 'this is \\'a string'",
-            "foo -b 'mañana será otro día'",
-            "commit -m 'there are \" some things here'",
-            "commit -m 'there are \u some things here'",
-            "locate ut*.py",
+            # "foo -b 'this is a string'",
+            # "foo -b 'this is a string' --cmd \"whatever and ever\"",
+            # "foo -b 'this is \\'a string'",
+            # "foo -b 'mañana será otro día'",
+            # "commit -m 'there are \" some things here'",
+            # "commit -m 'there are \u some things here'",
+            # "locate ut*.py",
         )
     for v in values:
         lx = CommandLexer(v)
-        print v
+        print(v)
         x = list([x for x in lx])
-        print x
-        print ' '.join(x)
+        print (x)
+        print (' '.join(x))
 import sublime
 import os
 import contextlib
-import client
+
+from SublimeHg.shglib import client
 
 
 class NoRepositoryFoundError(Exception):
 import os
 import re
 
-from shglib import commands
-from shglib import utils
-from shglib.commands import AmbiguousCommandError
-from shglib.commands import CommandNotFoundError
-from shglib.commands import find_cmd
-from shglib.commands import get_commands_by_ext
-from shglib.commands import HG_COMMANDS_LIST
-from shglib.commands import RUN_IN_OWN_CONSOLE
-from shglib.parsing import CommandLexer
+from SublimeHg.shglib import commands
+from SublimeHg.shglib import utils
+from SublimeHg.shglib.commands import AmbiguousCommandError
+from SublimeHg.shglib.commands import CommandNotFoundError
+from SublimeHg.shglib.commands import find_cmd
+from SublimeHg.shglib.commands import get_commands_by_ext
+from SublimeHg.shglib.commands import HG_COMMANDS_LIST
+from SublimeHg.shglib.commands import RUN_IN_OWN_CONSOLE
+from SublimeHg.shglib.parsing import CommandLexer
 
 
 VERSION = '12.8.12'
                 try:
                     run_in_console(self.command_server.hg_bin, self.command,
                                    self.command_server.encoding)
-                except EnvironmentError, e:
+                except EnvironmentError as e:
                     sublime.status_message("SublimeHg: " + e.message)
-                    print "SublimeHg: " + e.message
-                except NotImplementedError, e:
+                    print ("SublimeHg: " + e.message)
+                except NotImplementedError as e:
                     sublime.status_message("SublimeHg: " + e.message)
-                    print "SublimeHg: " + e.message
+                    print ("SublimeHg: " + e.message)
             return
 
         # Run the requested command through the command server.
         try:
             data, exit_code = run_hg_cmd(self.command_server, self.command)
             sublime.set_timeout(functools.partial(self.show_output, data, exit_code), 0)
-        except UnicodeDecodeError, e:
-            print "SublimeHg: Can't handle command string characters."
-            print e
-        except Exception, e:
-            print "SublimeHg: Error while trying to run the command server."
-            print "*" * 80
-            print e
-            print "*" * 80
+        except UnicodeDecodeError as e:
+            print ("SublimeHg: Can't handle command string characters.")
+            print (e)
+        except Exception as e:
+            print ("SublimeHg: Error while trying to run the command server.")
+            print ("*" * 80)
+            print (e)
+            print ("*" * 80)
 
     def show_output(self, data, exit_code):
         # If we're appending to the console, do it even if there's no data.
         # Output to the console or to a separate buffer.
         if not self.append:
             p = self.view.window().new_file()
-            p_edit = p.begin_edit()
-            p.insert(p_edit, 0, data)
-            p.end_edit(p_edit)
+            # p_edit = p.begin_edit()
+            # p.insert(p_edit, 0, data)
+            p.run_command('insert_into_view', {'start': 0, 'content': data})
+            # p.end_edit(p_edit)
             p.set_name("SublimeHg - Output")
             p.set_scratch(True)
             p.settings().set('gutter', False)
             p.sel().add(sublime.Region(0, 0))
         else:
             p = self.view
-            p_edit = p.begin_edit()
+            # p_edit = p.begin_edit()
             p.insert(p_edit, self.view.size(), '\n' + data + "\n> ")
-            p.end_edit(p_edit)
+            p.run_command('insert_into_view', {'start': self.view.size(), 'content': '\n' + data + "\n> "})
+            # p.end_edit(p_edit)
             p.show(self.view.size())
 
 
+class InsertIntoView(sublime_plugin.TextCommand):
+    def run(self, edit, start, content):
+        self.view.insert(edit, start, content)
+
+
 class HgCommandRunnerCommand(sublime_plugin.TextCommand):
     def run(self, edit, cmd=None, display_name=None, cwd=None, append=False):
         self.display_name = display_name
 
         try:
             hgs = running_servers[self.cwd]
-        except utils.NoRepositoryFoundError, e:
+        except utils.NoRepositoryFoundError as e:
             msg = "SublimeHg: %s" % e
-            print msg
+            print (msg)
             sublime.status_message(msg)
             return
-        except EnvironmentError, e:
+        except EnvironmentError as e:
             msg = "SublimeHg: %s (Is the Mercurial binary on your PATH?)" % e
-            print msg
+            print (msg)
             sublime.status_message(msg)
             return
-        except Exception, e:
+        except Exception as e:
             msg = ("SublimeHg: Cannot start server."
                   "(Your Mercurial version might be too old.)")
-            print msg
+            print (msg)
             sublime.status_message(msg)
             return
 
     CMDS_FOR_DISPLAY = None
 
     def is_enabled(self):
-        return self.view.file_name()
+        return True
+        # return self.view.file_name()
 
     def run(self, edit):
         if not self.CMDS_FOR_DISPLAY:

sublime_hg_cli.py

     def is_enabled(self):
         # Do not show if the file does not have a known path. SublimeHg would
         # not be able to find the corresponding root repo for it.
-        return self.view.file_name()
+        return bool(self.view.file_name())
 
     def init_console(self):
         v = self.view.window().new_file()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.