Skip to content
Snippets Groups Projects
Commit a692ba29 authored by kazix's avatar kazix
Browse files

clean main.py before last commit

parent 702b86fb
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,7 @@ load_dotenv() ...@@ -18,7 +18,7 @@ load_dotenv()
try: try:
if args.production: if args.production:
token = os.getenv('PRODUCTION_TOKEN') token = os.getenv('PRODUCTION_TOKEN')
print('produkcyjny') print('Production Mode, connect to server')
headers = {'PRIVATE-TOKEN': token} headers = {'PRIVATE-TOKEN': token}
gl = gitlab.Gitlab(url='https://gitlab.geant.org', private_token=token) gl = gitlab.Gitlab(url='https://gitlab.geant.org', private_token=token)
gl_user = 'https://gitlab.geant.org/api/v4/users' gl_user = 'https://gitlab.geant.org/api/v4/users'
...@@ -28,7 +28,7 @@ try: ...@@ -28,7 +28,7 @@ try:
projects = gl.projects.list(all=True) projects = gl.projects.list(all=True)
elif args.developer: elif args.developer:
token = os.getenv('DEVELOPER_TOKEN') token = os.getenv('DEVELOPER_TOKEN')
print('testowy') print('Production Mode, connect to server')
headers = {'PRIVATE-TOKEN': token} headers = {'PRIVATE-TOKEN': token}
gl = gitlab.Gitlab(url='https://k8s-gitlab.software.geant.org', private_token=token) gl = gitlab.Gitlab(url='https://k8s-gitlab.software.geant.org', private_token=token)
gl_user = 'https://k8s-gitlab.software.geant.org/api/v4/users' gl_user = 'https://k8s-gitlab.software.geant.org/api/v4/users'
...@@ -37,38 +37,16 @@ try: ...@@ -37,38 +37,16 @@ try:
gl_branch = 'repository/branches' gl_branch = 'repository/branches'
projects = gl.projects.list(all=True) projects = gl.projects.list(all=True)
else: else:
print("No variable, exit") print("--production or --developer, please, now exit")
exit() exit()
# pobieranie listy projektów
# # testowe
# headers = {'PRIVATE-TOKEN': 'glpat-hQFB1vBzz9rQzq8wuhcG'}
# gl = gitlab.Gitlab(url='https://k8s-gitlab.software.geant.org', private_token='glpat-hQFB1vBzz9rQzq8wuhcG')
# gl_user = 'https://k8s-gitlab.software.geant.org/api/v4/users'
# gl_proj = 'https://k8s-gitlab.software.geant.org/api/v4/projects'
# gl_license = 'repository/files/LICENSE?ref='
# gl_branch = 'repository/branches'
# projects = gl.projects.list()
# # (all=True)
# produkcyjne
# headers = {'PRIVATE-TOKEN': 'glpat-P6orz6-t2f3n1BoVDrnr'}
# gl = gitlab.Gitlab(url='https://gitlab.geant.org', private_token='glpat-P6orz6-t2f3n1BoVDrnr')
# gl_user = 'https://gitlab.geant.org/api/v4/users'
# gl_proj = 'https://gitlab.geant.org/api/v4/projects'
# gl_license = 'repository/files/LICENSE?ref='
# gl_branch = 'repository/branches'
# projects = gl.projects.list(all=True)
j_project = {} j_project = {}
j_project['projects'] = {} j_project['projects'] = {}
for project in projects: for project in projects:
# print('Project ID: ', project.attributes['id']) # print('Project ID: ', project.attributes['id'])
# print('Project Name: ', project.attributes['name_with_namespace']) print('Project Name: ', project.attributes['name_with_namespace'])
# # print('branch', project.attributes['default_branch']) # # print('branch', project.attributes['default_branch'])
# print('status', project.attributes['visibility']) print('Status:', project.attributes['visibility'])
# print('aktywny', project.attributes['last_activity_at']) # print('aktywny', project.attributes['last_activity_at'])
# print('grupa', project.attributes['namespace']['name']) # print('grupa', project.attributes['namespace']['name'])
x = project.attributes['id'] x = project.attributes['id']
...@@ -84,10 +62,10 @@ try: ...@@ -84,10 +62,10 @@ try:
c_data = c_response.text c_data = c_response.text
c_answer = json.loads(c_data) c_answer = json.loads(c_data)
if "message" in c_answer: if "message" in c_answer:
# print("License file: ", c_answer['message']) print("License file: ", c_answer['message'])
lic = c_answer['message'] lic = c_answer['message']
if "file_name" in c_answer: if "file_name" in c_answer:
# print("License file: ", c_answer['file_name']) print("License file: ", c_answer['file_name'])
lic = c_answer['file_name'] lic = c_answer['file_name']
# print('branch', project.attributes['default_branch']) # print('branch', project.attributes['default_branch'])
else: else:
...@@ -95,7 +73,6 @@ try: ...@@ -95,7 +73,6 @@ try:
sep = 'T' sep = 'T'
full_act = project.attributes['last_activity_at'] full_act = project.attributes['last_activity_at']
last_act = full_act.split(sep, 1)[0] last_act = full_act.split(sep, 1)[0]
# print("ostatnia aktywnosc: ", last_act)
tmp = { tmp = {
'project_id': project.attributes['id'], 'project_id': project.attributes['id'],
'project_name': project.attributes['name_with_namespace'], 'project_name': project.attributes['name_with_namespace'],
...@@ -134,7 +111,7 @@ try: ...@@ -134,7 +111,7 @@ try:
'owner_mail_commit': user.commit_email 'owner_mail_commit': user.commit_email
} }
j_project['projects'][x]['owners'][y] = user_tmp j_project['projects'][x]['owners'][y] = user_tmp
# print(8*"-") print(8*"-")
except: except:
print('Cant connect to GitLab server, check credential') print('Cant connect to GitLab server, check credential')
exit() exit()
...@@ -150,3 +127,5 @@ new_jproject_html = json2html.convert(json=new_jproject) ...@@ -150,3 +127,5 @@ new_jproject_html = json2html.convert(json=new_jproject)
with open("gitlab-projects.html", "w", encoding='utf8') as outfile: with open("gitlab-projects.html", "w", encoding='utf8') as outfile:
outfile.write(new_jproject_html) outfile.write(new_jproject_html)
print("This is the end...")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment