-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Add subcommand to install LaunchAgents wrapper for watch #890
Draft
glensc
wants to merge
16
commits into
Taxel:main
Choose a base branch
from
glensc:launchctl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
039dda0
Add plist for watch command
glensc 47170c4
Add launchctl command
glensc bdaeb5f
Register launchctl command
glensc 717c112
Add load/unload subcommands
glensc cfd830c
Add module_path export
glensc f291095
Add Plist helper class
glensc 5889ef1
Create/Remove plist file
glensc 2a31288
Add load/unload methods
glensc 39bf9aa
Add load/unload callouts
glensc f5aa9c8
Check for existence
glensc be55e6b
Add stdout/stderr debuging
glensc a73b053
Add program_path helper
glensc 509d029
Use absolute path to the program
glensc 9b0550a
Use python -m for execution
glensc b0b7a36
Encode each argument as <string>
glensc cd91efd
Add WorkingDirectory as a reference
glensc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Label</key> | ||
<string>com.github.plextraktsync.watch</string> | ||
<key>ProgramArguments</key> | ||
<array> | ||
<string>plextraktsync</string> | ||
<string>watch</string> | ||
</array> | ||
<key>WorkingDirectory</key> | ||
<string>/</string> | ||
<key>LimitLoadToSessionType</key> | ||
<string>Aqua</string> | ||
<key>RunAtLoad</key> | ||
<true/> | ||
<key>ExitTimeOut</key> | ||
<integer>0</integer> | ||
<key>ProcessType</key> | ||
<string>Background</string> | ||
|
||
<!-- | ||
Enable to see debug logs. | ||
- https://stackoverflow.com/a/29926482/2314626 | ||
--> | ||
<key>StandardErrorPath</key> | ||
<string>/tmp/plextraktsync.err</string> | ||
<key>StandardOutPath</key> | ||
<string>/tmp/plextraktsync.out</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import click | ||
|
||
from plextraktsync.decorators.cached_property import cached_property | ||
|
||
|
||
class Plist: | ||
plist_file = "com.github.plextraktsync.watch.plist" | ||
|
||
def load(self, plist_path: str): | ||
from os import system | ||
|
||
system(f"launchctl load {plist_path}") | ||
|
||
def unload(self, plist_path: str): | ||
from os import system | ||
from os.path import exists | ||
|
||
# Skip if file does not exist. | ||
if not exists(plist_path): | ||
return | ||
system(f"launchctl unload {plist_path}") | ||
|
||
def create(self, plist_path: str): | ||
from plextraktsync.util.packaging import program_path | ||
|
||
with open(self.plist_default_path, encoding='utf-8') as f: | ||
contents = "".join(f.readlines()) | ||
|
||
def encode(f): | ||
return f'<string>{f}</string>' | ||
|
||
program = "\n".join(map(encode, program_path().split(' '))) | ||
contents = contents.replace('<string>plextraktsync</string>', program) | ||
with open(plist_path, "w+") as fw: | ||
fw.writelines(contents) | ||
|
||
def remove(self, plist_path: str): | ||
from os import unlink | ||
from os.path import exists | ||
|
||
# Skip if file does not exist. | ||
if not exists(plist_path): | ||
return | ||
unlink(plist_path) | ||
|
||
@cached_property | ||
def plist_default_path(self): | ||
from os.path import join | ||
|
||
from plextraktsync.path import module_path | ||
|
||
return join(module_path, self.plist_file) | ||
|
||
@cached_property | ||
def plist_path(self): | ||
from os.path import expanduser | ||
|
||
return expanduser(f'~/Library/LaunchAgents/{self.plist_file}') | ||
|
||
|
||
@click.command() | ||
def load(): | ||
""" | ||
Load the service. | ||
""" | ||
p = Plist() | ||
p.create(p.plist_path) | ||
click.echo(f"Created: {p.plist_path}") | ||
p.load(p.plist_path) | ||
click.echo(f"Loaded: {p.plist_path}") | ||
|
||
|
||
@click.command() | ||
def unload(): | ||
""" | ||
Unload the service. | ||
""" | ||
p = Plist() | ||
p.unload(p.plist_path) | ||
click.echo(f"Unloaded: {p.plist_path}") | ||
p.remove(p.plist_path) | ||
click.echo(f"Removed: {p.plist_path}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why Aqua?
from this link
Background
seems more appropriate?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I used aqua based on a old example. You are right that
Background
might be better.Setting a
nice
level might be a good idea though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Send an example for nice level. perhaps using suggest code change feature:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bas-Man I can't see the suggestion on the web, but had a glimpse of it in the email. Did you delete it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bas-Man please reply in the thread where the question was asked.
But, I don't see your changes, perhaps you forgot to publish review?