Updated directory and perms to use MultipleCommands.

development
Shawn Davis 2 years ago
parent f4e43e3d85
commit 3c982420ee
  1. 93
      scripttease/lib/commands/posix.py

@ -1,5 +1,5 @@
import os import os
from .base import Command, Prompt from .base import Command, MultipleCommands, Prompt
def append(path, content=None, **kwargs): def append(path, content=None, **kwargs):
@ -111,7 +111,7 @@ def directory(path, group=None, mode=None, owner=None, recursive=True, **kwargs)
- recursive (bool): Create all directories along the path. - recursive (bool): Create all directories along the path.
""" """
kwargs.setdefault("comment", "create directory %s" % path) comment = kwargs.pop("comment", "create directory %s" % path)
statement = ["mkdir"] statement = ["mkdir"]
if mode is not None: if mode is not None:
@ -122,23 +122,34 @@ def directory(path, group=None, mode=None, owner=None, recursive=True, **kwargs)
statement.append(path) statement.append(path)
mkdir = Command(" ".join(statement), comment=comment, **kwargs)
chgrp = None
if group: if group:
if recursive: if recursive:
statement.append("&& chgrp -R %s" % group) chgrp = Command("chgrp -R %s %s" % (group, path), comment="set %s group on %s" % (group, path), **kwargs)
else: else:
statement.append("&& chgrp %s" % group) chgrp = Command("chgrp %s %s" % (group, path), comment="set %s group on %s" % (group, path), **kwargs)
statement.append(path)
chown = None
if owner: if owner:
if recursive: if recursive:
statement.append("&& chown -R %s" % owner) chown = Command("chown -R %s %s" % (owner, path), comment="set %s owner on %s" % (owner, path), **kwargs)
else: else:
statement.append("&& chown %s" % owner) chown = Command("chown %s %s" % (owner, path), comment="set %s owner on %s" % (owner, path), **kwargs)
statement.append(path) commands = list()
commands.append(mkdir)
if chgrp is not None:
commands.append(chgrp)
return Command(" ".join(statement), **kwargs) if chown is not None:
commands.append(chown)
if len(commands) == 1:
return commands[0]
return MultipleCommands(commands, comment=comment)
def extract(from_path, absolute=False, exclude=None, strip=None, to_path=None, view=False, **kwargs): def extract(from_path, absolute=False, exclude=None, strip=None, to_path=None, view=False, **kwargs):
@ -224,50 +235,58 @@ def perms(path, group=None, mode=None, owner=None, recursive=False, **kwargs):
- recursive: Create all directories along the path. - recursive: Create all directories along the path.
""" """
commands = list() comment = kwargs.pop("comment", "set permissions on %s" % path)
kwargs['comment'] = "set permissions on %s" % path
chgrp = None
if group is not None: if group is not None:
statement = ["chgrp"] a = ["chgrp"]
if recursive: if recursive:
statement.append("-R") a.append("-R")
statement.append(group) a.append(group)
statement.append(path) a.append(path)
commands.append(Command(" ".join(statement), **kwargs)) chgrp = Command(" ".join(a), comment="set %s group on %s" % (group, path), **kwargs)
if owner is not None: chmod = None
statement = ["chown"] if mode is not None:
a = ["chmod"]
if recursive: if recursive:
statement.append("-R") a.append("-R")
statement.append(owner) a.append(mode)
statement.append(path) a.append(path)
commands.append(Command(" ".join(statement), **kwargs)) chmod = Command(" ".join(a), comment="set %s mode on %s" % (mode, path), **kwargs)
if mode is not None: chown = None
statement = ["chmod"] if owner is not None:
a = ["chown"]
if recursive: if recursive:
statement.append("-R") a.append("-R")
a.append(owner)
a.append(path)
statement.append(str(mode)) chown = Command(" ".join(a), comment="set %s owner on %s" % (owner, path), **kwargs)
statement.append(path)
commands.append(Command(" ".join(statement), **kwargs)) commands = list()
if chgrp is not None:
commands.append(chgrp)
kwargs.setdefault("comment", "set permissions on %s" % path) if chmod is not None:
commands.append(chmod)
a = list() if chown is not None:
for c in commands: commands.append(chown)
a.append(c.get_statement(include_comment=True))
return Command("\n".join(a), **kwargs) if len(commands) == 1:
return commands[0]
return MultipleCommands(commands, comment=comment, **kwargs)
def prompt(name, back_title="Input", choices=None, default=None, dialog=False, help_text=None, label=None, **kwargs): def prompt(name, back_title="Input", choices=None, default=None, dialog=False, help_text=None, label=None, **kwargs):
@ -394,7 +413,9 @@ def rsync(source, target, delete=False, exclude=None, host=None, key_file=None,
tokens = list() tokens = list()
tokens.append("rsync") tokens.append("rsync")
tokens.append("--cvs-exclude") # BUG: Providing rsync --cvs-exclude was causing directories named "tags" to be omitted.
# tokens.append("--cvs-exclude")
tokens.append("--exclude=.git")
tokens.append("--checksum") tokens.append("--checksum")
tokens.append("--compress") tokens.append("--compress")

Loading…
Cancel
Save