fix: create the systemd folder if it doesn't already exist

This commit is contained in:
Andreas Zweili 2019-02-23 14:24:15 +01:00
parent d3b94ac49d
commit 276d12a835
1 changed files with 7 additions and 2 deletions

View File

@ -6,14 +6,19 @@ import subprocess
class SystemdFile(): class SystemdFile():
def __init__(self, file_name): def __init__(self, file_name):
self.file_name = file_name self.file_name = file_name
self.path = os.path.join(os.environ['HOME'], self.systemd_folder = os.path.join(os.environ['HOME'],
'.config/systemd/user/', '.config/systemd/user/')
self.path = os.path.join(self.systemd_folder,
self.file_name) self.file_name)
self.content = configparser.ConfigParser() self.content = configparser.ConfigParser()
self.content.optionxform = str self.content.optionxform = str
self.content['Unit'] = {} self.content['Unit'] = {}
def write(self): def write(self):
try:
os.makedirs(self.systemd_folder)
except OSError:
pass
with open(self.path, 'w+') as configfile: with open(self.path, 'w+') as configfile:
self.content.write(configfile) self.content.write(configfile)