-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollectDependencies.py
69 lines (56 loc) · 2.42 KB
/
collectDependencies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import getpass
import json
import argparse
import pprint
from azureFunctionPackageDependencyCollector import AzureFunctionPackageDependencyCollector
from mavenPomDependencyCollector import MavenPomDependencyCollector
from nuGetPackageDependencyCollector import NuGetPackageDependencyCollector
from repoCloner import RepoCloner
parser = argparse.ArgumentParser()
parser.add_argument('--username')
parser.add_argument('--noclone', action='store_true')
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--outformat')
parser.add_argument('--outfile')
parser.add_argument('--host')
parser.add_argument('--repofile')
args = parser.parse_args()
noclone = args.noclone
verbose = args.verbose
outformat = 'json' if args.outformat is None else args.outformat
if args.repofile is None:
print('Missing argument: --repofile')
exit()
if args.outfile is None:
print('Missing argument: --outfile')
exit()
if not noclone:
if args.username is None:
print('Missing argument: --username')
exit()
if args.host is None:
print('Missing argument: --host')
exit()
password = ''
if not noclone:
password = getpass.getpass(prompt='Git password:')
repositories = []
with open(args.repofile, 'r') as repofile:
repositories = json.loads(repofile.read())
dependencies = []
for repo in repositories:
name = repo["name"]
print(f'Processing {name} (branch: {repo["branch"]})')
repo_path = f'tmp/{name}'
if not noclone:
RepoCloner(verbose=verbose).clone_repo(args.username, password, args.host, name, repo["branch"], repo_path)
dependencies.extend(MavenPomDependencyCollector(verbose=verbose).process_poms(name, repo_path).get_dependencies())
dependencies.extend(AzureFunctionPackageDependencyCollector(verbose=verbose).process_azure_function_packages(name, repo_path).dependencies)
dependencies.extend(NuGetPackageDependencyCollector(verbose=verbose).process_nuget_packages(name, repo_path).dependencies)
with open(args.outfile, 'w') as fileout:
if outformat == 'json':
fileout.write(json.dumps(dependencies, indent=4))
if outformat == 'csv':
fileout.write('Repository,Type,Name,Version,License\n')
for dependency in dependencies:
fileout.write(f'{dependency["repo"]},{dependency["type"]},{dependency["name"]},="{dependency["version"]}",{dependency["license"]}\n')