[MediaWiki-commits] [Gerrit] Add sh.py into the repository to avoid dependency issues - change (labs...wikipedia-android-builds)

2014-10-17 Thread Yuvipanda (Code Review)
Yuvipanda has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/167205

Change subject: Add sh.py into the repository to avoid dependency issues
..

Add sh.py into the repository to avoid dependency issues

Change-Id: Ieeac5a409f3a6cc71ef48c320166e9fd8ad5f87e
---
A src/sh.py
1 file changed, 1,770 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/tools/wikipedia-android-builds 
refs/changes/05/167205/1

diff --git a/src/sh.py b/src/sh.py
new file mode 100644
index 000..5bf2e68
--- /dev/null
+++ b/src/sh.py
@@ -0,0 +1,1770 @@
+#===
+# Copyright (C) 2011-2012 by Andrew Moffat
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the Software), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#===
+
+
+__version__ = 1.09
+__project_url__ = https://github.com/amoffat/sh;
+
+
+
+import platform
+
+if windows in platform.system().lower():
+raise ImportError(sh %s is currently only supported on linux and osx. \
+please install pbs 0.110 (http://pypi.python.org/pypi/pbs) for windows \
+support. % __version__)
+
+
+
+import sys
+IS_PY3 = sys.version_info[0] == 3
+
+import traceback
+import os
+import re
+from glob import glob as original_glob
+from types import ModuleType
+from functools import partial
+import inspect
+import time as _time
+
+from locale import getpreferredencoding
+DEFAULT_ENCODING = getpreferredencoding() or utf-8
+
+
+if IS_PY3:
+from io import StringIO
+from io import BytesIO as cStringIO
+from queue import Queue, Empty
+else:
+from StringIO import StringIO
+from cStringIO import OutputType as cStringIO
+from Queue import Queue, Empty
+
+IS_OSX = platform.system() == Darwin
+THIS_DIR = os.path.dirname(os.path.realpath(__file__))
+
+
+import errno
+import warnings
+
+import pty
+import termios
+import signal
+import gc
+import select
+import atexit
+import threading
+import tty
+import fcntl
+import struct
+import resource
+from collections import deque
+import logging
+import weakref
+
+
+logging_enabled = False
+
+
+if IS_PY3:
+raw_input = input
+unicode = str
+basestring = str
+
+
+def encode_to_py3bytes_or_py2str(s):
+ takes anything and attempts to return a py2 string or py3 bytes.  this
+is typically used when creating command + arguments to be executed via
+os.exec* 
+
+fallback_encoding = utf8
+
+if IS_PY3:
+s = str(s)
+try:
+s = bytes(s, DEFAULT_ENCODING)
+except UnicodeEncodeError:
+s = bytes(s, fallback_encoding)
+else:
+# attempt to convert the thing to unicode from the system's encoding
+try:
+s = unicode(s, DEFAULT_ENCODING)
+# if the thing is already unicode, or it's a number, it can't be
+# coerced to unicode with an encoding argument, but if we leave out
+# the encoding argument, it will convert it to a string, then to 
unicode
+except TypeError:
+s = unicode(s)
+
+# now that we have guaranteed unicode, encode to our system encoding,
+# but attempt to fall back to something
+try:
+s = s.encode(DEFAULT_ENCODING)
+except:
+s = s.encode(fallback_encoding)
+return s
+
+
+class ErrorReturnCode(Exception):
+truncate_cap = 750
+
+def __init__(self, full_cmd, stdout, stderr):
+self.full_cmd = full_cmd
+self.stdout = stdout
+self.stderr = stderr
+
+
+if self.stdout is None: exc_stdout = redirected
+else:
+exc_stdout = self.stdout[:self.truncate_cap]
+out_delta = len(self.stdout) - len(exc_stdout)
+if out_delta:
+exc_stdout += (... (%d more, please see e.stdout) % 
out_delta).encode()
+
+if self.stderr is None: exc_stderr = redirected
+ 

[MediaWiki-commits] [Gerrit] Add sh.py into the repository to avoid dependency issues - change (labs...wikipedia-android-builds)

2014-10-17 Thread Yuvipanda (Code Review)
Yuvipanda has submitted this change and it was merged.

Change subject: Add sh.py into the repository to avoid dependency issues
..


Add sh.py into the repository to avoid dependency issues

Change-Id: Ieeac5a409f3a6cc71ef48c320166e9fd8ad5f87e
---
A src/sh.py
1 file changed, 1,770 insertions(+), 0 deletions(-)

Approvals:
  Yuvipanda: Verified; Looks good to me, approved



diff --git a/src/sh.py b/src/sh.py
new file mode 100644
index 000..5bf2e68
--- /dev/null
+++ b/src/sh.py
@@ -0,0 +1,1770 @@
+#===
+# Copyright (C) 2011-2012 by Andrew Moffat
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the Software), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#===
+
+
+__version__ = 1.09
+__project_url__ = https://github.com/amoffat/sh;
+
+
+
+import platform
+
+if windows in platform.system().lower():
+raise ImportError(sh %s is currently only supported on linux and osx. \
+please install pbs 0.110 (http://pypi.python.org/pypi/pbs) for windows \
+support. % __version__)
+
+
+
+import sys
+IS_PY3 = sys.version_info[0] == 3
+
+import traceback
+import os
+import re
+from glob import glob as original_glob
+from types import ModuleType
+from functools import partial
+import inspect
+import time as _time
+
+from locale import getpreferredencoding
+DEFAULT_ENCODING = getpreferredencoding() or utf-8
+
+
+if IS_PY3:
+from io import StringIO
+from io import BytesIO as cStringIO
+from queue import Queue, Empty
+else:
+from StringIO import StringIO
+from cStringIO import OutputType as cStringIO
+from Queue import Queue, Empty
+
+IS_OSX = platform.system() == Darwin
+THIS_DIR = os.path.dirname(os.path.realpath(__file__))
+
+
+import errno
+import warnings
+
+import pty
+import termios
+import signal
+import gc
+import select
+import atexit
+import threading
+import tty
+import fcntl
+import struct
+import resource
+from collections import deque
+import logging
+import weakref
+
+
+logging_enabled = False
+
+
+if IS_PY3:
+raw_input = input
+unicode = str
+basestring = str
+
+
+def encode_to_py3bytes_or_py2str(s):
+ takes anything and attempts to return a py2 string or py3 bytes.  this
+is typically used when creating command + arguments to be executed via
+os.exec* 
+
+fallback_encoding = utf8
+
+if IS_PY3:
+s = str(s)
+try:
+s = bytes(s, DEFAULT_ENCODING)
+except UnicodeEncodeError:
+s = bytes(s, fallback_encoding)
+else:
+# attempt to convert the thing to unicode from the system's encoding
+try:
+s = unicode(s, DEFAULT_ENCODING)
+# if the thing is already unicode, or it's a number, it can't be
+# coerced to unicode with an encoding argument, but if we leave out
+# the encoding argument, it will convert it to a string, then to 
unicode
+except TypeError:
+s = unicode(s)
+
+# now that we have guaranteed unicode, encode to our system encoding,
+# but attempt to fall back to something
+try:
+s = s.encode(DEFAULT_ENCODING)
+except:
+s = s.encode(fallback_encoding)
+return s
+
+
+class ErrorReturnCode(Exception):
+truncate_cap = 750
+
+def __init__(self, full_cmd, stdout, stderr):
+self.full_cmd = full_cmd
+self.stdout = stdout
+self.stderr = stderr
+
+
+if self.stdout is None: exc_stdout = redirected
+else:
+exc_stdout = self.stdout[:self.truncate_cap]
+out_delta = len(self.stdout) - len(exc_stdout)
+if out_delta:
+exc_stdout += (... (%d more, please see e.stdout) % 
out_delta).encode()
+
+if self.stderr is None: exc_stderr = redirected
+else:
+exc_stderr = self.stderr[:self.truncate_cap]
+