-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hot-patch for tomerfiliba/plumbum#180
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |