LaunchAgents + python
Project description
Install
$ [sudo] pip install mac-agents
Classes
mac_agents.Agent
- launchd.plist generator. Capital letter attrs/props as launchd.plist keys
method | __doc__ |
---|---|
create() |
create launchd.plist file and StandardOutPath , StandardErrorPath logs |
load() |
launchctl load plist file |
read() |
return a dictionary with plist file data |
rm() |
remove plist file (if exist) |
unload() |
launchctl unload plist file |
update(**kwargs) |
update plist file data |
write(data) |
write a dictionary to a plist file |
@property | __doc__ |
---|---|
Label |
path.to.file.py |
ProgramArguments |
['bash','-l','-c','python $script $plist'] |
StandardErrorPath |
~/Library/Logs/LaunchAgents/$Label/err.log |
StandardOutPath |
~/Library/Logs/LaunchAgents/$Label/out.log |
WorkingDirectory |
script file dirname |
path |
plist path - file.py.plist |
script |
script path - class module file |
mac_agents.db.Agent
- LaunchAgent class. fields: path
, Label
method | __doc__ |
---|---|
load() |
launchctl load plist |
lock(key) |
add Lock object for this agent |
unload() |
launchctl unload plist |
unlock(key) |
remove Lock object for this agent |
mac_agents.db.Lock
- LaunchAgent Lock class. fields: agent
(ForeignKey), key
, created_at
updated_at
Functions
function | __doc__ |
---|---|
mac_agents.create(path) |
create launchd.plist from python file and return plist path |
mac_agents.jobs() |
return list of launchctl Job objects (pid , status , label ) |
mac_agents.read(path) |
return a dictionary with plist file data |
mac_agents.tag(path='~/Library/LaunchAgents') |
set Finder tags. red - status, orange - stderr, gray - unloaded |
mac_agents.update(path, **kwargs) |
update plist file data |
mac_agents.write(path, data) |
write data dictionary to a plist file |
mac_agents.db.init(path='~/Library/LaunchAgents') |
create db.Agent objects |
CLI
usage | __doc__ |
---|---|
python -m mac_agents.create path ... |
generate launchd.plist from python file(s) |
python -m mac_agents.tag [path] |
set Finder tags. red - status, orange - stderr, gray - unloaded |
Examples
~/Library/LaunchAgents/file.py
import mac_agents
class Agent(mac_agents.Agent):
StartInterval = 5 # capital letter
def run(self):
pass
if __name__ == "__main__":
Agent().run()
$ find ~/Library/LaunchAgents -name "*.py" | xargs python -m mac_agents.create "$@"
$ find ~/Library/LaunchAgents -name "*.plist" | xargs launchctl load # or launchctl unload
$ launchctl list | grep .py$ | awk '{print $3}' | xargs -I '{}' launchctl remove {}
$ find ~/Library/LaunchAgents -name "*.py.plist" -exec rm {} +
django models
site-packages/mac_agents_settings.py
required
import os
SECRET_KEY = "I_LOVE_CATS"
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mac-agents',
'USER': os.environ["USER"],
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '5432',
}
}
$ bash -l django-project/create.sh # create tables. look at django-project/ in github repo
>>> import mac_agents.db
>>> mac_agents.db.init() # create db.Agent objects
>>> mac_agents.db.Agent.objects.all()
Links
readme-md - README.md generator
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mac-agents-2018.12.26.tar.gz
(5.6 kB
view hashes)
Built Distribution
Close
Hashes for mac_agents-2018.12.26-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77bf3748e4e3e33420722ed062ab6858b4eb420f75f88720beccd1c241b8eb7c |
|
MD5 | 95ce6e8408599a5e42014f0319f2c5c5 |
|
BLAKE2b-256 | 96afb82d2d3c37788e65d2d30606d2cb6469f6f34e138b60b9664ed8f4b79c36 |