本文整理汇总了Python中zest.releaser.utils.ask函数的典型用法代码示例。如果您正苦于以下问题:Python ask函数的具体用法?Python ask怎么用?Python ask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ask函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_core
def update_core(data, branch=None):
msg = "Ok to update coredev versions.cfg/checkouts.cfg?"
if branch:
msg = "Ok to update coredev {0} versions.cfg/checkouts.cfg?".format(branch)
if ask(msg, default=True):
root_path = os.path.join(os.getcwd(), '../../')
g = git.Git(root_path)
g.pull() # make sure buildout.coredev is up-to-date
package_name = data['name']
new_version = data['version']
update_versions(package_name, new_version)
if package_name not in ALWAYS_CHECKED_OUT_PACKAGES:
remove_from_checkouts(package_name)
# git commit
message = "{0} {1}".format(package_name, new_version)
g.add('versions.cfg')
g.add('checkouts.cfg')
print("Committing changes.")
g.commit(message=message)
msg = "Ok to push coredev?"
if branch:
msg = "Ok to push coredev {0}?".format(branch)
if ask(msg, default=True):
print("Pushing changes to server.")
g.push()
示例2: ask_what_to_release
def ask_what_to_release(self):
"""Show changes both in CHANGES.rst and on git history
For that checkout the repository, show both changes to see if
everything worth writing in CHANGES.rst from git history is already
there.
"""
logger.info('')
msg = 'What to release'
logger.info(msg)
logger.info('-' * len(msg))
to_release = []
for distribution_path in self.distributions:
dist_name = distribution_path.split('/')[-1]
repo = Repo(distribution_path)
git_changes = get_compact_git_history(
repo,
self.last_tags[dist_name],
self.branch,
)
cleaned_git_changes = filter_git_history(git_changes)
# a git history without any meaningful commit should not be
# released
if cleaned_git_changes == '':
continue
logger.info(DISTRIBUTION.format(distribution_path))
change_log_path = '{0}/CHANGES.rst'.format(repo.working_tree_dir)
try:
changes = self._grab_changelog(change_log_path)
except IOError:
logger.debug('Changelog not found, skipping.')
continue
self.changelogs[dist_name] = changes[2:]
# nice to have: show them side-by-side
logger.info('')
logger.info(cleaned_git_changes)
logger.info('')
logger.info('')
logger.info(''.join(changes))
msg = '{0}: write the above git history on CHANGES.rst?'
if self.test and ask(msg.format(dist_name)):
changelog = UpdateDistChangelog(
distribution_path,
branch=self.branch,
)
changelog.write_changes(history=cleaned_git_changes)
elif not self.test and \
ask('Is the change log ready for release?'):
to_release.append(distribution_path)
if not self.test:
self.distributions = to_release
logger.debug('Distributions: ')
logger.debug('\n'.join(self.distributions))
示例3: zest_releaser_check
def zest_releaser_check(data):
"""Check the completeness of MANIFEST.in before the release.
This is an entry point for zest.releaser. See the documentation at
http://zestreleaser.readthedocs.org/en/latest/entrypoints.html
"""
from zest.releaser.utils import ask
source_tree = data['workingdir']
if not is_package(source_tree):
# You can use zest.releaser on things that are not Python packages.
# It's pointless to run check-manifest in those circumstances.
# See https://github.com/mgedmin/check-manifest/issues/9 for details.
return
if not ask("Do you want to run check-manifest?"):
return
try:
if not check_manifest(source_tree):
if not ask("MANIFEST.in is not in order. "
" Do you want to continue despite that?", default=False):
sys.exit(1)
except Failure as e:
error(str(e))
if not ask("Something bad happened. "
" Do you want to continue despite that?", default=False):
sys.exit(2)
示例4: _upload_distributions
def _upload_distributions(self, package, sdist_options, pypiconfig):
# See if creating an egg actually works.
logger.info("Making an egg of a fresh tag checkout.")
print system(utils.setup_py('sdist ' + sdist_options))
# First ask if we want to upload to pypi, which should always
# work, also without collective.dist.
use_pypi = package_in_pypi(package)
if use_pypi:
logger.info("This package is registered on PyPI.")
else:
logger.warn("This package is NOT registered on PyPI.")
if pypiconfig.is_old_pypi_config():
pypi_command = 'register sdist %s upload' % sdist_options
shell_command = utils.setup_py(pypi_command)
if use_pypi:
default = True
exact = False
else:
# We are not yet on pypi. To avoid an 'Oops...,
# sorry!' when registering and uploading an internal
# package we default to False here.
default = False
exact = True
if utils.ask("Register and upload to PyPI", default=default,
exact=exact):
logger.info("Running: %s", shell_command)
result = system(shell_command)
utils.show_first_and_last_lines(result)
# If collective.dist is installed (or we are using
# python2.6 or higher), the user may have defined
# other servers to upload to.
for server in pypiconfig.distutils_servers():
if pypi.new_distutils_available():
commands = ('register', '-r', server, 'sdist',
sdist_options, 'upload', '-r', server)
else:
## This would be logical, given the lines above:
#commands = ('mregister', '-r', server, 'sdist',
# sdist_options, 'mupload', '-r', server)
## But according to the collective.dist documentation
## it should be this (with just one '-r'):
commands = ('mregister', 'sdist',
sdist_options, 'mupload', '-r', server)
shell_command = utils.setup_py(' '.join(commands))
default = True
exact = False
if server == 'pypi' and not use_pypi:
# We are not yet on pypi. To avoid an 'Oops...,
# sorry!' when registering and uploading an internal
# package we default to False here.
default = False
exact = True
if utils.ask("Register and upload to %s" % server,
default=default, exact=exact):
logger.info("Running: %s", shell_command)
result = system(shell_command)
utils.show_first_and_last_lines(result)
示例5: _upload_distributions
def _upload_distributions(self, package):
# See if creating an sdist (and maybe a wheel) actually works.
# Also, this makes the sdist (and wheel) available for plugins.
# And for twine, who will just upload the created files.
logger.info(
"Making a source distribution of a fresh tag checkout (in %s).",
self.data['tagworkingdir'])
result = utils.execute_command(utils.setup_py('sdist'))
utils.show_interesting_lines(result)
if self.pypiconfig.create_wheel():
logger.info("Making a wheel of a fresh tag checkout (in %s).",
self.data['tagworkingdir'])
result = utils.execute_command(utils.setup_py('bdist_wheel'))
utils.show_interesting_lines(result)
if not self.pypiconfig.is_pypi_configured():
logger.error(
"You must have a properly configured %s file in "
"your home dir to upload to a Python package index.",
pypi.DIST_CONFIG_FILE)
if utils.ask("Do you want to continue without uploading?",
default=False):
return
sys.exit(1)
# Run extra entry point
self._run_hooks('before_upload')
# Get list of all files to upload.
files_in_dist = sorted([
os.path.join('dist', filename) for filename in os.listdir('dist')]
)
# Get servers/repositories.
servers = self.pypiconfig.distutils_servers()
register = self.pypiconfig.register_package()
for server in servers:
default = True
exact = False
if server == 'pypi' and not package_in_pypi(package):
logger.info("This package does NOT exist yet on PyPI.")
# We are not yet on pypi. To avoid an 'Oops...,
# sorry!' when registering and uploading an internal
# package we default to False here.
default = False
exact = True
question = "Upload"
if register:
question = "Register and upload"
if utils.ask("%s to %s" % (question, server),
default=default, exact=exact):
if register:
logger.info("Registering...")
# We only need the first file, it has all the needed info
self._retry_twine('register', server, files_in_dist[:1])
self._retry_twine('upload', server, files_in_dist)
示例6: zester
def zester(data):
main_files = os.listdir(data['workingdir'])
if 'setup.py' not in main_files and 'setup.cfg' not in main_files:
return
from zest.releaser.utils import ask
if ask("Run pyroma on the package before tagging?"):
rating = run('directory', os.path.abspath(data['workingdir']))
if rating < 8:
if not ask("Continue?"):
sys.exit(1)
示例7: run_pyroma
def run_pyroma(data):
import sys
from zest.releaser.utils import ask
if not ask("Run pyroma on the package before uploading?"):
return
try:
from pyroma import run
result = run(data['tagdir'])
if result != 10:
if not ask("Continue?"):
sys.exit(1)
except ImportError:
if not ask("pyroma not available. Continue?"):
sys.exit(1)
示例8: change_log
def change_log():
utils.parse_options()
utils.configure_logging()
logger.info('Starting changelogrelease.')
if not utils.ask("OK to update ChangeLog"):
return
if not BUILDOUT:
logger.warn("No BUILDOUT environment variable")
return
vcs = baserelease.Basereleaser().vcs
package = vcs.name
buildoutpackage = os.path.split(os.path.abspath(BUILDOUT))[1]
if package == buildoutpackage:
logger.warn("It's the buildout")
return
# Current buildout
history_lines, history_encoding = getHistoryLines(vcs)
headings = extractHeadings(history_lines)
if not headings:
return
changelogs, version = getCurrentChangeLogs(history_lines, headings)
# Master Buildout
history_lines, history_encoding = getBuildoutHistoryLines()
headings = extractHeadings(history_lines)
if not headings:
return
updateBuildoutChangeLogs(history_lines, history_encoding, headings, changelogs, package, version)
upgradeBuildoutVersion(package, version)
示例9: main
def main():
logging.basicConfig(level=utils.loglevel(),
format="%(levelname)s: %(message)s")
check_for_files()
directories = development_eggs()
if not directories:
sys.exit()
old_situation = url_list()
tags = determine_tags(directories)
remove_old_part()
add_new_part(tags)
new_situation = url_list()
diff = list(difflib.ndiff(old_situation, new_situation))
logger.debug("Diff: %s", diff)
check_stable()
# XXX The diff is too ugly to put in the history file or the
# commit message.
msg = ["Stabilized buildout to most recent svn tags of our packages:"]
msg += diff
insert_msg_into_history(msg)
msg = '\n'.join(msg)
# show diff, offer commit
vcs = zest.releaser.choose.version_control()
diff_cmd = vcs.cmd_diff()
diff = getoutput(diff_cmd)
logger.info("The '%s':\n\n%s\n" % (diff_cmd, diff))
if utils.ask("OK to commit this"):
commit_cmd = vcs.cmd_commit(msg)
commit = getoutput(commit_cmd)
logger.info(commit)
示例10: _grab_history
def _grab_history(self):
"""Calculate the needed history/changelog changes
Every history heading looks like '1.0 b4 (1972-12-25)'. Extract them,
check if the first one matches the version and whether it has a the
current date.
"""
default_location = None
config = self.setup_cfg.config
if config and config.has_option('zest.releaser', 'history_file'):
default_location = config.get('zest.releaser', 'history_file')
history_file = self.vcs.history_file(location=default_location)
if not history_file:
logger.warn("No history file found")
self.data['history_lines'] = None
self.data['history_file'] = None
self.data['history_encoding'] = None
return
logger.debug("Checking %s", history_file)
history_lines, history_encoding = read_text_file(history_file)
history_lines = history_lines.split('\n')
headings = utils.extract_headings_from_history(history_lines)
if not len(headings):
logger.error("No detectable version heading in the history "
"file %s", history_file)
sys.exit(1)
good_heading = self.data['history_header'] % self.data
# ^^^ history_header is a string with %(abc)s replacements.
line = headings[0]['line']
previous = history_lines[line]
history_lines[line] = good_heading
logger.debug("Set heading from %r to %r.", previous, good_heading)
history_lines[line + 1] = utils.fix_rst_heading(
heading=good_heading,
below=history_lines[line + 1])
logger.debug("Set line below heading to %r",
history_lines[line + 1])
self.data['history_lines'] = history_lines
self.data['history_file'] = history_file
self.data['history_encoding'] = history_encoding
# TODO: add line number where an extra changelog entry can be
# inserted.
# Look for 'Nothing changed yet' under the latest header. Not
# nice if this text ends up in the changelog. Did nothing happen?
start = headings[0]['line']
if len(headings) > 1:
end = headings[1]['line']
else:
end = -1
for line in history_lines[start:end]:
if self.data['nothing_changed_yet'] in line:
if not utils.ask(
"WARNING: Changelog contains %r. Are you sure you "
"want to release?" % self.data['nothing_changed_yet'],
default=False):
logger.info("You can use the 'lasttaglog' command to "
"see the commits since the last tag.")
sys.exit(0)
break
示例11: show_changelog_entries
def show_changelog_entries(data):
# Find changelog
# TODO: Figure out how to catch malformed rst
if data['history_file'] is not None:
changelog = Changelog(file_location=data['history_file'])
# Get top release's entry
entries = changelog.latest()
if entries is None:
if not ask("Unable to parse changelog. Continue?", default=True):
sys.exit()
return
print "Changelog entries for version %s." % data['new_version']
for entry in entries:
print entry
if not ask("Continue?", default=True):
sys.exit()
示例12: compile_in_tag
def compile_in_tag(data):
"""Compile all po files in the tag.
We expect to get a dictionary from zest.releaser, with a tagdir.
When an exception occurs during finding/compiling, and we were
indeed called as an entry point of zest.releaser, we ask the user
what to do: continue with the release or not.
"""
tagdir = data.get('tagdir')
if not tagdir:
logger.warn("Aborted compiling of po files: no tagdir found in data.")
return
logger.info('Finding and compiling po files in %s', tagdir)
try:
find_lc_messages(tagdir)
except Exception:
logger.warn('Finding and compiling aborted after exception.',
exc_info=True)
if data and ask:
# We were called as an entry point of zest.releaser.
if not ask("Error compiling po file. This could mean some "
"languages have no working translations. Do you want "
"to continue with the release?"):
sys.exit(1)
示例13: available_tags
def available_tags(self):
base = self._base_from_svn()
tags_name = self._tags_name
if tags_name is None:
# Suggest to create a tags dir with the default plural /tags name.
print("tags dir does not exist at %s" % base + 'tags')
if utils.ask("Shall I create it"):
cmd = 'svn mkdir %stags -m "Creating tags directory."' % (base)
logger.info("Running %r", cmd)
print(execute_command(cmd))
tags_name = self._tags_name
assert tags_name == 'tags'
else:
sys.exit(0)
tag_info = execute_command('svn list %s%s' % (base, tags_name))
network_errors = [
'Could not resolve hostname',
'E670008',
'Repository moved',
'Unable to connect',
]
found_errors = [1 for network_error in network_errors
if network_error in tag_info]
if found_errors:
logger.error('Network problem: %s', tag_info)
sys.exit(1)
tags = [line.replace('/', '').strip()
for line in tag_info.split('\n')]
tags = [tag for tag in tags if tag] # filter empty ones
logger.debug("Available tags: %r", tags)
return tags
示例14: available_tags
def available_tags(self):
base = self._base_from_svn()
tags_name = self._tags_name
if tags_name is None:
# Suggest to create a tags dir with the default plural /tags name.
print "tags dir does not exist at %s" % base + 'tags'
if utils.ask("Shall I create it"):
cmd = 'svn mkdir %stags -m "Creating tags directory."' % (base)
logger.info("Running %r", cmd)
print system(cmd)
tags_name = self._tags_name
assert tags_name == 'tags'
else:
sys.exit(0)
tag_info = system('svn list %s%s' % (base, tags_name))
if 'Could not resolve hostname' in tag_info or \
'Repository moved' in tag_info:
logger.error('Network problem: %s', tag_info)
sys.exit()
tags = [line.replace('/', '').strip()
for line in tag_info.split('\n')]
tags = [tag for tag in tags if tag] # filter empty ones
logger.debug("Available tags: %r", tags)
return tags
示例15: _run_pyroma
def _run_pyroma(data): # pragma: no cover
"""Run pyroma (used to perform checks before releasing a new version).
"""
import sys
from zest.releaser.utils import ask
if not ask("Run pyroma on the package before uploading?"):
return
try:
from pyroma import run
result = run(data['tagdir'])
if result != 10:
if not ask("Continue?"):
sys.exit(1)
except ImportError:
if not ask("pyroma not available. Continue?"):
sys.exit(1)