Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def entries(self):
"""A list of :class:`PasswordEntry` objects."""
timer = Timer()
passwords = []
logger.info("Scanning %s ..", format_path(self.directory))
listing = self.context.capture("find", "-type", "f", "-name", "*.gpg", "-print0")
for filename in split(listing, "\0"):
basename, extension = os.path.splitext(filename)
if extension == ".gpg":
# We use os.path.normpath() to remove the leading `./' prefixes
# that `find' adds because it searches the working directory.
passwords.append(PasswordEntry(name=os.path.normpath(basename), store=self))
logger.verbose("Found %s in %s.", pluralize(len(passwords), "password"), timer)
return natsort(passwords, key=lambda e: e.name)
def create_branch(self, branch_name):
"""
Create a new branch based on the working tree's revision.
:param branch_name: The name of the branch to create (a string).
This method automatically checks out the new branch, but note that the
new branch may not actually exist until a commit has been made on the
branch.
"""
# Make sure the local repository exists and supports a working tree.
self.create()
self.ensure_working_tree()
# Create the new branch in the local repository.
logger.info("Creating branch '%s' in %s ..", branch_name, format_path(self.local))
self.context.execute(*self.get_create_branch_command(branch_name))
def generate_screenshots():
"""Generate screenshots from shell scripts."""
this_script = os.path.abspath(__file__)
this_directory = os.path.dirname(this_script)
repository = os.path.join(this_directory, os.pardir)
examples_directory = os.path.join(repository, 'docs', 'examples')
images_directory = os.path.join(repository, 'docs', 'images')
for shell_script in sorted(glob.glob(os.path.join(examples_directory, '*.sh'))):
basename, extension = os.path.splitext(os.path.basename(shell_script))
image_file = os.path.join(images_directory, '%s.png' % basename)
logger.info("Generating %s by running %s ..",
format_path(image_file),
format_path(shell_script))
command_line = [sys.executable, __file__, shell_script]
random_title = random_string(25)
# Generate the urxvt command line.
urxvt_command = [
'urxvt',
# Enforce a default geometry.
'-geometry', '98x30',
# Set the text and background color.
'-fg', TEXT_COLOR,
'-bg', BACKGROUND_COLOR,
# Set the font name and pixel size.
'-fn', 'xft:%s:pixelsize=%i' % (FONT_NAME, FONT_SIZE),
# Set the window title.
'-title', random_title,
# Hide scrollbars.
'+sb',
def delete_branch(self, branch_name, message=None, author=None):
"""
Delete or close a branch in the local repository.
:param branch_name: The name of the branch to delete or close (a string).
:param message: The message to use when closing the branch requires a
commit (a string or :data:`None`, defaults to the
string "Closing branch NAME").
:param author: Override :attr:`author` (refer to
:func:`coerce_author()` for details
on argument handling).
"""
# Make sure the local repository exists.
self.create()
# Delete the branch in the local repository.
logger.info("Deleting branch '%s' in %s ..", branch_name, format_path(self.local))
self.context.execute(*self.get_delete_branch_command(
author=(coerce_author(author) if author else self.author),
message=(message or ("Closing branch %s" % branch_name)),
branch_name=branch_name,
))
def ensure_clean(self):
"""
Make sure the working tree is clean (contains no changes to tracked files).
:raises: :exc:`~vcs_repo_mgr.exceptions.WorkingTreeNotCleanError`
when the working tree contains changes to tracked files.
"""
if not self.is_clean:
raise WorkingTreeNotCleanError(compact("""
The repository's local working tree ({local})
contains changes to tracked files!
""", local=format_path(self.local)))
def load_config(description, filename):
"""
Load a py2deb configuration file.
param filename: Filename of configuration file (a string).
"""
if os.path.isfile(filename):
logger.debug("Loading %s configuration file: %s", description, format_path(filename))
config.read(filename)
def ensure_working_tree(self):
"""
Make sure the local repository has working tree support.
:raises: :exc:`~vcs_repo_mgr.exceptions.MissingWorkingTreeError` when
the local repository doesn't support a working tree.
"""
if not self.supports_working_tree:
raise MissingWorkingTreeError(compact("""
A working tree is required but the local {friendly_name}
repository at {directory} doesn't support a working tree!
""", friendly_name=self.friendly_name, directory=format_path(self.local)))
- :exc:`~vcs_repo_mgr.exceptions.MergeConflictError` if the
merge command reports an error and merge conflicts are
detected that can't be (or haven't been) resolved
interactively.
- :exc:`~executor.ExternalCommandFailed` if the merge command
reports an error but no merge conflicts are detected.
Refer to the documentation of :attr:`merge_conflict_handler` if you
want to customize the handling of merge conflicts.
"""
# Make sure the local repository exists and supports a working tree.
self.create()
self.ensure_working_tree()
# Merge the specified revision into the current branch.
revision = revision or self.default_revision
logger.info("Merging revision '%s' in %s ..", revision, format_path(self.local))
try:
self.context.execute(*self.get_merge_command(revision))
except ExternalCommandFailed as e:
# Check for merge conflicts.
conflicts = self.merge_conflicts
if conflicts:
# Always warn about merge conflicts and log the relevant filenames.
explanation = format("Merge failed due to conflicts in %s! (%s)",
pluralize(len(conflicts), "file"),
concatenate(sorted(conflicts)))
logger.warning("%s", explanation)
if self.merge_conflict_handler(e):
# Trust the operator (or caller) and swallow the exception.
return
else:
# Raise a specific exception for merge conflicts.
.. warning:: Depending on the version control backend the push command
may fail when there are no changes to push. No attempt has
been made to make this behavior consistent between
implementations (although the thought has crossed my
mind and I'll likely revisit this in the future).
"""
# Make sure the local repository exists.
self.ensure_exists()
# Make sure there is a remote repository to push to.
if not (remote or self.remote or self.default_push_remote):
logger.info("Skipping push (no default remote is configured).")
# Push the changes to the remote repository.
timer = Timer()
logger.info("Pushing changes from %s to %s ..",
format_path(self.local),
remote or self.remote or "default remote")
self.context.execute(*self.get_push_command(remote, revision))
logger.debug("Took %s to push changes to remote repository.", timer)
def create_tag(self, tag_name):
"""
Create a new tag based on the working tree's revision.
:param tag_name: The name of the tag to create (a string).
"""
# Make sure the local repository exists and supports a working tree.
self.create()
self.ensure_working_tree()
# Create the new tag in the local repository.
logger.info("Creating tag '%s' in %s ..", tag_name, format_path(self.local))
self.context.execute(*self.get_create_tag_command(tag_name))