Skip to content

Commit d20fede

Browse files
Expose epre-built wheels, tarballs and ABOUT files as releases #295
This script copies all thirdparty files(required) and place it in repo as release assets. Signed-off-by: Abhishek Kumar <abhishek.kasyap09@gmail.com>
1 parent 4d44bd3 commit d20fede

2 files changed

Lines changed: 76 additions & 23 deletions

File tree

etc/scripts/freeze_and_update_reqs.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,13 @@
3636
import subprocess
3737

3838

39-
os.chdir(os.pardir) #go to etc
40-
os.chdir(os.pardir) # go to scancode-toolkit
41-
cwd = os.getcwd()
42-
print("Current working directory:", cwd)
43-
fp = open("requirements.txt", "wb")
44-
fp.close()
45-
46-
4739
def is_package_exist_with_hashes(package_name,hash_of_file):
4840
""" Check if any line in the file contains package with same hashes """
4941
# Open the file in read only mode
50-
line_with_hash = package_name + " \\" + "\n" + " --hash=sha256:"+ hash_of_file
51-
with open("requirements.txt", 'r') as read_obj:
42+
line_with_hash = "{} \\\n --hash=sha256:{}".format(package_name,hash_of_file)
43+
with open('requirements.txt') as file:
5244
# Read all lines in the file one by one
53-
for line in read_obj:
45+
for line in file:
5446
# For each line, check if line contains the package with same hashes
5547
if line_with_hash in line:
5648
return True
@@ -59,33 +51,33 @@ def is_package_exist_with_hashes(package_name,hash_of_file):
5951
def is_package_exist_without_hashes(package_name):
6052
""" Check if any line in the file contains package without same hash """
6153
# Open the file in read only mode
62-
line_with_hash = package_name + " \\" + "\n"
63-
with open("requirements.txt", 'r') as read_obj:
54+
line_with_hash = "{} \\\n".format(package_name)
55+
with open('requirements.txt') as file:
6456
# Read all lines in the file one by one
65-
for line in read_obj:
57+
for line in file:
6658
# For each line, check if line contains the string
6759
if line_with_hash in line:
6860
return True
6961
return False
7062

7163

7264
def add_package(package_name,hash_of_file):
73-
with open("requirements.txt", "a") as file_object:
65+
with open('requirements.txt', 'a') as file:
7466
# Append package with hashes at the end of file
75-
line = package_name + " \\" + "\n" + " --hash=sha256:"+ hash_of_file + " \n"
76-
file_object.write(line)
67+
line = "{} \\\n --hash=sha256:{}\n".format(package_name,hash_of_file)
68+
file.write(line)
7769

7870
def append_requirement_file(package_name,hash_of_file):
7971
if is_package_exist_with_hashes(package_name,hash_of_file):
8072
return
8173
else:
82-
inputfile = open("requirements.txt", 'r').readlines()
83-
write_file = open("requirements.txt",'w')
74+
inputfile = open('requirements.txt').readlines()
75+
write_file = open('requirements.txt','w')
8476
for line in inputfile:
8577
write_file.write(line)
86-
lion= package_name + " \\" + "\n"
87-
if lion in line:
88-
new_line = " --hash=sha256:"+ hash_of_file + " \\"
78+
current_line = package_name + " \\" + "\n"
79+
if current_line in line:
80+
new_line = " --hash=sha256:{} \\".format(hash_of_file)
8981
write_file.write(new_line + "\n")
9082
write_file.close()
9183

@@ -108,10 +100,14 @@ def hash_of_file(path):
108100
return hash.hexdigest()
109101

110102
def main():
103+
os.chdir(os.pardir) #go to etc
104+
os.chdir(os.pardir) # go to scancode-toolkit
105+
cwd = os.getcwd()
106+
print("Current working directory:", cwd)
107+
fp= open('requirements.txt','w') #Create empty file because it must exits before opening the file in read mode.
111108
for subdir, dirs, files in os.walk(cwd+"/thirdparty"):
112109
for filename in files:
113110
filepath = subdir + os.sep + filename
114-
print(filename)
115111
if filepath.endswith(".whl") and (fnmatch.fnmatchcase(filename, "*py3*") or fnmatch.fnmatchcase(filename, "*cp36*")):
116112
name = filename.split('-')[0]
117113
version = filename.split('-')[1]
@@ -133,6 +129,7 @@ def main():
133129
if is_package_exist_without_hashes(package_name):
134130
append_requirement_file(package_name,hs)
135131
else: add_package(package_name,hs)
132+
fp.close()
136133

137134
if __name__ == '__main__':
138135
main()

github_release.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (c) 2019 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+
27+
from __future__ import absolute_import
28+
from __future__ import print_function
29+
30+
import fnmatch
31+
import os
32+
import subprocess
33+
34+
35+
def main():
36+
cwd = os.getcwd()
37+
print("Current working directory:", cwd)
38+
subprocess.run(["pip3","install","github-release-retry"])
39+
token = input ("Enter GITHUB_TOKEN :")
40+
41+
os.environ ["GITHUB_TOKEN"] = token
42+
43+
tag = input ("Enter tag_name :")
44+
repo = input ("Enter name of repository name :")
45+
body = input ("Enter body string :")
46+
user = input ("Enter Github user name :")
47+
limit = input ("Enter retry limit :")
48+
for subdir, dirs, files in os.walk(cwd+"/thirdparty"):
49+
for filename in files:
50+
if fnmatch.fnmatchcase(filename, "*py3*") or fnmatch.fnmatchcase(filename, "*cp36*") or (fnmatch.fnmatchcase(filename, "*tar.gz*") and not fnmatch.fnmatchcase(filename, "*py2*")):
51+
filepath = subdir + os.sep + filename
52+
subprocess.run(["python3","-m","github_release_retry.github_release_retry","--user",user,"--repo",repo,"--tag_name",tag,"--body_string",body,"--retry_limit",limit,filepath])
53+
54+
if __name__ == '__main__':
55+
main()
56+

0 commit comments

Comments
 (0)