From 1a7193a02559df54a4c09a3f9f61ae09b36e9bf3 Mon Sep 17 00:00:00 2001 From: Sky Date: Thu, 2 Jul 2015 12:01:22 -0400 Subject: [PATCH] Add hot-patch for tomerfiliba/plumbum#180 --- gut/gut.py | 1 + gut/patch_plumbum.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 gut/patch_plumbum.py diff --git a/gut/gut.py b/gut/gut.py index ac2f74c..08f3fec 100755 --- a/gut/gut.py +++ b/gut/gut.py @@ -12,6 +12,7 @@ import plumbum from plumbum.commands.processes import ProcessExecutionError +import patch_plumbum; patch_plumbum.patch_darwin_stat() GIT_REPO_URL = 'https://github.com/git/git.git' GIT_VERSION = 'v2.4.5' diff --git a/gut/patch_plumbum.py b/gut/patch_plumbum.py new file mode 100644 index 0000000..cd11dbe --- /dev/null +++ b/gut/patch_plumbum.py @@ -0,0 +1,26 @@ +def patch_darwin_stat(): + import plumbum + from plumbum.commands import shquote + from plumbum.path.remote import StatRes + def _path_getuid(self, fn): + stat_cmd = "stat -c '%u,%U' " if self.uname != 'Darwin' else "stat -f '%u,%Su' " + return self._session.run(stat_cmd + shquote(fn))[1].strip().split(",") + def _path_getgid(self, fn): + stat_cmd = "stat -c '%g,%G' " if self.uname != 'Darwin' else "stat -f '%g,%Sg' " + return self._session.run(stat_cmd + shquote(fn))[1].strip().split(",") + def _path_stat(self, fn): + if self.uname != 'Darwin': + stat_cmd = "stat -c '%F,%f,%i,%d,%h,%u,%g,%s,%X,%Y,%Z' " + else: + stat_cmd = "stat -f '%HT,%Xp,%i,%d,%l,%u,%g,%z,%a,%m,%c' " + rc, out, _ = self._session.run(stat_cmd + shquote(fn), retcode = None) + if rc != 0: + return None + statres = out.strip().split(",") + text_mode = statres.pop(0).lower() + res = StatRes((int(statres[0], 16),) + tuple(int(sr) for sr in statres[1:])) + res.text_mode = text_mode + return res + plumbum.machines.remote.BaseRemoteMachine._path_getuid = _path_getuid + plumbum.machines.remote.BaseRemoteMachine._path_getgid = _path_getgid + plumbum.machines.remote.BaseRemoteMachine._path_stat = _path_stat