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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mac-agents-2018.12.26.tar.gz.
File metadata
- Download URL: mac-agents-2018.12.26.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c318f4a2623f34730bad6f153a6a2c4cc7c862637130e3f66c352a5b1b0cf385
|
|
| MD5 |
532550dc092ba43908838cc36ce8f490
|
|
| BLAKE2b-256 |
63140fb664431522c19adb48f61c9831c0d948a7646c401a45b31ce23141479d
|
File details
Details for the file mac_agents-2018.12.26-py2.py3-none-any.whl.
File metadata
- Download URL: mac_agents-2018.12.26-py2.py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77bf3748e4e3e33420722ed062ab6858b4eb420f75f88720beccd1c241b8eb7c
|
|
| MD5 |
95ce6e8408599a5e42014f0319f2c5c5
|
|
| BLAKE2b-256 |
96afb82d2d3c37788e65d2d30606d2cb6469f6f34e138b60b9664ed8f4b79c36
|