Skip to content

Commit

Permalink
Allow using {USER} and {USERNAME} in cmd
Browse files Browse the repository at this point in the history
This allows a very specific amount of configurability, so
you can spawn notebooks from different places based on the
username. This was preferred to a different solution involving
making these into callables instead, since that opens up a lot
more flexibility - causing problems for backwards compatibility.
  • Loading branch information
yuvipanda committed Sep 22, 2016
1 parent 71ce38f commit 8d9fbc8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion systemdspawner/systemdspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def get_state(self):
state['unit_name'] = self.unit_name
return state

def _expand_user_vars(self, string):
"""
Expand user related variables in a given string
Currently expands:
{USERNAME} -> Name of the user
{USERID} -> UserID
"""
return string.format(
USERNAME=self.user.name,
USERID=self.user.id
)

@gen.coroutine
def start(self):
self.port = random_port()
Expand Down Expand Up @@ -103,7 +116,7 @@ def start(self):
'--property=CPUQuota={quota}%'.format(quota=self.cpu_limit)
])

cmd.extend(self.cmd)
cmd.extend([self._expand_user_vars(c) for c in self.cmd])
cmd.extend(self.get_args())

self.proc = subprocess.Popen(cmd, start_new_session=True)
Expand Down

0 comments on commit 8d9fbc8

Please sign in to comment.