The launchdman API reference

inherited-members:
 
class launchdman.__init__.AbandonProcessGroup(key='')

AbandonProcessGroup config

Example:

config = AbandonProcessGroup()
class launchdman.__init__.AfterInitialDemand(*key)

AfterInitialDemand option for KeepAlive

class launchdman.__init__.ArraySingle(*value)

Single with default tag as ‘array’.

class launchdman.__init__.BoolPair(key='')

A special type of pair that contains it’s key and only one tag, usually </true> or </false>.

setToFalse()

Might be needed, set value to false.

setToTrue()

This method sets the value of key true.

class launchdman.__init__.BoolSingle(boolValue)

A type of Single that only have a single tag that usually indicate true of false.

Example:

</true>
<false>
class launchdman.__init__.Crashed(key='')

Crashed option for KeepAlive

class launchdman.__init__.DictSingle(*value)

Single with default tag as ‘dict’.

class launchdman.__init__.EnvironmentVariables(path)

EnvironmentVariables config

Example:

config = EnvironmentVariables('/bin:/usr/bin:/usr/local/bin')
config.changeTo('some-other-env')
changeTo(path)

change value

Parameters:path (str) – the new environment path
class launchdman.__init__.ExitTimeOut(integer)

ExitTimeOut config

Example:

config = Label(30)
config.changeTo(60)
class launchdman.__init__.GroupName(string)

GroupName config

Example:

config = GroupName('some-group')
config.changeTo('some-other-group')
class launchdman.__init__.HardResourceLimit(dic)

HardResourceLimit config

Example:

config = HardResourceLimit({'CPU': 2, 'FileSize': 1024})
config.add({'NumberOfFiles': 10})
config.remove({'CPU': 2})

Avaliable keys are: CPU, FileSize, NumberOfFiles, Core, Data, MemoryLock, NumberOfProcesses, ResidentSetSize, Stack.

class launchdman.__init__.InitGroups(string)

Label InitGroups

Example:

config = InitGroups('some-group')
config.changeTo('some-other-group')
class launchdman.__init__.IntegerSingle(*value)

Single with default tag as ‘integer’.

class launchdman.__init__.Job(path)

Each Job is correspond to a plist.

printMe(selfTag, selfValue)

Parse the job into plist format.

Parameters:
  • selfTag (str) – The tag. Usually self.tag
  • selfValue (list) – The value list. Usually self.value
write()

Write the job to the corresponding plist.

launchdman.__init__.KeepAlive(branch='always', *key)

KeepAlive config

Example:

config = KeepAlive('always') # keepAlive no matter what
config2 = KeepAlive('depends', SuccessfulExit())
config2.addKey(Crashed())
config2.removeKey(Crashed())
config2.addKey(OtherJobEnabled('some-job'))

You can also use KeepAliveAlways() or KeepAliveDepends(), KeepAlive() is just a helper function that returns either one of the two classes.

Parameters:
  • branch (str) – indicates which version of KeepAlive you want, can be either ‘always’ or ‘depends’.
  • *key (str) – If there is any key to be passed to depend version of KeepAlive, put it in key. Possible keys are SuccessfulExit(), Crashed(), OtherJobEnabled(), AfterInitialDemand() and PathState().
Raises:

KeyError – if branch is not one of ‘always’ and ‘depends’

Returns:

the actual class. Either KeepAliveAlways or KeepAliveDepends.

Return type:

class

class launchdman.__init__.KeepAliveAlways

KeepAlive option

class launchdman.__init__.Label(string)

Label config

Example:

config = Label('some-label')
config.changeTo('some-other-label')
class launchdman.__init__.LegacyTimers(key='')

LegacyTimers config

Example:

config = LegacyTimers()
class launchdman.__init__.Nice(integer)

Nice config

Example:

config = Nice(-5)
config.changeTo(20)
class launchdman.__init__.OtherJobEnabled(*key)

OtherJobEnabled option for KeepAlive

Example:

OtherJobEnabled('some-job')
class launchdman.__init__.OuterOFInnerPair(Outer, Inner, *l)

A “double layer” Pair. e.g.: array of string, dict of pair, array of bool Outer can be: ArraySingle, DictSingle Inner can be: Pair, StringSingle, IntegerSingle, BoolPair

add(*l)

add inner to outer

Parameters:*l – element that is passed into Inner init
remove(*l)

remove inner from outer

Parameters:element that is passes into Inner init (*l) –
class launchdman.__init__.Pair(key='', *value)

A data type that have a key and it’s value. For example:

<key>some_key</key> # some_key is the key
<array> # array is the value
    <string>something</string>
</array>
parse()

parse the pair in plist format. A wrapper of printMe().

Returns:the parsed text
Return type:str
printMe(selfKey, selfValue)

Parse the single and its value and return the parsed str.

Parameters:
  • selfTag (str) – The tag. Normally just self.tag
  • selfValue (list) – a list of value elements(single, subclasses, str, int). Normally just self.value
Returns:

A parsed text

Return type:

str

class launchdman.__init__.PathState(*key)

PathState option for KeepAlive

class launchdman.__init__.Program(string)

Program config

Example:

config = Program('/path/to/program')
config.changeTo('/new/path/to/program')
class launchdman.__init__.ProgramArguments(*l)

ProgramArguments config

Example:

config = ProgramArguments(['-r', '--outfile', '-m'])
config = ProgramArguments('-r')
config = ProgramArguments('-r', '-m', '--file')
config.remove('-r')
config.add('--kill')
class launchdman.__init__.QueueDirecotries(*l)

QueueDirectories config

Example:

config = QueueDirectories(['/path1', '/path2', '/path3'])
config = QueueDirectories('/path2')
config = QueueDirectories('/path1', '/path2', '/path3')
config.remove('/path1')
config.add('/path1')
class launchdman.__init__.RootDirecotry(string)

RootDirecotry config

Example:

config = RootDirecotry('some-dir')
config.changeTo('some-other-dir')
class launchdman.__init__.RunAtLoad(key='')

RunAtLoad config

Example:

config = RunAtLoad()
class launchdman.__init__.Single(tag, *value)

A type of structure that only have a tag and it’s values. It is parsed sush as

<tag>value</tag> # for on value element and

<tag>
    value1
    value2
</tag> # for multiple value element

Overwrite printMe(tag, value) if subclass parse differently from Single.

Properties:
tag (string): the tag value (list): A list of values. element can be Single and any subclass of it, string, integer. Other data type might be possible, but not used in launchd files.
add(*value)

convert value and add to self.value

Subclass must overwrite this method. Subclass are responsible of creating whatever single instance it need from its add(*value) and call _add() to add them to self.value

Parameters:*value – the value to be added
clear()

Remove everything in a Single

findAll(selfValue)

Looks for all the non single values(str, int) recursively and returns a list of them

Parameters:selfValue – A list of single, str, int. Normally just self.value
Returns:A list contains only non singles(str, int).
Return type:list
findAllSingle(selfValue)

Looks for all the single values and subclasses recursively and returns a list of them

Parameters:selfValue – A list of single, str, int. Normally just self.value
Returns:A list contains only singles and subclasses.
Return type:list
parse()

A wrap of PrintMe, which parse the single and its value and returns a str. In most cases, this is the method you need to use.

printMe(selfTag, selfValue)

Parse the single and its value and return the parsed str.

Parameters:
  • selfTag (str) – The tag. Normally just self.tag
  • selfValue (list) – a list of value elements(single, subclasses, str, int). Normally just self.value
Returns:

A parsed text

Return type:

str

remove(*l)

remove elements from self.value by matching.

Create the exactly same single you want to delete and pass it(them) in. Normally this method needs to be overwrited by subclass. It only looks inside current instance’s value, not recursive. There is no need for a recursive one anyway.

Parameters:*l – a single element, a bunch of element seperated by comma, or a list of elements, or any combination. Element is what you match with.
class launchdman.__init__.SingleDictPair(dic)

Pair that contains one DictSingle(which contains pairs) in its value.

add(dic)

adds a dict as pair

Parameters:dic (dict) – key and value
remove(dic)

remove the pair by passing a identical dict

Parameters:dic (dict) – key and value
class launchdman.__init__.SingleIntegerPair(integer)

The Pair that contains only a integer.

Since there is only a single element in value. add() and remove() is not needed. Instead there is a changTo() method.

changeTo(newInt)

This method change the value element of the Pair.

Parameters:newInt (int) – The integer you want to change to
class launchdman.__init__.SingleStringPair(string)

Pair that conntains only a string in its value.

Since there is only a single element in value. add() and remove() is not needed. Instead there is a changTo() method.

changeTo(newString)

This method change the value element of the Pair.

Parameters:newString (str) – The string you want to change to
class launchdman.__init__.SoftResourceLimit(dic)

SoftResourceLimit config

Example:

config = SoftResourceLimit({'CPU': 2, 'FileSize': 1024})
config.add({'NumberOfFiles': 10})
config.remove({'CPU': 2})

Avaliable keys are: CPU, FileSize, NumberOfFiles, Core, Data, MemoryLock, NumberOfProcesses, ResidentSetSize, Stack.

class launchdman.__init__.StandardErrorPath(string)

StandardErrorPath config

Example:

config = StandardErrorPath('/tmp/error')
config.changeTo('some/other/path')
class launchdman.__init__.StandardInPath(string)

StandardInPath config

Example:

config = StandardInPath('/tmp/in')
config.changeTo('some/other/path')
class launchdman.__init__.StandardOutPath(string)

StandardOutPath config

Example:

config = StandardOutPath('/tmp/out')
config.changeTo('some/other/path')
class launchdman.__init__.StartCalendarInterval(*dic)

Set StartCalendarInterval config

Usage:
pass a dictionary as setting into StartCalendarInterval, possible key words are Month, Day, Weekday, Hour, Minute. Note the uppercase.

For example:

# for simple config
schedule = StartCalendarInterval({'Day': 1, 'Month': 3}) # every March 1st

# for more straight forward syntax, use gen()
schedule.add(schedule.gen(day=1, month=3)) # every March 1st

# for a interval schedule, use genInterval()
schedule.add(schedule.genInterval(day=(1,15))) # from 1st to 15th every month

# for more complicated(corn-like) schedule, use genMix()
schedule.add(schedule.genMix(day=(1, 3, 5), month=(2,4)))

schedule.add(schedule.genMix(day=tuple(range(1, 10, 2))))
# 1st, 3rd, 5th, 7th, 9th every month

# like other add() method, StartCalendarInterval.add() can take multiple arguments or lists
schedule.add(schedule.gen(day=1), schedule.gen(day=15), [schedule.gen(month=12), schedule.gen(weekday=3)])
add(*dic)

add a config to StartCalendarInterval.

Parameters:*dic (dict) – dictionary with format {‘Day’: 12, ‘Hour’: 34} Avaliable keys are Month, Day, Weekday, Hour, Minute. Note the uppercase. You can use gen(), genMix() to generate complex config dictionary.
gen(month=0, week=0, day=0, weekday=0, hour=0, minute=0)

generate config dictionary to pass to add() or remove()

Parameters:
  • month (int) – month in a year, from 1 to 12
  • week (int) – week in a month, from 1 to 4
  • day (int) – day in a month, from 1 to 31
  • weekday (int) – weekday in a week, from 0 to 7. 0 and 7 both represent Sunday
  • hour (int) – hour in a day, from 0 to 24
  • minute (int) – minute in an hour, from 0 to 59
Returns:

a dictionary with form {‘Day’: 1, etc}

Return type:

dict

genInterval(month=(), day=(), week=(), weekday=(), hour=(), minute=())

Generate list of config dictionarie(s) that represent a interval of time. Used to be passed into add() or remove(). For example:

genInterval(month=(1,4), week(1,4))
# generate list contains from first to third week in from January to March
Parameters:
  • month (tuple) – (start, end) month in a year, from 1 to 12
  • week (tuple) – (start, end) week in a month, from 1 to 4
  • day (tuple) – (start, end) day in a month, from 1 to 31
  • weekday (tuple) – (start, end) weekday in a week, from 0 to 7. 0 and 7 both represent Sunday
  • hour (tuple) – (start, end) hour in a day, from 0 to 24
  • minute (tuple) – (start, end) minute in an hour, from 0 to 59
Returns:

a list of dictionarie(s) with form [{‘Day’:12, ‘Month’:3}, {}, etc]

Return type:

list

genMix(month=(), day=(), week=(), weekday=(), hour=(), minute=())

Generate a list of config dictionarie(s), in form of [{‘Day’:12, ‘Month’:3}, {}, etc] For example:

genMix(month=(1, 4, 6, 8), day=tuple(range(1, 30, 2)))
# Keep in mind that range(1, n) gives you (1, 2, ... , n-1)
Parameters:
  • month (tuple) – month in a year, from 1 to 12
  • week (tuple) – week in a month, from 1 to 4
  • day (tuple) – day in a month, from 1 to 31
  • weekday (tuple) – weekday in a week, from 0 to 7. 0 and 7 both represent Sunday
  • hour (tuple) – hour in a day, from 0 to 24
  • minute (tuple) – minute in an hour, from 0 to 59
Returns:

a list of dictionarie(s) with form [{‘Day’:12, ‘Month’:3}, {}, etc]

Return type:

list

remove(*dic)

remove a calendar config.

Parameters:*dic (dict) – dictionary with format {‘Day’: 12, ‘Hour’: 34} Avaliable keys are Month, Day, Weekday, Hour, Minute. Note the uppercase. You can use gen(), genMix() to generate complex config dictionary.
class launchdman.__init__.StartInterval

StartInterval config

Example

config = StartInterval().every(1).second config = StartInterval().every(10).day

Avaliable time intervals are: second, minute. hour, day, week.

day

set unit to day

every(baseNumber)

set base number

Parameters:baseNumber (str) – number of day/minute/second/etc
hour

set unit to hour

minute

set unit to minute

second

set unit to second

week

set unit to week

class launchdman.__init__.StartOnMount(key='')

StartOnMount config

Example:

config = StartOnMount()
class launchdman.__init__.StringSingle(*value)

Single with default tag as ‘string’.

class launchdman.__init__.SuccessfulExit(key='')

SuccessfulExit option for KeepAlive

class launchdman.__init__.ThrottleInverval(integer)

ThrottleInverval config

Example:

config = Label(5)
config.changeTo(10)
KeepAlive('always', ThrottleInverval(5))
class launchdman.__init__.Timeout(integer)

Timeout config

Example:

config = Timeout(30)
config.changeTo(60)
class launchdman.__init__.TypedSingle(*value)

A little sugar so that you don’t need to type the tag every time creating a specific single. This class is meant to be inheritated by specific type single classes such as arraySingle and StringSingle. The class name of subclass will become the tag. For example:

ArraySingle.tag -> 'array'
class launchdman.__init__.Umask(integer)

Umask config

Example:

config = Label(0)
config.changeTo(1)
class launchdman.__init__.UserName(string)

UserName config

Example:

config = UserName('some-user')
config.changeTo('some-other-user')
class launchdman.__init__.WatchPaths(*l)

WatchPaths config

Example:

config = WatchPaths(['/path1', '/path2', '/path3'])
config = WatchPaths('/path2')
config = WatchPaths('/path1', '/path2', '/path3')
config.remove('/path1')
config.add('/path1')
class launchdman.__init__.WorkingDirectory(string)

WorkingDirectory config

Example:

config = WorkingDirectory('/home')
config.changeTo('some/other/path')
launchdman.__init__.ancestor(obj)

Trace the parent tree of the object and return the second last one.(under object)

Parameters:obj (object) – Literally anything.
Returns:a class object
Return type:class
launchdman.__init__.ancestorJr(obj)

Trace the parent tree of the object and return the third last one.(under object and anothr parent)

Parameters:obj (object) – Literally anything.
Returns:a class object
Return type:class
launchdman.__init__.combine(a1, a2)

Combine to argument into a single flat list

It is used when you are not sure whether arguments are lists but want to combine them into one flat list

Parameters:
  • a1 – list or other thing
  • a2 – list or other thing
Returns:

a flat list contain a1 and a2

Return type:

list

launchdman.__init__.combinteDict(d, d1)

Combine two dict into one

Example:

>>> combinteDict({'1': 1}, {'2': 2})
>>> {'1': 1, '2': 2}
Parameters:
  • d (dict) – A dict to combine with
  • d1 (dict) – A dict to combine with
Returns:

the combined dict

Return type:

dict

launchdman.__init__.crossCombine(l)

Taken a list of lists, returns a big list of lists contain all the possibilities of elements of sublist combining together.

It is basically a Combinatorics of list. For example:

>>> crossCombine([[a,a1,a2,...], [b,b1,b2,...]])
>>> [[a,b], [a,b1], [a,b2], [a1,b], [a1,b1], [a1, b2], [a2,b], [a2,b1], [a2,b2], ...]
For using in StartCalendarInterval, the syntax of l is like below:
l: [[dic of month], [dict of day]]
such as:
l: [[{'month': 1}, {'month': 2}], [{'day': 2}, {'day': 3}, {'day': 4}]]
Parameters:l (list[list]) – the list of lists you want to crossCombine with.
Returns:crossCombined list
Return type:list
launchdman.__init__.flatten(l)

Flatten a multi-deminision list and return a iterable

Note that dict and str will not be expanded, instead, they will be kept as a single element.

Parameters:l (list) – The list needs to be flattened
Returns:A iterable of flattened list. To have a list instead use list(flatten(l))
launchdman.__init__.indent(text, amount, ch=' ')

take test and indent every line by amount characters

Parameters:
  • text (str) – The test to be indented
  • amount (int) – The amount of indentation
  • ch (str) – Default to be a space(‘ ‘). This is what to use when indenting the text.

Example:

>>> indent('Mary had a little lamb', 4, '$')
>>> '$$$$Mary had a little lamb'
Returns:The indented text
Return type:str
launchdman.__init__.removeEverything(toBeRemoved, l)

Remove every instance that matches the input from a list

Match with ==, operation, which can be defined in __eq__.

Parameters:
  • tobeRemoved (object) – the same object you want to remove from the list.
  • l (list) – the llist you want to remove stuff from.
launchdman.__init__.singleOrPair(obj)

Chech an object is single or pair or neither.

Of course,, all pairs are single, so what the function is really detecting is whether an object is only single or at the same time a pair.

Parameters:obj (object) – Literally anything.
Returns:‘Single’, or ‘Pair’, or ‘Neither’
Return type:str