~ubuntu-branches/ubuntu/vivid/git-cola/vivid

« back to all changes in this revision

Viewing changes to cola/core.py

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2014-02-14 13:13:33 UTC
  • mfrom: (1.3.22)
  • Revision ID: package-import@ubuntu.com-20140214131333-xbklb7yd9jntikpm
Tags: 1.9.4-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
def decode(enc, encoding=None):
26
26
    """decode(encoded_string) returns an unencoded unicode string
27
27
    """
28
 
    if type(enc) is unicode:
 
28
    if enc is None or type(enc) is unicode:
29
29
        return enc
30
30
 
31
31
    if encoding is None:
111
111
    return proc.communicate()
112
112
 
113
113
 
114
 
def run_command(cmd, *args, **kwargs):
 
114
def run_command(cmd, encoding=None, *args, **kwargs):
115
115
    """Run the given command to completion, and return its results.
116
116
 
117
117
    This provides a simpler interface to the subprocess module.
121
121
    """
122
122
    process = start_command(cmd, *args, **kwargs)
123
123
    (output, errors) = communicate(process)
124
 
    output = decode(output)
125
 
    errors = decode(errors)
 
124
    output = decode(output, encoding=encoding)
 
125
    errors = decode(errors, encoding=encoding)
126
126
    exit_code = process.returncode
127
127
    return (exit_code, output, errors)
128
128
 
129
129
 
130
130
@interruptable
131
 
def _fork_posix(args):
 
131
def _fork_posix(args, cwd=None):
132
132
    """Launch a process in the background."""
133
133
    encoded_args = [encode(arg) for arg in args]
134
 
    return subprocess.Popen(encoded_args).pid
135
 
 
136
 
 
137
 
def _fork_win32(args):
 
134
    return subprocess.Popen(encoded_args, cwd=cwd).pid
 
135
 
 
136
 
 
137
def _fork_win32(args, cwd=None):
138
138
    """Launch a background process using crazy win32 voodoo."""
139
139
    # This is probably wrong, but it works.  Windows.. wow.
140
140
    if args[0] == 'git-dag':
141
141
        # win32 can't exec python scripts
142
142
        args = [sys.executable] + args
143
143
 
144
 
    enc_args = [encode(arg) for arg in args]
145
 
    abspath = _win32_abspath(enc_args[0])
 
144
    argv = [encode(arg) for arg in args]
 
145
    abspath = _win32_abspath(argv[0])
146
146
    if abspath:
147
147
        # e.g. fork(['git', 'difftool', '--no-prompt', '--', 'path'])
148
 
        enc_args[0] = abspath
 
148
        argv[0] = abspath
149
149
    else:
150
150
        # e.g. fork(['gitk', '--all'])
151
 
        cmdstr = subprocess.list2cmdline(enc_args)
 
151
        cmdstr = subprocess.list2cmdline(argv)
152
152
        sh_exe = _win32_abspath('sh')
153
 
        enc_args = [sh_exe, '-c', cmdstr]
 
153
        argv = [sh_exe, '-c', cmdstr]
154
154
 
155
155
    DETACHED_PROCESS = 0x00000008 # Amazing!
156
 
    return subprocess.Popen(enc_args, creationflags=DETACHED_PROCESS).pid
 
156
    return subprocess.Popen(argv, cwd=cwd, creationflags=DETACHED_PROCESS).pid
157
157
 
158
158
 
159
159
def _win32_abspath(exe):
216
216
 
217
217
 
218
218
abspath = wrap(encode, os.path.abspath, decorator=decode)
 
219
chdir = wrap(encode, os.chdir)
219
220
exists = wrap(encode, os.path.exists)
220
221
expanduser = wrap(encode, os.path.expanduser, decorator=decode)
221
222
getcwd = decorate(decode, os.getcwd)
230
231
realpath = wrap(encode, os.path.realpath, decorator=decode)
231
232
stat = wrap(encode, os.stat)
232
233
unlink = wrap(encode, os.unlink)
 
234
walk = wrap(encode, os.walk)