cli: rename _unique_path to unique_path, and deprecate the old one

This commit is contained in:
Yuming Zhu 2018-06-22 13:42:47 +08:00 committed by Mike McLean
parent 967704b9a3
commit 1c76cd0c0f
11 changed files with 46 additions and 40 deletions

View file

@ -39,7 +39,7 @@ from koji_cli.lib import _, OptionParser, activate_session, parse_arches, \
_unique_path, _running_in_bg, _progress_callback, watch_tasks, \
arg_filter, linked_upload, list_task_output_all_volumes, \
print_task_headers, print_task_recurse, download_file, watch_logs, \
error, greetings, _list_tasks
error, greetings, _list_tasks, unique_path
def _printable_unicode(s):
@ -485,7 +485,7 @@ def handle_build(options, session, args):
#treat source as an srpm and upload it
if not build_opts.quiet:
print("Uploading srpm: %s" % source)
serverdir = _unique_path('cli-build')
serverdir = unique_path('cli-build')
if _running_in_bg() or build_opts.noprogress or build_opts.quiet:
callback = None
else:
@ -1179,7 +1179,7 @@ def handle_import(goptions, session, args):
if options.test:
print(_("Test mode -- skipping import for %s") % path)
return
serverdir = _unique_path('cli-import')
serverdir = unique_path('cli-import')
if options.link:
linked_upload(path, serverdir)
else:
@ -1299,7 +1299,7 @@ def handle_import_cg(goptions, session, args):
# get upload path
# XXX - need a better way
serverdir = _unique_path('cli-import')
serverdir = unique_path('cli-import')
for localpath, info in to_upload:
relpath = os.path.join(serverdir, info.get('relpath', ''))
@ -2159,7 +2159,7 @@ def handle_import_archive(options, session, args):
for filepath in args[1:]:
filename = os.path.basename(filepath)
print("Uploading archive: %s" % filename)
serverdir = _unique_path('cli-import')
serverdir = unique_path('cli-import')
if _running_in_bg() or suboptions.noprogress:
callback = None
else:
@ -5594,7 +5594,7 @@ def _build_image_indirection(options, task_opts, session, args):
# only scratch builds can omit indirection_template_url
raise koji.GenericError(_("Non-scratch builds must provide a URL for the indirection template"))
templatefile = task_opts.indirection_template
serverdir = _unique_path('cli-image-indirection')
serverdir = unique_path('cli-image-indirection')
session.uploadWrapper(templatefile, serverdir, callback=callback)
task_opts.indirection_template = os.path.join('work', serverdir,
os.path.basename(templatefile))
@ -5791,7 +5791,7 @@ def _build_image(options, task_opts, session, args, img_type):
ksfile = args[4]
if not task_opts.ksurl:
serverdir = _unique_path('cli-' + img_type)
serverdir = unique_path('cli-' + img_type)
session.uploadWrapper(ksfile, serverdir, callback=callback)
ksfile = os.path.join(serverdir, os.path.basename(ksfile))
print('')
@ -5867,7 +5867,7 @@ def _build_image_oz(options, task_opts, session, args):
# only scratch builds can omit ksurl
raise koji.GenericError(_("Non-scratch builds must provide ksurl"))
ksfile = task_opts.kickstart
serverdir = _unique_path('cli-image')
serverdir = unique_path('cli-image')
session.uploadWrapper(ksfile, serverdir, callback=callback)
task_opts.kickstart = os.path.join('work', serverdir,
os.path.basename(ksfile))
@ -6975,7 +6975,7 @@ def handle_dist_repo(options, session, args):
parser.error(_('allow_missing_signatures and skip_missing_signatures '
'are mutually exclusive'))
activate_session(session, options)
stuffdir = _unique_path('cli-dist-repo')
stuffdir = unique_path('cli-dist-repo')
if task_opts.comps:
if not os.path.exists(task_opts.comps):
parser.error(_('could not find %s') % task_opts.comps)

View file

@ -402,7 +402,7 @@ def list_task_output_all_volumes(session, task_id):
return dict([fn, ['DEFAULT']] for fn in output)
def _unique_path(prefix):
def unique_path(prefix):
"""Create a unique path fragment by appending a path component
to prefix. The path component will consist of a string of letter and numbers
that is unlikely to be a duplicate, but is not guaranteed to be unique."""
@ -414,6 +414,12 @@ def _unique_path(prefix):
''.join([random.choice(string.ascii_letters) for i in range(8)]))
def _unique_path(prefix):
koji.util.deprecated('_unique_path is deprecated, use unique_path instead.'
' See: https://pagure.io/koji/issue/975')
return unique_path(prefix)
def _format_size(size):
if (size / 1073741824 >= 1):
return "%0.2f GiB" % (size / 1073741824.0)

View file

@ -146,7 +146,7 @@ You can create progress bars as necessary with this snippet:
callback = None
else:
callback = _progress_callback
serverdir = _unique_path('cli-image') # create a unique path on the hub
serverdir = unique_path('cli-image') # create a unique path on the hub
session.uploadWrapper(somefile, serverdir, callback=callback)
Task Arguments

View file

@ -25,7 +25,7 @@ class TestBuild(unittest.TestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_from_srpm(
@ -77,7 +77,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_from_scm(
@ -127,7 +127,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_no_arg(
@ -173,7 +173,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_help(
@ -232,7 +232,7 @@ Options:
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_arch_override_denied(
@ -280,7 +280,7 @@ Options:
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_none_tag(
@ -326,7 +326,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_target_not_found(
@ -373,7 +373,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_dest_tag_not_found(
@ -424,7 +424,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_dest_tag_locked(
@ -475,7 +475,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_arch_override(
@ -531,7 +531,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_background(
@ -580,7 +580,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=True)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_running_in_bg(
@ -631,7 +631,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_noprogress(
@ -684,7 +684,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_quiet(
@ -734,7 +734,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_wait(
@ -788,7 +788,7 @@ Task info: weburl/taskinfo?taskID=1
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands.activate_session')
@mock.patch('koji_cli.commands._unique_path', return_value='random_path')
@mock.patch('koji_cli.commands.unique_path', return_value='random_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.watch_tasks', return_value=0)
def test_handle_build_nowait(

View file

@ -53,7 +53,7 @@ class TestDistRepo(utils.CliTestCase):
self.setUpMocks()
def setUpMocks(self):
self.unique_path = mock.patch('koji_cli.commands._unique_path').start()
self.unique_path = mock.patch('koji_cli.commands.unique_path').start()
self.unique_path.return_value = '/path/to/cli-dist-repo'
self.activate_session = mock.patch('koji_cli.commands.activate_session').start()

View file

@ -113,7 +113,7 @@ class TestBuildImageOz(utils.CliTestCase):
# mocks
self.activate_session = mock.patch('koji_cli.commands.activate_session').start()
self.watch_tasks = mock.patch('koji_cli.commands.watch_tasks').start()
self.unique_path = mock.patch('koji_cli.commands._unique_path').start()
self.unique_path = mock.patch('koji_cli.commands.unique_path').start()
self.unique_path.return_value = '/path/to/cli-image'
self.running_in_bg = mock.patch('koji_cli.commands._running_in_bg').start()
self.running_in_bg.return_value = False

View file

@ -53,7 +53,7 @@ class TestBuildImageIndirection(utils.CliTestCase):
self.options.weburl = self.weburl
self.session = mock.MagicMock()
self.activate_session = mock.patch('koji_cli.commands.activate_session').start()
self.unique_path = mock.patch('koji_cli.commands._unique_path').start()
self.unique_path = mock.patch('koji_cli.commands.unique_path').start()
self.task_opts = Options(TASK_OPTIONS)

View file

@ -95,7 +95,7 @@ class TestImport(utils.CliTestCase):
upload_rpm_mock = kwargs.get('upload_rpm_mock', session.uploadWrapper)
with mock.patch('koji.get_header_fields') as get_header_fields_mock:
with mock.patch('koji_cli.commands._unique_path') as unique_path_mock:
with mock.patch('koji_cli.commands.unique_path') as unique_path_mock:
with mock.patch('koji_cli.commands.activate_session') as activate_session_mock:
with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:
with upload_rpm_mock:
@ -475,7 +475,7 @@ class TestImport(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.get_header_fields')
@mock.patch('koji_cli.commands._unique_path')
@mock.patch('koji_cli.commands.unique_path')
@mock.patch('koji_cli.commands.activate_session')
def test_handle_import_with_test_option(
self,
@ -524,7 +524,7 @@ class TestImport(utils.CliTestCase):
expected = "Test mode -- would have created empty build: %s\n" % nvr()
expected += "Test mode -- skipping import for %s\n" % arguments[0]
with mock.patch('koji_cli.commands._unique_path') as unique_path_mock:
with mock.patch('koji_cli.commands.unique_path') as unique_path_mock:
handle_import(options, session, arguments)
self.assert_console_message(stdout, expected)
unique_path_mock.assert_not_called()
@ -533,7 +533,7 @@ class TestImport(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji.get_header_fields')
@mock.patch('koji_cli.commands._unique_path')
@mock.patch('koji_cli.commands.unique_path')
@mock.patch('koji_cli.commands.activate_session')
def test_handle_import_with_epoch_option(
self,

View file

@ -31,7 +31,7 @@ class TestImportCG(utils.CliTestCase):
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('koji_cli.commands._progress_callback')
@mock.patch('koji_cli.commands._unique_path')
@mock.patch('koji_cli.commands.unique_path')
@mock.patch('koji_cli.commands._running_in_bg', return_value=False)
@mock.patch('koji_cli.commands.linked_upload')
@mock.patch('koji_cli.commands.activate_session')

View file

@ -77,7 +77,7 @@ class TestBuildImage(utils.CliTestCase):
self.session = mock.MagicMock()
self.arguments = ['test-image', '1', 'target', 'x86_64', 'image.ks']
self.activate_session = mock.patch('koji_cli.commands.activate_session').start()
self.unique_path = mock.patch('koji_cli.commands._unique_path').start()
self.unique_path = mock.patch('koji_cli.commands.unique_path').start()
self.running_in_bg = mock.patch('koji_cli.commands._running_in_bg').start()
self.watch_tasks = mock.patch('koji_cli.commands.watch_tasks').start()

View file

@ -6,17 +6,17 @@ except ImportError:
from six.moves import range
from koji_cli.lib import _unique_path
from koji_cli.lib import unique_path
class TestUniquePath(unittest.TestCase):
def test_unique_path(self):
for i in range(1000):
self.assertNotEqual(
_unique_path('prefix'),
_unique_path('prefix'))
unique_path('prefix'),
unique_path('prefix'))
self.assertRegexpMatches(
_unique_path('prefix'),
unique_path('prefix'),
'^prefix/\d{10}\.\d{1,7}\.[a-zA-Z]{8}$')
if __name__ == '__main__':