Skip to content

Commit a797c1f

Browse files
Finally, it's possible to keep both behaviors
1 parent d908bad commit a797c1f

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

artifacts/copy_artifacts_app.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,37 @@ def main():
2626
mandatory_arguments.add_argument("--packages-home",
2727
dest="packages_home_dir",
2828
metavar='repository directory',
29-
required=True,
29+
required=False,
3030
help='copy found artifacts here')
3131

32-
parser.add_argument("base_dirs",
32+
parser.add_argument("items",
3333
metavar='base directory to search or archive file',
3434
nargs=argparse.REMAINDER,
3535
help='base directory to search for artifacts or archive file')
3636

3737
arguments = parser.parse_args()
3838

39-
if arguments.base_dirs is None or len(arguments.base_dirs) == 0:
39+
if arguments.items is None or len(arguments.items) == 0:
4040
parser.print_usage()
41-
raise Exception("missing base directories")
42-
43-
for base_dir in arguments.base_dirs:
44-
if os.path.isfile(base_dir):
45-
artifacts.copy_package(base_dir, arguments.packages_home_dir)
46-
elif os.path.isdir(base_dir):
47-
print("-------------- searching base dir: ", base_dir, " -----------------")
48-
for archive in glob.glob(os.path.join(base_dir, "**", "*.tar.gz"), recursive=True):
49-
artifacts.copy_package(archive, arguments.packages_home_dir)
41+
raise Exception("missing item list")
42+
else:
43+
if arguments.packages_home_dir is not None:
44+
repository = arguments.packages_home_dir
45+
else:
46+
repository = arguments.items[len(arguments.items) - 1]
47+
arguments.items.pop()
48+
49+
assert os.path.isdir(repository), "{} is not a directory.".format(repository)
50+
51+
for item in arguments.items:
52+
if os.path.isfile(item):
53+
artifacts.copy_package(item, repository)
54+
elif os.path.isdir(item):
55+
print("-------------- searching base dir: ", item, " -----------------")
56+
for archive in glob.glob(os.path.join(item, "**", "*.tar.gz"), recursive=True):
57+
artifacts.copy_package(archive, repository)
58+
else:
59+
raise AssertionError("'{}' is neither a file nor a directory.".format(item))
5060

5161
except AssertionError as err:
5262
print("error: {} failed. {}".format(parser.prog, err))

tests/apps_unit_tests.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,20 @@ def test_copy_app_help(self):
5858
artifacts.copy_artifacts_app.main()
5959

6060
def test_copy_app(self):
61+
sys.argv = [
62+
"{}.copy_app_test".format(__name__),
63+
'tests/fixtures/', 'tests/fixtures/artifact-qnx-2.3.4-snapshot-x86.tar.gz','tests/fixtures/cpp-pthread-Darwin-1.11.0-x86.tar.gz',
64+
self.repository
65+
]
66+
artifacts.copy_artifacts_app.main()
67+
archives = glob.glob(os.path.join(self.repository, '*.tar.gz'))
68+
self.assertEqual(2, len(archives))
69+
70+
def test_copy_app_with_package_arg(self):
6171
sys.argv = [
6272
"{}.copy_app_test".format(__name__),
6373
'--packages-home', self.repository,
64-
'tests/fixtures/', 'tests/fixtures/artifact-qnx-2.3.4-snapshot-x86.tar.gz','tests/fixtures/cpp-pthread-Darwin-1.11.0-x86.tar.gz'
74+
'tests/fixtures/', 'tests/fixtures/artifact-qnx-2.3.4-snapshot-x86.tar.gz','tests/fixtures/cpp-pthread-Darwin-1.11.0-x86.tar.gz',
6575
]
6676
artifacts.copy_artifacts_app.main()
6777
archives = glob.glob(os.path.join(self.repository, '*.tar.gz'))

0 commit comments

Comments
 (0)