Skip to content

Commit

Permalink
Added getmod().
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Oct 25, 2018
1 parent 427f662 commit 72c3b0a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
14 changes: 14 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,20 @@ Examples::
tmp_mutt = lsf('/tmp/', select='mutt-*')


File Permissions
~~~~~~~~~~~~~~~~

Change the file permissiongs of a file, or files, or directory, or directories::

chmod(mode, path)

where *mode* is a three digit octal number.

You may read the permissions of a file or directory using::

mode = getmod(path)


Paths
-----

Expand Down
28 changes: 22 additions & 6 deletions shlib/shlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ def chmod(mode, *paths):
for path in to_paths(paths):
path.chmod(mode)

# getmod {{{2
def getmod(path):
"Return the permission bits for a file or directory"
return os.stat(str(path)).st_mode & 0o777

# ls {{{2
def ls(*paths, **kwargs):
"""
Expand Down Expand Up @@ -521,7 +526,7 @@ def run(self, stdin=None):
cmd = [str(c) for c in self.cmd]
if _use_log(self.log):
from inform import log
log('Running:', render_command(cmd, option_args=self.option_args))
log('running:', render_command(cmd, option_args=self.option_args))

# indicate streams to intercept
streams = {}
Expand All @@ -535,9 +540,20 @@ def run(self, stdin=None):
streams['stderr'] = subprocess.STDOUT

# run the command
process = subprocess.Popen(
cmd, shell=self.use_shell, env=self.env, **streams
)
try:
process = subprocess.Popen(
cmd, shell=self.use_shell, env=self.env, **streams
)
except OSError as e:
if preferences.get('use_inform'):
from inform import Error
raise Error(
msg = os_error(e),
cmd = render_command(self.cmd),
template = '{msg}'
)
else:
raise

# store needed information and wait for termination if desired
self.pid = process.pid
Expand All @@ -562,7 +578,7 @@ def start(self, stdin=None):
cmd = self.cmd
if _use_log(self.log):
from inform import log
log('Running:', render_command(cmd, option_args=self.option_args))
log('running:', render_command(cmd, option_args=self.option_args))

if self.save_stdout or self.save_stderr:
try:
Expand Down Expand Up @@ -612,7 +628,7 @@ def wait(self):

if _use_log(self.log):
from inform import log
log('Exit status:', self.status)
log('exit status:', self.status)

# check return code
if self.accept.unacceptable(self.status):
Expand Down

0 comments on commit 72c3b0a

Please sign in to comment.