-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommon.py
More file actions
105 lines (82 loc) · 4.37 KB
/
Copy pathcommon.py
File metadata and controls
105 lines (82 loc) · 4.37 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright (C) 2021 Technorabilia
# Written by Simon de Kraa <simon@technorabilia.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import textwrap
import requests
import yaml
def get_project_vars(project_name, init_vars, mode):
project_vars = init_vars.copy()
vars_url = "https://raw.githubusercontent.com/linuxserver/docker-{}/master/readme-vars.yml".format(
project_name)
response = requests.get(vars_url)
project_vars.update(yaml.load(response.text, Loader=yaml.FullLoader))
project_vars["param_env_vars"] = [row for row in project_vars["param_env_vars"] if row["env_var"] != "TZ"]
if not project_vars["param_env_vars"]:
project_vars["param_usage_include_env"] = False
# overrides
if mode == "scripts":
project_vars["param_container_name"] = project_vars["param_container_name"].replace(
"{{ project_name }}", project_vars["project_name"])
project_vars["project_blurb"] = project_vars["project_blurb"].replace(
"{{ project_name|capitalize }}", project_vars["project_name"].capitalize())
project_vars["project_blurb"] = project_vars["project_blurb"].replace(
"{{ project_name }}", project_vars["project_name"].capitalize())
project_vars["project_blurb"] = project_vars["project_blurb"].replace(
"{{ project_url }}", project_vars["project_url"])
project_vars["project_blurb"] = project_vars["project_blurb"].replace(
"\n", " ")
project_vars["project_blurb"] = project_vars["project_blurb"].replace(
'"', "'")
project_vars["project_blurb"] = ' '.join(
project_vars["project_blurb"].split())
if mode == "scripts":
lines = textwrap.wrap(
project_vars["project_blurb"], 78, break_long_words=False)
project_vars["project_blurb"] = ""
for line in lines:
project_vars["project_blurb"] += "# {}\n".format(line)
for row in project_vars["common_param_env_vars"]:
if row["env_var"] == "PGID":
row["desc"] = "Run 'id [USER]' for the owner of the host volume directories to get the GID to use here."
if row["env_var"] == "PUID":
row["desc"] = "Run 'id [USER]' for the owner of the host volume directories to get the UID to use here."
if project_vars["project_logo"] == "http://www.logo.com/logo.png":
project_vars["project_logo"] = ""
if "full_custom_readme" in project_vars.keys() and project_vars["full_custom_readme"] != "":
project_vars["project_blurb"] = "# This container needs special attention. Please check https://hub.docker.com/r/linuxserver/{} for details.".format(
project_vars["project_name"])
return project_vars
def get_initial_variables():
vars_url = "https://raw.githubusercontent.com/linuxserver/docker-jenkins-builder/master/ansible/vars/common.yml"
resp = requests.get(vars_url)
init_vars = yaml.load(resp.text, Loader=yaml.FullLoader)
vars_url = "https://raw.githubusercontent.com/linuxserver/docker-jenkins-builder/master/ansible/vars/_container-vars-blank"
resp = requests.get(vars_url)
init_vars.update(yaml.load(resp.text, Loader=yaml.FullLoader))
init_vars["param_env_vars"] = [row for row in init_vars["param_env_vars"] if row["env_var"] != "TZ"]
if not init_vars["param_env_vars"]:
init_vars["param_usage_include_env"] = False
return init_vars
def get_project_list():
image_url = "https://api.linuxserver.io/api/v1/images"
response = requests.get(image_url)
response_json = response.json()
project_list = response_json["data"]["repositories"]["linuxserver"]
project_list = list(
filter(lambda project: not project["deprecated"], project_list))
# # testing
# project_list = list(
# filter(lambda project: project["name"] == "emby", project_list))
return project_list