Skip to content
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

Bug fix 12 #15

Merged
merged 16 commits into from
Sep 26, 2021
42 changes: 34 additions & 8 deletions src/packages/buskill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
::

File: buskill.py
Authors: Michael Altfield <michael@buskill.in>
Authors: Michael Altfield <michael@buskill.in>, Steven Johnson <steven.j2019@protonmail.com>
Created: 2020-06-23
Updated: 2020-08-09
Updated: 2020-10-14
Version: 0.2

This is the heart of the buskill app, shared by both the cli and gui
Expand All @@ -19,8 +19,10 @@

import platform, multiprocessing, traceback, subprocess
import urllib.request, re, json, certifi, sys, os, math, shutil, tempfile, random, gnupg
import os.path
from buskill_version import BUSKILL_VERSION
from hashlib import sha256
from ConfigParser import SafeConfigParser()

import logging
logger = logging.getLogger( __name__ )
Expand Down Expand Up @@ -199,6 +201,7 @@ def __init__(self):

# instantiate instance fields
self.CURRENT_PLATFORM = None
self.KERNEL_VERSION = None
self.IS_PLATFORM_SUPPORTED = False
self.OS_NAME_SHORT = None
self.ERR_PLATFORM_NOT_SUPPORTED = None
Expand All @@ -224,6 +227,25 @@ def __init__(self):
self.CURRENT_PLATFORM = platform.system().upper()
self.ERR_PLATFORM_NOT_SUPPORTED = 'ERROR: Your platform (' +str(platform.system())+ ') is not supported. If you believe this is an error, please file a bug report:\n\nhttps://github.com/BusKill/buskill-app/issues'

config = SafeConfigParser()

self.CONFIG = None

# NOTE self.config will change to a dictionary if the file is found
# if not a startup routine should begin
# Dictionary keys will be the setting and the value the variable
# i.e. Trigger would be the key, the trigger file location would be the value

if os.file.exists(APP_DIR, 'buskill.conf'):
self.CONFIG = dict()
config.read('buskill.conf')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be os.path( APP_DIR, 'buskill.conf' )?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Matthew,
apologies I forgot I worked on this while waiting for a VM to come up.

The code is inactive I can amend this and re push code up.

actual feature progress is in work on a different branch on my fork

and yes the line should be if os.file.exists(os.path(APP_DIR, 'buskill.conf'))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I was referring to the config.read() line -- shouldn't that be config.read( os.path(APP_DIR,'buskill.conf') )?

for name, value in config.options():
self.config[name] == value
else:
do_something = None
# NOTE This a placeholder!!!!
# Here there should be a setup wizard which will create the config file (TODO Make the function to create Config files)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this suggest that currently the config file is not created if it doesn't yet exist?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a placeholder for now.

On local this has been actually implemented. will be pushed after testing

#
# NOTE about instance fields used for storing path info relative to the
# buskill executable:
#
Expand Down Expand Up @@ -277,6 +299,7 @@ def __init__(self):
if CURRENT_PLATFORM.startswith( 'DARWIN' ):
self.IS_PLATFORM_SUPPORTED = True
self.OS_NAME_SHORT = 'mac'
self.KERNEL_VERSION = str(platform.release()).split('.')[0]
self.ARM_FUNCTION = self.armNix
self.TRIGGER_FUNCTION = self.triggerMac

Expand Down Expand Up @@ -600,15 +623,18 @@ def triggerWin(self):

windll.user32.LockWorkStation()

#TODO test on other mac kernel version for sierra - big sur
def triggerMac(self):
msg = "DEBUG: BusKill lockscreen trigger executing now"
print( msg ); logger.info( msg )

try:
subprocess.run( ['pmset', 'displaysleepnow'] )
except FileNotFoundError as e:
subprocess.run( ['/System/Library/CoreServices/Menu Extras/user.menu/Contents/Resources/CGSession', '-suspend'] )

if self.KERNEL_VERSION.startswith('17') or self.KERNEL_VERSION.startswith('19'): # High Sierra or Catalina
subprocess.run(['/System/Library/CoreServices/Menu Extras/user.menu/Contents/Resources/CGSession', '-suspend'])
#elif self.KERNEL_VERSION.startswith('18'): # Mojave
# Find which command works
else:
msg = "ERROR: Mac Kernel" + self.KERNEL_VERSION + "Unsupported"
print( msg ); logger.error(msg)
# subprocess.run( ['pmset', 'displaysleepnow'] )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, when does the pmset command work? Wouldn't it be better to just try a bunch of commands as fall-back instead of giving-up before trying?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pmset command had the same issue which linked to the bug on my machines on the other version of macOS.

#####################
# UPGRADE FUNCTIONS #
#####################
Expand Down