Skip to content

Commit a1c0500

Browse files
Expose all .whl, and other files and Create an archive for each OS/python 3
It will upload all .whl,.ABOUT, .NOTICE,.LICENCE files of thirdparty repo to github new repo as an asset of specific OS and python and also generate archive for each Oses and all python and release them an asset on github. Signed-off-by: Abhishek Kumar <abhishek.kasyap09@gmail.com>
1 parent 3068680 commit a1c0500

2 files changed

Lines changed: 244 additions & 0 deletions

File tree

deps_archive.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (c) nexB Inc. and others. All rights reserved.
4+
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
5+
# The ScanCode software is licensed under the Apache License version 2.0.
6+
# Data generated with ScanCode require an acknowledgment.
7+
# ScanCode is a trademark of nexB Inc.
8+
#
9+
# You may not use this software except in compliance with the License.
10+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
11+
# Unless required by applicable law or agreed to in writing, software distributed
12+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
# specific language governing permissions and limitations under the License.
15+
#
16+
# When you publish or redistribute any data created with ScanCode or any ScanCode
17+
# derivative work, you must accompany this data with the following acknowledgment:
18+
#
19+
# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
20+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
21+
# ScanCode should be considered or used as legal advice. Consult an Attorney
22+
# for any legal advice.
23+
# ScanCode is a free software code scanning tool from nexB Inc. and others.
24+
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.
25+
26+
from __future__ import absolute_import
27+
from __future__ import print_function
28+
29+
import argparse
30+
from commoncode.system import on_windows
31+
import os
32+
from shutil import make_archive
33+
import sys
34+
35+
36+
def generate_OS_archive(input_dir, output):
37+
"""
38+
Generate an archive for dependencies for specific OS and
39+
given version of python by taking directory as an input.
40+
"""
41+
42+
root_dir = os.path.expanduser(os.path.join("~", input_dir))
43+
output_dir = os.path.expanduser(os.path.join("~", output))
44+
if on_windows:
45+
make_archive(output_dir, "zip", root_dir)
46+
else:
47+
make_archive(output_dir, "gztar", root_dir)
48+
49+
50+
def main_with_args(args: str) -> None:
51+
parser = argparse.ArgumentParser(
52+
description="""Creates a archive for specific OS and specific python.
53+
EXAMPLE:
54+
generate_OS_archive.py \\
55+
--input scancode-toolkit/thirdparty \\
56+
--output Desktop/macOS_py36 \\
57+
""",
58+
formatter_class=argparse.RawDescriptionHelpFormatter,
59+
)
60+
61+
parser.add_argument(
62+
"--input",
63+
help="Required: Thirdparty Dependencies directory to be archived. ",
64+
type=str,
65+
required=True,
66+
)
67+
68+
parser.add_argument(
69+
"--output",
70+
help="Required: The Generated archive file name without extension. ",
71+
type=str,
72+
required=True,
73+
)
74+
75+
args = parser.parse_args()
76+
77+
input_dir = args.input
78+
output = args.output
79+
generate_OS_archive(input_dir, output)
80+
81+
82+
def main() -> None:
83+
main_with_args(sys.argv[1:])
84+
85+
86+
if __name__ == "__main__":
87+
main()

github_release.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (c) nexB Inc. and others. All rights reserved.
4+
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
5+
# The ScanCode software is licensed under the Apache License version 2.0.
6+
# Data generated with ScanCode require an acknowledgment.
7+
# ScanCode is a trademark of nexB Inc.
8+
#
9+
# You may not use this software except in compliance with the License.
10+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
11+
# Unless required by applicable law or agreed to in writing, software distributed
12+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
# specific language governing permissions and limitations under the License.
15+
#
16+
# When you publish or redistribute any data created with ScanCode or any ScanCode
17+
# derivative work, you must accompany this data with the following acknowledgment:
18+
#
19+
# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
20+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
21+
# ScanCode should be considered or used as legal advice. Consult an Attorney
22+
# for any legal advice.
23+
# ScanCode is a free software code scanning tool from nexB Inc. and others.
24+
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.
25+
26+
from __future__ import absolute_import
27+
from __future__ import print_function
28+
29+
import argparse
30+
from commoncode.fileutils import resource_iter
31+
import fnmatch
32+
import os
33+
import subprocess
34+
import sys
35+
36+
37+
def release_asset(token, tag, repo, body, user, limit, file):
38+
"""
39+
Release .whl,.ABOUT,.NOTICE,.LICENSE to github repository from
40+
given directory.
41+
"""
42+
43+
cwd = os.getcwd()
44+
os.environ["GITHUB_TOKEN"] = token
45+
thirdparty = list(resource_iter(file, with_dirs=False))
46+
# FIXME this code is for py 3.6 and later we will update for all version
47+
dependencies = [
48+
files
49+
for files in thirdparty
50+
if fnmatch.fnmatchcase(files, "*py3*")
51+
or fnmatch.fnmatchcase(files, "*cp36*")
52+
or (
53+
fnmatch.fnmatchcase(files, "*tar.gz*")
54+
and not fnmatch.fnmatchcase(files, "*py2-ipaddress-3.4.1.tar.gz*")
55+
)
56+
]
57+
for deps in dependencies:
58+
print(deps)
59+
subprocess.run(
60+
[
61+
"python3",
62+
"-m",
63+
"github_release_retry.github_release_retry",
64+
"--user",
65+
user,
66+
"--repo",
67+
repo,
68+
"--tag_name",
69+
tag,
70+
"--body_string",
71+
body,
72+
"--retry_limit",
73+
limit,
74+
deps,
75+
]
76+
)
77+
78+
79+
def main_with_args(args: str) -> None:
80+
parser = argparse.ArgumentParser(
81+
description="""Creates a GitHub release (if it does not already exist) and uploads files to the release.
82+
Please pass the GITHUB_TOKEN as an argument.
83+
EXAMPLE:
84+
github-release-asset \\
85+
--user Abhishek-Dev09 \\
86+
--repo thirdparty \\
87+
--tag_name v1.0 \\
88+
--body_string "Python 3.6 wheels" \\
89+
hello-world.zip RELEASE_NOTES.txt
90+
""",
91+
formatter_class=argparse.RawDescriptionHelpFormatter,
92+
)
93+
94+
parser.add_argument(
95+
"--user",
96+
help="Required: The GitHub username or organization name in which the repo resides. ",
97+
type=str,
98+
required=True,
99+
)
100+
101+
parser.add_argument(
102+
"--token",
103+
help="Required: The Github token is required to acess the repository where you want to upload . ",
104+
type=str,
105+
required=True,
106+
)
107+
108+
parser.add_argument(
109+
"--repo",
110+
help="Required: The GitHub repo name in which to make the release. ",
111+
type=str,
112+
required=True,
113+
)
114+
115+
parser.add_argument(
116+
"--tag_name",
117+
help="Required: The name of the tag to create or use. ",
118+
type=str,
119+
required=True,
120+
)
121+
122+
parser.add_argument(
123+
"--body_string",
124+
help="Required (or use --body_file): Text describing the release. Ignored if the release already exists.",
125+
type=str,
126+
)
127+
128+
parser.add_argument(
129+
"--retry_limit",
130+
help="The number of times to retry creating/getting the release and/or uploading each file. ",
131+
type=str,
132+
default="10",
133+
)
134+
135+
parser.add_argument(
136+
"--files", type=str, help="The files to upload to the release.",
137+
)
138+
139+
args = parser.parse_args()
140+
141+
token = args.token
142+
tag = args.tag_name
143+
repo = args.repo
144+
body = args.body_string
145+
user = args.user
146+
limit = args.retry_limit
147+
file = args.files
148+
149+
release_asset(token, tag, repo, body, user, limit, file)
150+
151+
152+
def main() -> None:
153+
main_with_args(sys.argv[1:])
154+
155+
156+
if __name__ == "__main__":
157+
main()

0 commit comments

Comments
 (0)