Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions auto-selfcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def check_if_running(api, config):
if api is Api.V2:
username = config["username"]
defaults = get_selfcontrol_settings(username)
return defaults.has_key("BlockStartedDate") and not NSDate.distantFuture().isEqualToDate_(defaults["BlockStartedDate"])
return "BlockStartedDate" in defaults and not NSDate.distantFuture().isEqualToDate_(defaults["BlockStartedDate"])
elif api is Api.V3:
output = execSelfControl(config, ["--is-running"])
m = re.search(
Expand Down Expand Up @@ -340,23 +340,23 @@ def install(config, settings_dir):

def check_config(config):
""" checks whether the config file is correct """
if not config.has_key("username"):
if "username" not in config:
exit_with_error("No username specified in config.")
if config["username"] not in get_osx_usernames():
if config["username"] not in os.getlogin():
exit_with_error(
"Username '{username}' unknown.\nPlease use your OSX username instead.\n"
"If you have trouble finding it, just enter the command 'whoami'\n"
"in your terminal.".format(
username=config["username"]))
if not config.has_key("selfcontrol-path"):
if "selfcontrol-path" not in config:
exit_with_error(
"The setting 'selfcontrol-path' is required and must point to the location of SelfControl.")
if not os.path.exists(config["selfcontrol-path"]):
exit_with_error(
"The setting 'selfcontrol-path' does not point to the correct location of SelfControl. "
"Please make sure to use an absolute path and include the '.app' extension, "
"e.g. /Applications/SelfControl.app")
if not config.has_key("block-schedules"):
if "block-schedules" not in config:
exit_with_error("The setting 'block-schedules' is required.")
if len(config["block-schedules"]) == 0:
exit_with_error("You need at least one schedule in 'block-schedules'.")
Expand All @@ -378,11 +378,6 @@ def update_blocklist(blocklist_path, config, schedule):
plistlib.writePlist(plist, fp)


def get_osx_usernames():
output = subprocess.check_output(["dscl", ".", "list", "/users"])
return [s.strip() for s in output.splitlines()]


def excepthook(excType, excValue, tb):
""" This function is called whenever an exception is not caught. """
err = "Uncaught exception:\n{}\n{}\n{}".format(str(excType), excValue,
Expand Down