forked from rvojcik/gitlab-project-export
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wiro
committed
Dec 20, 2018
1 parent
851270c
commit b13cae9
Showing
5 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,6 @@ dist/ | |
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
|
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import print_function | ||
import yaml | ||
import os | ||
|
||
class Config: | ||
'''Load configuration from yaml file''' | ||
|
||
def __init__(self,config_file): | ||
'''Init config object''' | ||
|
||
self.config_file = config_file | ||
self.config_open() | ||
self.config_load() | ||
self.config_close() | ||
|
||
def config_open(self): | ||
try: | ||
self.conf_fh = open(self.config_file,'r') | ||
except IOError, e: | ||
print("({})".format(e)) | ||
sys.exit(1) | ||
|
||
def config_close(self): | ||
self.conf_fh.close() | ||
|
||
def config_load(self): | ||
self.config = yaml.load(self.conf_fh.read()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from __future__ import print_function | ||
import requests | ||
import urllib | ||
import sys | ||
import time | ||
|
||
class Api: | ||
'''Api class for gitlab''' | ||
|
||
def __init__(self,gitlab_url, token): | ||
'''Init config object''' | ||
self.headers = { "PRIVATE-TOKEN": token } | ||
self.api_url = gitlab_url + "/api/v4" | ||
self.download_url = None | ||
|
||
def __api_export(self, project_url): | ||
'''Send export request to API''' | ||
self.download_url = None | ||
return requests.post(self.api_url+"/projects/" + project_url + "/export", headers=self.headers) | ||
|
||
def __api_status(self,project_url): | ||
'''Check project status''' | ||
return requests.get(self.api_url+"/projects/" + project_url + "/export", headers=self.headers) | ||
|
||
def project_export(self, project_path): | ||
url_project_path = urllib.quote(project_path, safe='') | ||
|
||
# Let's export project | ||
r = self.__api_export(url_project_path) | ||
if ( str(r.status_code) == "202" ): | ||
# Api good, check for status | ||
max_tries = 20 | ||
s = "" | ||
status_export = False | ||
while max_tries != 0: | ||
# Decrement tries | ||
max_tries -= 1 | ||
|
||
r = self.__api_status(url_project_path) | ||
|
||
# Check API reply status | ||
if ( r.status_code == requests.codes.ok ): | ||
json = r.json() | ||
|
||
# Check export status | ||
print(json) | ||
if "export_status" in json.keys(): | ||
s = json["export_status"] | ||
if s == "finished": | ||
status_export = True | ||
break | ||
else: | ||
s = "unknown" | ||
print(s) | ||
|
||
else: | ||
print("API not respond well with %s" %(str(r.status_code)), file=sys.stderr) | ||
break | ||
|
||
# Wait litle bit | ||
time.sleep(2) | ||
|
||
if status_export: | ||
self.download_url = json["_links"] | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
|
||
else: | ||
print("API not respond well with %s" %(str(r.status_code)), file=sys.stderr) | ||
return False | ||
|