Skip to content

Commit 716653d

Browse files
committed
create directory hierarchy for plist file if not present. fixes #6
1 parent 0ed02b6 commit 716653d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Release history
22
---------------
33

4+
0.x.x (TBD)
5+
++++++++++++++++++
6+
- changed: create directory hierarchy for plist file if not present. issue #6
7+
48
0.2.0 (March 2021)
59
++++++++++++++++++
610
- drop python 2.x, 3.2, 3.3 support

launchd/plist.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
}
1919

2020

21+
def compute_directory(scope):
22+
return os.path.expanduser(PLIST_LOCATIONS[scope])
23+
24+
2125
def compute_filename(label, scope):
22-
return os.path.expanduser(os.path.join(PLIST_LOCATIONS[scope], label + ".plist"))
26+
return os.path.join(compute_directory(scope), label + ".plist")
2327

2428

2529
def discover_filename(label, scopes=None):
@@ -51,10 +55,12 @@ def write(label, plist, scope=USER):
5155
Writes the given property list to the appropriate file on disk and returns
5256
the absolute filename.
5357
58+
Creates the underlying parent directory structure if missing.
5459
:param plist: dict
5560
:param label: string
5661
:param scope: oneOf(USER, USER_ADMIN, DAEMON_ADMIN, USER_OS, DAEMON_OS)
5762
'''
63+
os.makedirs(compute_directory(scope), mode=0o755, exist_ok=True)
5864
fname = compute_filename(label, scope)
5965
with open(fname, "wb") as f:
6066
plistlib.dump(plist, f)

0 commit comments

Comments
 (0)