Skip to content

Commit 700830e

Browse files
canepanNicola Canepa
andauthored
Make code more pythonic (#75)
* Make code more pythonic * Make code more pythonic --------- Co-authored-by: Nicola Canepa <[email protected]>
1 parent 8aaf54c commit 700830e

File tree

2 files changed

+176
-187
lines changed

2 files changed

+176
-187
lines changed

container_configs.py

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import getpass
12
import os
3+
import pwd
24

35
class ContainerConfig:
46
def __init__(self,
@@ -8,17 +10,17 @@ def __init__(self,
810
):
911
self.root_dir = root_dir
1012
self.timezone = timezone
11-
self.config_dir = root_dir + '/config'
13+
self.config_dir = f'{root_dir}/config'
1214
self.plex_claim = plex_claim
13-
self.movie_dir = root_dir + '/media/movies'
14-
self.tv_dir = root_dir + '/media/tv'
15-
self.music_dir = root_dir + '/media/music'
16-
self.book_dir = root_dir + '/media/books'
17-
self.comic_dir = root_dir + '/media/comics'
18-
self.torrent_dir = root_dir + '/data/torrents'
19-
self.usenet_dir = root_dir + '/data/usenet'
20-
self.homarr_dir = root_dir + '/data/homarr/appdata'
21-
self.UID = os.popen('id -u').read().rstrip('\n')
15+
self.movie_dir = f'{root_dir}/media/movies'
16+
self.tv_dir = f'{root_dir}/media/tv'
17+
self.music_dir = f'{root_dir}/media/music'
18+
self.book_dir = f'{root_dir}/media/books'
19+
self.comic_dir = f'{root_dir}/media/comics'
20+
self.torrent_dir = f'{root_dir}/data/torrents'
21+
self.usenet_dir = f'{root_dir}/data/usenet'
22+
self.homarr_dir = f'{root_dir}/data/homarr/appdata'
23+
self.UID = pwd.getpwnam(getpass.getuser()).pw_uid
2224

2325
def plex(self):
2426
return (
@@ -30,10 +32,10 @@ def plex(self):
3032
' - PUID=13010\n'
3133
' - PGID=13000\n'
3234
' - VERSION=docker\n'
33-
' - PLEX_CLAIM=' + self.plex_claim + '\n'
35+
f' - PLEX_CLAIM={self.plex_claim}\n'
3436
' volumes:\n'
35-
' - ' + self.config_dir + '/plex-config:/config\n'
36-
' - ' + self.root_dir + '/data/media:/media\n'
37+
f' - {self.config_dir}/plex-config:/config\n'
38+
f' - {self.root_dir}/data/media:/media\n'
3739
' restart: unless-stopped\n\n'
3840
)
3941

@@ -45,11 +47,11 @@ def tautulli(self):
4547
' depends_on:\n'
4648
' - plex\n'
4749
' environment:\n'
48-
' - PUID='+ self.UID + '\n'
50+
f' - PUID={self.UID}\n'
4951
' - PGID=13000\n'
50-
' - TZ=' + self.timezone + '\n'
52+
f' - TZ={self.timezone}\n'
5153
' volumes:\n'
52-
' - ' + self.config_dir + '/tautulli-config:/config\n'
54+
f' - {self.config_dir}/tautulli-config:/config\n'
5355
' ports:\n'
5456
' - "8181:8181"\n'
5557
' restart: unless-stopped\n\n'
@@ -61,13 +63,13 @@ def jellyfin(self):
6163
' image: lscr.io/linuxserver/jellyfin:latest\n'
6264
' container_name: jellyfin\n'
6365
' environment:\n'
64-
' - PUID='+ self.UID + '\n'
66+
f' - PUID={self.UID}\n'
6567
' - PGID=13000\n'
6668
' - UMASK=002\n'
67-
' - TZ=' + self.timezone + '\n'
69+
f' - TZ={self.timezone}\n'
6870
' volumes:\n'
69-
' - ' + self.config_dir + '/jellyfin-config:/config\n'
70-
' - ' + self.root_dir + '/data/media:/data\n'
71+
f' - {self.config_dir}/jellyfin-config:/config\n'
72+
f' - {self.root_dir}/data/media:/data\n'
7173
' ports:\n'
7274
' - "8096:8096"\n'
7375
' restart: unless-stopped\n\n'
@@ -82,10 +84,10 @@ def sonarr(self):
8284
' - PUID=13001\n'
8385
' - PGID=13000\n'
8486
' - UMASK=002\n'
85-
' - TZ=' + self.timezone + '\n'
87+
f' - TZ={self.timezone}\n'
8688
' volumes:\n'
87-
' - ' + self.config_dir + '/sonarr-config:/config\n'
88-
' - ' + self.root_dir + '/data:/data\n'
89+
f' - {self.config_dir}/sonarr-config:/config\n'
90+
f' - {self.root_dir}/data:/data\n'
8991
' ports:\n'
9092
' - "8989:8989"\n'
9193
' restart: unless-stopped\n\n'
@@ -100,10 +102,10 @@ def radarr(self):
100102
' - PUID=13002\n'
101103
' - PGID=13000\n'
102104
' - UMASK=002\n'
103-
' - TZ=' + self.timezone + '\n'
105+
f' - TZ={self.timezone}\n'
104106
' volumes:\n'
105-
' - ' + self.config_dir + '/radarr-config:/config\n'
106-
' - ' + self.root_dir + '/data:/data\n'
107+
f' - {self.config_dir}/radarr-config:/config\n'
108+
f' - {self.root_dir}/data:/data\n'
107109
' ports:\n'
108110
' - "7878:7878"\n'
109111
' restart: unless-stopped\n\n'
@@ -117,10 +119,10 @@ def bazarr(self):
117119
' environment:\n'
118120
' - PUID=13013\n'
119121
' - PGID=13000\n'
120-
' - TZ=' + self.timezone + '\n'
122+
f' - TZ={self.timezone}\n'
121123
' volumes:\n'
122-
' - ' + self.config_dir + '/bazarr-config:/config\n'
123-
' - ' + self.root_dir + '/data/media:/media\n'
124+
f' - {self.config_dir}/bazarr-config:/config\n'
125+
f' - {self.root_dir}/data/media:/media\n'
124126
' ports:\n'
125127
' - "6767:6767"\n'
126128
' restart: unless-stopped\n\n'
@@ -135,10 +137,10 @@ def lidarr(self):
135137
' - PUID=13003\n'
136138
' - PGID=13000\n'
137139
' - UMASK=002\n'
138-
' - TZ=' + self.timezone + '\n'
140+
f' - TZ={self.timezone}\n'
139141
' volumes:\n'
140-
' - ' + self.config_dir + '/lidarr-config:/config\n'
141-
' - ' + self.root_dir + '/data:/data\n'
142+
f' - {self.config_dir}/lidarr-config:/config\n'
143+
f' - {self.root_dir}/data:/data\n'
142144
' ports:\n'
143145
' - "8686:8686"\n'
144146
' restart: unless-stopped\n\n'
@@ -153,10 +155,10 @@ def readarr(self):
153155
' - PUID=13004\n'
154156
' - PGID=13000\n'
155157
' - UMASK=002\n'
156-
' - TZ=' + self.timezone + '\n'
158+
f' - TZ={self.timezone}\n'
157159
' volumes:\n'
158-
' - ' + self.config_dir + '/readarr-config:/config\n'
159-
' - ' + self.root_dir + '/data:/data\n'
160+
f' - {self.config_dir}/readarr-config:/config\n'
161+
f' - {self.root_dir}/data:/data\n'
160162
' ports:\n'
161163
' - "8787:8787"\n'
162164
' restart: unless-stopped\n\n'
@@ -172,8 +174,8 @@ def mylar3(self):
172174
' - PGID=13000\n'
173175
' - UMASK=002\n'
174176
' volumes:\n'
175-
' - ' + self.config_dir + '/mylar-config:/config\n'
176-
' - ' + self.root_dir + '/data:/data\n'
177+
f' - {self.config_dir}/mylar-config:/config\n'
178+
f' - {self.root_dir}/data:/data\n'
177179
' ports:\n'
178180
' - "8090:8090"\n'
179181
' restart: unless-stopped\n\n'
@@ -186,12 +188,12 @@ def audiobookshelf(self):
186188
' container_name: audiobookshelf\n'
187189
' environment:\n'
188190
' - user=13014:13000\n'
189-
' - TZ=' + self.timezone + '\n'
191+
f' - TZ={self.timezone}\n'
190192
' volumes:\n'
191-
' - ' + self.config_dir + '/audiobookshelf:/config\n'
192-
' - ' + self.root_dir + '/data/media/audiobooks:/audiobooks\n'
193-
' - ' + self.root_dir + '/data/media/podcasts:/podcasts\n'
194-
' - ' + self.root_dir + '/data/media/audiobookshelf-metadata:/metadata\n'
193+
f' - {self.config_dir}/audiobookshelf:/config\n'
194+
f' - {self.root_dir}/data/media/audiobooks:/audiobooks\n'
195+
f' - {self.root_dir}/data/media/podcasts:/podcasts\n'
196+
f' - {self.root_dir}/data/media/audiobookshelf-metadata:/metadata\n'
195197
' ports:\n'
196198
' - "13378:80"\n'
197199
' restart: unless-stopped\n\n'
@@ -206,9 +208,9 @@ def prowlarr(self):
206208
' - PUID=13006\n'
207209
' - PGID=13000\n'
208210
' - UMASK=002\n'
209-
' - TZ=' + self.timezone + '\n'
211+
f' - TZ={self.timezone}\n'
210212
' volumes:\n'
211-
' - ' + self.config_dir + '/prowlarr-config:/config\n'
213+
f' - {self.config_dir}/prowlarr-config:/config\n'
212214
' ports:\n'
213215
' - "9696:9696"\n'
214216
' restart: unless-stopped\n\n'
@@ -221,9 +223,9 @@ def homarr(self):
221223
' image: ghcr.io/homarr-labs/homarr:latest\n'
222224
' container_name: homarr\n'
223225
' environment:\n'
224-
' - SECRET_ENCRYPTION_KEY=' + key + '\n'
226+
f' - SECRET_ENCRYPTION_KEY={key}\n'
225227
' volumes:\n'
226-
' - ' + self.homarr_dir + ':/appdata\n'
228+
f' - {self.homarr_dir}:/appdata\n'
227229
' - /var/run/docker.sock:/var/run/docker.sock\n'
228230
' ports:\n'
229231
' - "7575:7575"\n'
@@ -239,11 +241,11 @@ def qbittorrent(self):
239241
' - PUID=13007\n'
240242
' - PGID=13000\n'
241243
' - UMASK=002\n'
242-
' - TZ=' + self.timezone + '\n'
244+
f' - TZ={self.timezone}\n'
243245
' - WEBUI_PORT=8080\n'
244246
' volumes:\n'
245-
' - ' + self.config_dir + '/qbittorrent-config:/config\n'
246-
' - ' + self.torrent_dir + ':/data/torrents\n'
247+
f' - {self.config_dir}/qbittorrent-config:/config\n'
248+
f' - {self.torrent_dir}:/data/torrents\n'
247249
' ports:\n'
248250
' - "8080:8080"\n'
249251
' - "6881:6881"\n'
@@ -260,9 +262,9 @@ def overseerr(self):
260262
' - PUID=13009\n'
261263
' - PGID=13000\n'
262264
' - UMASK=002\n'
263-
' - TZ=' + self.timezone + '\n'
265+
f' - TZ={self.timezone}\n'
264266
' volumes:\n'
265-
' - ' + self.config_dir + '/overseerr-config:/app/config\n'
267+
f' - {self.config_dir}/overseerr-config:/app/config\n'
266268
' ports:\n'
267269
' - "5055:5055"\n'
268270
' restart: unless-stopped\n\n'
@@ -277,9 +279,9 @@ def jellyseerr(self):
277279
' - PUID=13012\n'
278280
' - PGID=13000\n'
279281
' - UMASK=002\n'
280-
' - TZ=' + self.timezone + '\n'
282+
f' - TZ={self.timezone}\n'
281283
' volumes:\n'
282-
' - ' + self.config_dir + '/jellyseerr-config:/app/config\n'
284+
f' - {self.config_dir}/jellyseerr-config:/app/config\n'
283285
' ports:\n'
284286
' - "5056:5055"\n'
285287
' restart: unless-stopped\n\n'
@@ -294,10 +296,10 @@ def sabnzbd(self):
294296
' - PUID=13011\n'
295297
' - PGID=13000\n'
296298
' - UMASK=002\n'
297-
' - TZ=' + self.timezone + '\n'
299+
f' - TZ={self.timezone}\n'
298300
' volumes:\n'
299-
' - ' + self.config_dir + '/sabnzbd-config:/config\n'
300-
' - ' + self.usenet_dir + ':/data/usenet\n'
301+
f' - {self.config_dir}/sabnzbd-config:/config\n'
302+
f' - {self.usenet_dir}:/data/usenet\n'
301303
' ports:\n'
302304
' - "8081:8080"\n'
303305
' restart: unless-stopped\n\n'
@@ -312,9 +314,9 @@ def jackett(self):
312314
' - PUID=13008\n'
313315
' - PGID=13000\n'
314316
' - UMASK=002\n'
315-
' - TZ=' + self.timezone + '\n'
317+
f' - TZ={self.timezone}\n'
316318
' volumes:\n'
317-
' - ' + self.config_dir + '/jackett-config:/config\n'
319+
f' - {self.config_dir}/jackett-config:/config\n'
318320
' ports:\n'
319321
' - 9117:9117\n'
320322
' restart: unless-stopped\n\n'
@@ -329,7 +331,7 @@ def flaresolverr(self):
329331
' - LOG_LEVEL=${LOG_LEVEL:-info}\n'
330332
' - LOG_HTML=${LOG_HTML:-false}\n'
331333
' - CAPTCHA_SOLVER=${CAPTCHA_SOLVER:-none}\n'
332-
' - TZ=' + self.timezone + '\n'
334+
f' - TZ={self.timezone}\n'
333335
' ports:\n'
334336
' - "8191:8191"\n'
335337
' restart: unless-stopped\n\n'

0 commit comments

Comments
 (0)