halib 0.1.7__py3-none-any.whl → 0.1.99__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- halib/__init__.py +84 -0
- halib/common.py +151 -0
- halib/cuda.py +39 -0
- halib/dataset.py +209 -0
- halib/filetype/csvfile.py +151 -45
- halib/filetype/ipynb.py +63 -0
- halib/filetype/jsonfile.py +1 -1
- halib/filetype/textfile.py +4 -4
- halib/filetype/videofile.py +44 -33
- halib/filetype/yamlfile.py +95 -0
- halib/gdrive.py +1 -1
- halib/online/gdrive.py +104 -54
- halib/online/gdrive_mkdir.py +29 -17
- halib/online/gdrive_test.py +31 -18
- halib/online/projectmake.py +58 -43
- halib/plot.py +296 -11
- halib/projectmake.py +1 -1
- halib/research/__init__.py +0 -0
- halib/research/base_config.py +100 -0
- halib/research/base_exp.py +100 -0
- halib/research/benchquery.py +131 -0
- halib/research/dataset.py +208 -0
- halib/research/flop_csv.py +34 -0
- halib/research/flops.py +156 -0
- halib/research/metrics.py +133 -0
- halib/research/mics.py +68 -0
- halib/research/params_gen.py +108 -0
- halib/research/perfcalc.py +336 -0
- halib/research/perftb.py +780 -0
- halib/research/plot.py +758 -0
- halib/research/profiler.py +300 -0
- halib/research/torchloader.py +162 -0
- halib/research/wandb_op.py +116 -0
- halib/rich_color.py +285 -0
- halib/sys/filesys.py +17 -10
- halib/system/__init__.py +0 -0
- halib/system/cmd.py +8 -0
- halib/system/filesys.py +124 -0
- halib/tele_noti.py +166 -0
- halib/torchloader.py +162 -0
- halib/utils/__init__.py +0 -0
- halib/utils/dataclass_util.py +40 -0
- halib/utils/dict_op.py +9 -0
- halib/utils/gpu_mon.py +58 -0
- halib/utils/listop.py +13 -0
- halib/utils/tele_noti.py +166 -0
- halib/utils/video.py +82 -0
- halib/videofile.py +1 -1
- halib-0.1.99.dist-info/METADATA +209 -0
- halib-0.1.99.dist-info/RECORD +64 -0
- {halib-0.1.7.dist-info → halib-0.1.99.dist-info}/WHEEL +1 -1
- halib-0.1.7.dist-info/METADATA +0 -59
- halib-0.1.7.dist-info/RECORD +0 -30
- {halib-0.1.7.dist-info → halib-0.1.99.dist-info/licenses}/LICENSE.txt +0 -0
- {halib-0.1.7.dist-info → halib-0.1.99.dist-info}/top_level.txt +0 -0
halib/online/gdrive.py
CHANGED
|
@@ -5,26 +5,31 @@
|
|
|
5
5
|
"""
|
|
6
6
|
import ast
|
|
7
7
|
import os
|
|
8
|
+
import requests
|
|
9
|
+
import json
|
|
8
10
|
|
|
9
11
|
import googleapiclient.errors
|
|
12
|
+
|
|
10
13
|
# Import Google libraries
|
|
11
14
|
from pydrive.auth import GoogleAuth
|
|
12
15
|
from pydrive.drive import GoogleDrive
|
|
13
16
|
from pydrive.files import GoogleDriveFileList
|
|
14
17
|
|
|
15
|
-
from
|
|
16
|
-
from
|
|
18
|
+
from ..system import filesys
|
|
19
|
+
from ..filetype import textfile
|
|
17
20
|
|
|
18
21
|
# Import general libraries
|
|
19
22
|
|
|
20
23
|
ggDrive = None
|
|
24
|
+
ggAuth = None
|
|
21
25
|
|
|
22
26
|
|
|
23
|
-
def get_gg_drive(settings_file=
|
|
27
|
+
def get_gg_drive(settings_file="settings.yaml"):
|
|
24
28
|
"""
|
|
25
|
-
|
|
29
|
+
Authenticate to Google API
|
|
26
30
|
"""
|
|
27
31
|
global ggDrive
|
|
32
|
+
global ggAuth
|
|
28
33
|
if ggDrive is None:
|
|
29
34
|
ggAuth = GoogleAuth(settings_file=settings_file)
|
|
30
35
|
ggDrive = GoogleDrive(ggAuth)
|
|
@@ -41,13 +46,13 @@ def get_folder_id(gg_parent_folder_id, folder_name):
|
|
|
41
46
|
file_list = GoogleDriveFileList()
|
|
42
47
|
try:
|
|
43
48
|
file_list = drive.ListFile(
|
|
44
|
-
{
|
|
49
|
+
{"q": "'{0}' in parents and trashed=false".format(gg_parent_folder_id)}
|
|
45
50
|
).GetList()
|
|
46
51
|
# Exit if the parent folder doesn't exist
|
|
47
52
|
except googleapiclient.errors.HttpError as err:
|
|
48
53
|
# Parse error message
|
|
49
|
-
message = ast.literal_eval(err.content)[
|
|
50
|
-
if message ==
|
|
54
|
+
message = ast.literal_eval(err.content)["error"]["message"]
|
|
55
|
+
if message == "File not found: ":
|
|
51
56
|
print(message + folder_name)
|
|
52
57
|
exit(1)
|
|
53
58
|
# Exit with stacktrace in case of other error
|
|
@@ -56,22 +61,22 @@ def get_folder_id(gg_parent_folder_id, folder_name):
|
|
|
56
61
|
|
|
57
62
|
# Find the the destination folder in the parent folder's files
|
|
58
63
|
for file1 in file_list:
|
|
59
|
-
if file1[
|
|
60
|
-
print(
|
|
61
|
-
return file1[
|
|
64
|
+
if file1["title"] == folder_name:
|
|
65
|
+
print("title: %s, id: %s" % (file1["title"], file1["id"]))
|
|
66
|
+
return file1["id"]
|
|
62
67
|
|
|
63
68
|
|
|
64
69
|
def create_folder(folder_name, gg_parent_folder_id):
|
|
65
70
|
"""
|
|
66
|
-
|
|
71
|
+
Create folder on Google Drive
|
|
67
72
|
"""
|
|
68
73
|
|
|
69
74
|
folder_metadata = {
|
|
70
|
-
|
|
75
|
+
"title": folder_name,
|
|
71
76
|
# Define the file type as folder
|
|
72
|
-
|
|
77
|
+
"mimeType": "application/vnd.google-apps.folder",
|
|
73
78
|
# ID of the parent folder
|
|
74
|
-
|
|
79
|
+
"parents": [{"kind": "drive#fileLink", "id": gg_parent_folder_id}],
|
|
75
80
|
}
|
|
76
81
|
drive = get_gg_drive()
|
|
77
82
|
folder = drive.CreateFile(folder_metadata)
|
|
@@ -79,7 +84,7 @@ def create_folder(folder_name, gg_parent_folder_id):
|
|
|
79
84
|
|
|
80
85
|
# Return folder information
|
|
81
86
|
# print('title: %s, id: %s' % (folder['title'], folder['id']))
|
|
82
|
-
return folder[
|
|
87
|
+
return folder["id"]
|
|
83
88
|
|
|
84
89
|
|
|
85
90
|
def is_in_ignore_list(local_path, ignore_list=None):
|
|
@@ -94,56 +99,88 @@ def is_in_ignore_list(local_path, ignore_list=None):
|
|
|
94
99
|
|
|
95
100
|
def upload_file(local_file_path, gg_folder_id, ignore_list=None):
|
|
96
101
|
"""
|
|
97
|
-
|
|
102
|
+
Upload local file to Google Drive folder
|
|
98
103
|
"""
|
|
99
104
|
drive = get_gg_drive()
|
|
100
105
|
if not is_in_ignore_list(local_file_path, ignore_list):
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
106
|
+
link = ""
|
|
107
|
+
|
|
108
|
+
# print('uploading ' + local_file_path)
|
|
109
|
+
try:
|
|
110
|
+
# Upload file to folder.
|
|
111
|
+
title = filesys.get_file_name(local_file_path, split_file_ext=False)
|
|
112
|
+
|
|
113
|
+
# delete file if exist on gg folder
|
|
114
|
+
query = f"'{gg_folder_id}' in parents and trashed=false"
|
|
115
|
+
file_list = drive.ListFile({"q": f"{query}"}).GetList()
|
|
116
|
+
for file in file_list:
|
|
117
|
+
if file["title"] == title:
|
|
118
|
+
# print(f'[DELETE] {title} on Google Drive')
|
|
119
|
+
file.Delete()
|
|
120
|
+
break
|
|
121
|
+
# print('uploading ' + local_file_path)
|
|
122
|
+
f = drive.CreateFile(
|
|
123
|
+
{
|
|
124
|
+
"title": f"{title}",
|
|
125
|
+
"parents": [{"kind": "drive#fileLink", "id": gg_folder_id}],
|
|
126
|
+
}
|
|
127
|
+
)
|
|
128
|
+
f.SetContentFile(local_file_path)
|
|
129
|
+
f.Upload(param={"supportsAllDrives": True})
|
|
130
|
+
access_token = (
|
|
131
|
+
ggAuth.credentials.access_token
|
|
132
|
+
) # gauth is from drive = GoogleDrive(gauth) Please modify this for your actual script.
|
|
133
|
+
# print(f'access_token {access_token}')
|
|
134
|
+
file_id = f["id"]
|
|
135
|
+
url = (
|
|
136
|
+
"https://www.googleapis.com/drive/v3/files/"
|
|
137
|
+
+ file_id
|
|
138
|
+
+ "/permissions?supportsAllDrives=true"
|
|
139
|
+
)
|
|
140
|
+
headers = {
|
|
141
|
+
"Authorization": "Bearer " + access_token,
|
|
142
|
+
"Content-Type": "application/json",
|
|
143
|
+
}
|
|
144
|
+
payload = {"type": "anyone", "value": "anyone", "role": "reader"}
|
|
145
|
+
res = requests.post(url, data=json.dumps(payload), headers=headers)
|
|
146
|
+
# SHARABLE LINK
|
|
147
|
+
link = f["alternateLink"]
|
|
148
|
+
return link
|
|
149
|
+
except Exception as e:
|
|
150
|
+
print("error uploading " + local_file_path)
|
|
151
|
+
print(e)
|
|
152
|
+
return link
|
|
119
153
|
# Skip the file if it's empty
|
|
120
154
|
else:
|
|
121
|
-
print(
|
|
155
|
+
print("file {0} is empty or in ignore list".format(local_file_path))
|
|
156
|
+
return "" # return empty string
|
|
122
157
|
|
|
123
158
|
|
|
124
|
-
def recursive_walk_and_upload(
|
|
125
|
-
|
|
159
|
+
def recursive_walk_and_upload(
|
|
160
|
+
local_folder_path, gg_folder_id, processed_path, ignore_list=None
|
|
161
|
+
):
|
|
126
162
|
for root, sub_folders, files in os.walk(local_folder_path):
|
|
127
163
|
# already processed folder
|
|
128
164
|
if root in processed_path:
|
|
129
|
-
print(f
|
|
165
|
+
print(f"[SKIP] already processed folder {root}")
|
|
130
166
|
return
|
|
131
|
-
print(f
|
|
132
|
-
print(f
|
|
167
|
+
print(f"\n\n[RECURSIVE] {local_folder_path}, {gg_folder_id}")
|
|
168
|
+
print(f"[FF] {root} {sub_folders} {files}")
|
|
133
169
|
if sub_folders:
|
|
134
170
|
for sub_folder in sub_folders:
|
|
135
171
|
sub_folder_path = os.path.join(root, sub_folder)
|
|
136
|
-
print(f
|
|
172
|
+
print(f"process {sub_folder_path}")
|
|
137
173
|
if is_in_ignore_list(sub_folder_path, ignore_list):
|
|
138
174
|
continue
|
|
139
175
|
# Get destination folder ID
|
|
140
176
|
gg_sub_folder_id = get_folder_id(gg_folder_id, sub_folder)
|
|
141
177
|
# Create the folder if it doesn't exists
|
|
142
178
|
if not gg_sub_folder_id:
|
|
143
|
-
print(
|
|
179
|
+
print("creating folder " + sub_folder)
|
|
144
180
|
gg_sub_folder_id = create_folder(sub_folder, gg_folder_id)
|
|
145
|
-
recursive_walk_and_upload(
|
|
146
|
-
|
|
181
|
+
recursive_walk_and_upload(
|
|
182
|
+
sub_folder_path, gg_sub_folder_id, processed_path, ignore_list
|
|
183
|
+
)
|
|
147
184
|
if files:
|
|
148
185
|
for file in files:
|
|
149
186
|
filePath = os.path.join(root, file)
|
|
@@ -151,15 +188,15 @@ def recursive_walk_and_upload(local_folder_path, gg_folder_id,
|
|
|
151
188
|
processed_path.append(root)
|
|
152
189
|
|
|
153
190
|
|
|
154
|
-
def upload_folder_to_drive(
|
|
155
|
-
|
|
156
|
-
|
|
191
|
+
def upload_folder_to_drive(
|
|
192
|
+
local_folder, gg_folder_id, content_only=True, ignore_file=None
|
|
193
|
+
):
|
|
194
|
+
"""
|
|
195
|
+
Upload folder to Google Drive folder
|
|
196
|
+
bool content_only: if true, we only upload files and folder inside local_folder
|
|
197
|
+
else create a folder with the same name of the local folder and upload all files and folders
|
|
198
|
+
in the local folder to it
|
|
157
199
|
"""
|
|
158
|
-
Upload folder to Google Drive folder
|
|
159
|
-
bool content_only: if true, we only upload files and folder inside local_folder
|
|
160
|
-
else create a folder with the same name of the local folder and upload all files and folders
|
|
161
|
-
in the local folder to it
|
|
162
|
-
"""
|
|
163
200
|
|
|
164
201
|
ignore_list = None
|
|
165
202
|
if ignore_file:
|
|
@@ -175,5 +212,18 @@ def upload_folder_to_drive(local_folder, gg_folder_id,
|
|
|
175
212
|
|
|
176
213
|
processed_path = []
|
|
177
214
|
local_folder = os.path.normpath(local_folder)
|
|
178
|
-
recursive_walk_and_upload(
|
|
179
|
-
|
|
215
|
+
recursive_walk_and_upload(
|
|
216
|
+
local_folder, gg_folder_id_to_upload, processed_path, ignore_list
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def main():
|
|
221
|
+
settingf = r"halib\online\settings.yaml"
|
|
222
|
+
folder_id = "1RXew5llcebEXclbEAKQ2IWDtTWmW0d_z"
|
|
223
|
+
get_gg_drive(settingf)
|
|
224
|
+
sharelink = upload_file(r"D:\Dev\github_proj\halib\LICENSE.txt", folder_id)
|
|
225
|
+
print(sharelink)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
if __name__ == "__main__":
|
|
229
|
+
main()
|
halib/online/gdrive_mkdir.py
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
from argparse import ArgumentParser
|
|
2
2
|
from datetime import datetime
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
from
|
|
4
|
+
import gdrive
|
|
5
|
+
from ..filetype import textfile
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
def parse_args():
|
|
9
|
-
parser = ArgumentParser(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
parser = ArgumentParser(description="Upload local folder to Google Drive")
|
|
10
|
+
parser.add_argument(
|
|
11
|
+
"-a",
|
|
12
|
+
"--authFile",
|
|
13
|
+
type=str,
|
|
14
|
+
help="authenticate file to Google Drive",
|
|
15
|
+
default="settings.yaml",
|
|
16
|
+
)
|
|
17
|
+
parser.add_argument(
|
|
18
|
+
"-g",
|
|
19
|
+
"--GDriveParentFolder",
|
|
20
|
+
type=str,
|
|
21
|
+
help="Destination parent folder ID in Google Drive",
|
|
22
|
+
)
|
|
23
|
+
parser.add_argument(
|
|
24
|
+
"-n",
|
|
25
|
+
"--folderName",
|
|
26
|
+
type=str,
|
|
27
|
+
help="name of the folder which is about to be created",
|
|
28
|
+
default="untitled",
|
|
29
|
+
)
|
|
18
30
|
return parser.parse_args()
|
|
19
31
|
|
|
20
32
|
|
|
@@ -24,17 +36,17 @@ def main():
|
|
|
24
36
|
gDrive_parent_folder_id = args.GDriveParentFolder
|
|
25
37
|
folder_name = args.folderName
|
|
26
38
|
|
|
27
|
-
if folder_name ==
|
|
28
|
-
folder_name = datetime.today().strftime(
|
|
39
|
+
if folder_name == "untitled":
|
|
40
|
+
folder_name = datetime.today().strftime("%Y.%m.%d_%Hh%M")
|
|
29
41
|
else:
|
|
30
|
-
date_str = datetime.today().strftime(
|
|
31
|
-
folder_name = f
|
|
42
|
+
date_str = datetime.today().strftime("%Y.%m.%d_%Hh%M")
|
|
43
|
+
folder_name = f"{date_str}_{folder_name}"
|
|
32
44
|
|
|
33
|
-
print(f
|
|
45
|
+
print(f"[GDrive] creating {folder_name} in GDrive folder {gDrive_parent_folder_id}")
|
|
34
46
|
|
|
35
47
|
gdrive.get_gg_drive(auth_file)
|
|
36
48
|
folder_id = gdrive.create_folder(folder_name, gDrive_parent_folder_id)
|
|
37
|
-
textfile.write([folder_id],
|
|
49
|
+
textfile.write([folder_id], "./GDriveFolder.txt")
|
|
38
50
|
|
|
39
51
|
|
|
40
52
|
if __name__ == "__main__":
|
halib/online/gdrive_test.py
CHANGED
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
from argparse import ArgumentParser
|
|
2
|
-
|
|
3
|
-
from halib.online import gdrive
|
|
2
|
+
import gdrive
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
def parse_args():
|
|
7
|
-
parser = ArgumentParser(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
parser.add_argument(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
parser = ArgumentParser(description="Upload local folder to Google Drive")
|
|
7
|
+
parser.add_argument(
|
|
8
|
+
"-a",
|
|
9
|
+
"--authFile",
|
|
10
|
+
type=str,
|
|
11
|
+
help="authenticate file to Google Drive",
|
|
12
|
+
default="settings.yaml",
|
|
13
|
+
)
|
|
14
|
+
parser.add_argument("-s", "--source", type=str, help="Folder to upload")
|
|
15
|
+
parser.add_argument(
|
|
16
|
+
"-d", "--destination", type=str, help="Destination folder ID in Google Drive"
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"-c",
|
|
20
|
+
"--contentOnly",
|
|
21
|
+
type=str,
|
|
22
|
+
help="Parent Folder in Google Drive",
|
|
23
|
+
default="True",
|
|
24
|
+
)
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"-i",
|
|
27
|
+
"--ignoreFile",
|
|
28
|
+
type=str,
|
|
29
|
+
help="file containing files/folders to ignore",
|
|
30
|
+
default=None,
|
|
31
|
+
)
|
|
19
32
|
|
|
20
33
|
return parser.parse_args()
|
|
21
34
|
|
|
@@ -25,12 +38,12 @@ def main():
|
|
|
25
38
|
auth_file = args.authFile
|
|
26
39
|
local_folder = args.source
|
|
27
40
|
gg_folder_id = args.destination
|
|
28
|
-
content_only =
|
|
41
|
+
content_only = args.contentOnly.lower() == "true"
|
|
29
42
|
ignore_file = args.ignoreFile
|
|
30
43
|
gdrive.get_gg_drive(auth_file)
|
|
31
|
-
gdrive.upload_folder_to_drive(
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
gdrive.upload_folder_to_drive(
|
|
45
|
+
local_folder, gg_folder_id, content_only=content_only, ignore_file=ignore_file
|
|
46
|
+
)
|
|
34
47
|
|
|
35
48
|
|
|
36
49
|
if __name__ == "__main__":
|
halib/online/projectmake.py
CHANGED
|
@@ -8,9 +8,8 @@ import subprocess
|
|
|
8
8
|
|
|
9
9
|
import certifi
|
|
10
10
|
import pycurl
|
|
11
|
-
|
|
12
|
-
from
|
|
13
|
-
from halib.sys import filesys
|
|
11
|
+
from ..filetype import jsonfile
|
|
12
|
+
from ..system import filesys
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
def get_curl(url, user_and_pass, verbose=True):
|
|
@@ -23,42 +22,48 @@ def get_curl(url, user_and_pass, verbose=True):
|
|
|
23
22
|
|
|
24
23
|
|
|
25
24
|
def get_user_and_pass(username, appPass):
|
|
26
|
-
return f
|
|
25
|
+
return f"{username}:{appPass}"
|
|
27
26
|
|
|
28
27
|
|
|
29
|
-
def create_repo(
|
|
30
|
-
|
|
28
|
+
def create_repo(
|
|
29
|
+
username, appPass, repo_name, workspace, proj_name, template_repo="py-proj-template"
|
|
30
|
+
):
|
|
31
31
|
buffer = BytesIO()
|
|
32
|
-
url = f
|
|
33
|
-
data = json.dumps({
|
|
32
|
+
url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_name}"
|
|
33
|
+
data = json.dumps({"scm": "git", "project": {"key": f"{proj_name}"}})
|
|
34
34
|
|
|
35
35
|
user_and_pass = get_user_and_pass(username, appPass)
|
|
36
36
|
c = get_curl(url, user_and_pass)
|
|
37
37
|
c.setopt(pycurl.WRITEDATA, buffer)
|
|
38
38
|
c.setopt(pycurl.POST, 1)
|
|
39
39
|
c.setopt(pycurl.POSTFIELDS, data)
|
|
40
|
-
c.setopt(pycurl.HTTPHEADER, [
|
|
40
|
+
c.setopt(pycurl.HTTPHEADER, ["Accept: application/json"])
|
|
41
41
|
c.perform()
|
|
42
42
|
RESPOND_CODE = c.getinfo(pycurl.HTTP_CODE)
|
|
43
43
|
c.close()
|
|
44
44
|
# log info
|
|
45
45
|
body = buffer.getvalue()
|
|
46
|
-
msg = body.decode(
|
|
47
|
-
successful = True if str(RESPOND_CODE) ==
|
|
46
|
+
msg = body.decode("iso-8859-1")
|
|
47
|
+
successful = True if str(RESPOND_CODE) == "200" else False
|
|
48
48
|
|
|
49
49
|
if successful and template_repo:
|
|
50
|
-
template_repo_url = f
|
|
50
|
+
template_repo_url = f"https://{username}:{appPass}@bitbucket.org/{workspace}/{template_repo}.git"
|
|
51
51
|
git_clone(template_repo_url)
|
|
52
|
-
template_folder = f
|
|
52
|
+
template_folder = f"./{template_repo}"
|
|
53
53
|
|
|
54
|
-
created_repo_url =
|
|
54
|
+
created_repo_url = (
|
|
55
|
+
f"https://{username}:{appPass}@bitbucket.org/{workspace}/{repo_name}.git"
|
|
56
|
+
)
|
|
55
57
|
git_clone(created_repo_url)
|
|
56
|
-
created_folder = f
|
|
57
|
-
shutil.copytree(
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
created_folder = f"./{repo_name}"
|
|
59
|
+
shutil.copytree(
|
|
60
|
+
template_folder,
|
|
61
|
+
created_folder,
|
|
62
|
+
dirs_exist_ok=True,
|
|
63
|
+
ignore=shutil.ignore_patterns(".git"),
|
|
64
|
+
)
|
|
60
65
|
os.system('rmdir /S /Q "{}"'.format(template_folder))
|
|
61
|
-
project_folder =
|
|
66
|
+
project_folder = "project_name"
|
|
62
67
|
|
|
63
68
|
filesys.change_current_dir(created_folder)
|
|
64
69
|
filesys.rename_dir_or_file(project_folder, repo_name)
|
|
@@ -69,15 +74,20 @@ def create_repo(username, appPass, repo_name, workspace,
|
|
|
69
74
|
|
|
70
75
|
|
|
71
76
|
def parse_args():
|
|
72
|
-
parser = ArgumentParser(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
parser = ArgumentParser(description="Upload local folder to Google Drive")
|
|
78
|
+
parser.add_argument(
|
|
79
|
+
"-a",
|
|
80
|
+
"--authFile",
|
|
81
|
+
type=str,
|
|
82
|
+
help="authenticate file (json) to Bitbucket",
|
|
83
|
+
default="bitbucket.json",
|
|
84
|
+
)
|
|
85
|
+
parser.add_argument(
|
|
86
|
+
"-r", "--repoName", type=str, help="Repository name", default="hahv-proj"
|
|
87
|
+
)
|
|
88
|
+
parser.add_argument(
|
|
89
|
+
"-t", "--templateRepo", type=str, help="template repo to fork", default="True"
|
|
90
|
+
)
|
|
81
91
|
return parser.parse_args()
|
|
82
92
|
|
|
83
93
|
|
|
@@ -91,24 +101,29 @@ def main():
|
|
|
91
101
|
repo_name = args.repoName
|
|
92
102
|
|
|
93
103
|
authInfo = jsonfile.read(authFile)
|
|
94
|
-
username = authInfo[
|
|
95
|
-
appPass = authInfo[
|
|
96
|
-
workspace_id = authInfo[
|
|
97
|
-
project_id = authInfo[
|
|
98
|
-
use_template =
|
|
99
|
-
template_repo = authInfo[
|
|
100
|
-
|
|
101
|
-
extra_info = f
|
|
102
|
-
print(f
|
|
103
|
-
|
|
104
|
-
successful, msg = create_repo(
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
username = authInfo["username"]
|
|
105
|
+
appPass = authInfo["appPass"]
|
|
106
|
+
workspace_id = authInfo["workspace_id"]
|
|
107
|
+
project_id = authInfo["project_id"]
|
|
108
|
+
use_template = args.templateRepo.lower() == "true"
|
|
109
|
+
template_repo = authInfo["template_repo"] if use_template else ""
|
|
110
|
+
|
|
111
|
+
extra_info = f"[Use template project {template_repo}]" if use_template else ""
|
|
112
|
+
print(f"[BitBucket] creating {repo_name} Project in Bitbucket {extra_info}")
|
|
113
|
+
|
|
114
|
+
successful, msg = create_repo(
|
|
115
|
+
username,
|
|
116
|
+
appPass,
|
|
117
|
+
repo_name,
|
|
118
|
+
workspace_id,
|
|
119
|
+
project_id,
|
|
120
|
+
template_repo=template_repo,
|
|
121
|
+
)
|
|
107
122
|
if successful:
|
|
108
|
-
print(f
|
|
123
|
+
print(f"[Bitbucket] {repo_name} created successfully.{extra_info}")
|
|
109
124
|
else:
|
|
110
125
|
formatted_msg = jsonfile.beautify(msg)
|
|
111
|
-
print(f
|
|
126
|
+
print(f"[Bitbucket] {repo_name} created failed. Details:\n{formatted_msg}")
|
|
112
127
|
|
|
113
128
|
|
|
114
129
|
if __name__ == "__main__":
|