-
Notifications
You must be signed in to change notification settings - Fork 0
/
redpull
executable file
·55 lines (45 loc) · 1.75 KB
/
redpull
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
import os
import sys
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import logging
log = logging.getLogger("redmine")
log.setLevel(logging.DEBUG)
log.addHandler(logging.StreamHandler())
from redminelib import Redmine
from settings import *
def connect():
log.debug(f"Connecting to: {REDMINE_URL}")
redmine = Redmine(REDMINE_URL, key=REDMINE_KEY, requests={'verify': False})
user = redmine.user.get("current")
log.info(f"Hi, {user.firstname} {user.lastname}")
return redmine
def download_attached(redmine, issue_id):
issue = redmine.issue.get(issue_id)
log.debug(issue)
log.debug(f"Attachments: {[a.filename for a in issue.attachments]}")
download_dir = f"{DOWNLOAD_ROOT}/{issue_id}/"
os.makedirs(download_dir, exist_ok=True)
if len(os.listdir(download_dir)):
log.error(f"Download dir ({download_dir}) is not empty")
sys.exit(1)
log.info("Start downloading...")
for a in issue.attachments:
filename = a.filename
if os.path.exists(os.path.join(download_dir, filename)):
filename = f"{a.id}{a.filename}"
log.info(f"\tDublicate filename {a.filename}")
log.info(f"\tStore it as {filename}")
log.info(f"\t* {filename}")
a.download(savepath=download_dir, filename=filename)
log.info(f"Successfully downloaded {len(issue.attachments)} attachments to {download_dir}")
if __name__ == "__main__":
if len(sys.argv) != 2:
log.error("Wrong number of arguments!")
log.info(f"Usage {__file__} issue_id")
sys.exit(1)
if not REDMINE_KEY:
log.error("REDMINE_KEY Not defined! Set it in settings.py")
sys.exit(1)
download_attached(connect(), sys.argv[1])