[sysadmin-bin] Don't use execfile, re-use the existing cfg file



commit a47d1a20a689794c6167567bcc420db629270a54
Author: Andrea Veri <averi redhat com>
Date:   Thu Feb 7 13:48:43 2019 +0100

    Don't use execfile, re-use the existing cfg file

 deprecated_github_repos.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
---
diff --git a/deprecated_github_repos.py b/deprecated_github_repos.py
index a2e2314..4faea17 100755
--- a/deprecated_github_repos.py
+++ b/deprecated_github_repos.py
@@ -2,7 +2,7 @@
 
 import os
 
-cfg_file = '/home/admin/secret/github2.oauth'
+cfg_file = '/home/admin/secret/deprecated_github_repos.cfg'
 
 if not os.path.isfile(cfg_file):
     print 'No configuration file could be found at %s' % cfg_file
@@ -13,18 +13,18 @@ else:
     secure_config = ConfigParser.ConfigParser()
     secure_config.read(cfg_file)
 
-if secure_config.has_option("github", "oauth_token"):
-    auth_token = secure_config.get("github", "oauth_token")
+if secure_config.has_option('github', 'oauth_token') and secure_config.has_option('gitlab', 'rw_token'):
+    gh_token = secure_config.get('github', "oauth_token')
+    gl_token = secure_config.get('gitlab', 'rw_token')
 else:
-    print 'Make sure %s has a github section and an oauth_token key/value pair' % cfg_file
+    print 'Make sure %s has a github/gitlab section and an oauth_token/rw_token key/value pair' % cfg_file
     sys.exit(1)
 
 def l_gitlab_repos():
     import gitlab
     gitlab_projects = list()
 
-    execfile('/home/admin/secret/gitlab_rw')
-    gl = gitlab.Gitlab('https://gitlab.gnome.org', GITLAB_PRIVATE_RW_TOKEN, api_version=4)
+    gl = gitlab.Gitlab('https://gitlab.gnome.org', gl_token, api_version=4)
 
     group = gl.groups.get(8, with_projects=False)
     projects = group.projects.list(all=True)
@@ -42,7 +42,7 @@ def l_github_repos(url='https://api.github.com/orgs/GNOME/repos?per_page=100'):
     url = str(url)
 
     req = Request(url)
-    req.add_header('Authorization', 'token %s' % auth_token)
+    req.add_header('Authorization', 'token %s' % gh_token)
     response = urlopen(req)
     link = response.info().getheader('link')
     response.close()
@@ -53,7 +53,7 @@ def l_github_repos(url='https://api.github.com/orgs/GNOME/repos?per_page=100'):
     for i in range(1, int(last_page) + 1):
         _url = url + '&page=%i' % i
         r = Request(_url)
-        r.add_header('Authorization', 'token %s' % auth_token)
+        r.add_header('Authorization', 'token %s' % gh_token)
         resp = urlopen(r)
 
         content = resp.read()
@@ -73,7 +73,7 @@ def delete_repo(repo_name, url='https://api.github.com/repos/GNOME'):
     url = str('%s/%s') % (url, repo_name)
 
     req = Request(url)
-    req.add_header('Authorization', 'token %s' % auth_token)
+    req.add_header('Authorization', 'token %s' % gh_token)
     req.get_method = lambda: 'DELETE'
 
     try:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]