Skip to content

Commit

Permalink
Fix Wakelock on Mac, better Munging Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalanyr committed Mar 12, 2020
1 parent 6abd6b0 commit 2e1b3d4
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions gogrepoc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
Expand Down Expand Up @@ -343,7 +342,8 @@ def myreplacementclose(m):
else:
return m.group(0)

if compiledregexmungeopen.search(ad):
mungeDetected = compiledregexmungeopen.search(ad)
if mungeDetected:
info("detected AttrDict error in manifest")
ad = compiledregexmungeopen.sub("{",ad)
ad = compiledregexmungeclose.sub("}",ad)
Expand All @@ -354,6 +354,9 @@ def myreplacementclose(m):

if (sys.version_info[0] >= 3):
ad = re.sub(r"'size': ([0-9]+)L,",r"'size': \1,",ad)
db = eval(ad)
if (mungeDetected):
save_manifest(db)
return eval(ad)
except IOError:
return []
Expand Down Expand Up @@ -1008,7 +1011,6 @@ def process_argv(argv):

return args


# --------
# Commands
# --------
Expand Down Expand Up @@ -1202,6 +1204,8 @@ def cmd_update(os_list, lang_list, skipknown, updateonly, partial, ids, skipids,
else:
info('fetching game product data (page %d / %d)...' % (i, json_data['totalPages']))
data_response = request(updateSession,api_url,args={'mediaType': media_type,'sortBy': 'title','page': str(i)})
# with open("text.html","w+",encoding='utf-8') as f:
# f.write(data_response.text)
try:
json_data = data_response.json()
except ValueError:
Expand Down Expand Up @@ -1749,9 +1753,9 @@ def ioloop(tid, path, response, out):
responseTimer = threading.Timer(HTTP_TIMEOUT,killresponse,[response])
responseTimer.start()
except (requests.exceptions.ConnectionError,requests.packages.urllib3.exceptions.ProtocolError) as e:
error("server response issue while downloading content for %s" % (path))
error("server response issue while downloading content for %s" % (path))
except (OpenSSL.SSL.Error) as e:
error("SSL issue while downloading content for %s" % (path))
error("SSL issue while downloading content for %s" % (path))
responseTimer.cancel()
#info("Exiting I/O Loop - " + path)
return dlsz
Expand Down Expand Up @@ -2486,7 +2490,6 @@ def update_self():
with open_notrunc('rolling.tar.gz') as w:
w.write(rawResponse)


def main(args):
stime = datetime.datetime.now()

Expand Down Expand Up @@ -2627,6 +2630,7 @@ def __init__(self):
self._PMassertion = None
self._PMassertID = ctypes.c_uint32(0)
self._PMerrcode = None
self._IOPMAssertionRelease = self.libIOKit.IOPMAssertionRelease


def _CFSTR(self,py_string):
Expand All @@ -2639,7 +2643,7 @@ def _IOPMAssertionCreateWithName(self,assert_name, assert_level, assert_msg):
assertID = ctypes.c_uint32(0)
p_assert_name = self.raw_ptr(self._CFSTR(assert_name))
p_assert_msg = self.raw_ptr(self._CFSTR(assert_msg))
errcode = libIOKit.IOPMAssertionCreateWithName(p_assert_name,
errcode = self.libIOKit.IOPMAssertionCreateWithName(p_assert_name,
assert_level, p_assert_msg, ctypes.byref(assertID))
return (errcode, assertID)

Expand Down Expand Up @@ -2676,10 +2680,11 @@ def take_wakelock(self):
ctypes.windll.kernel32.SetThreadExecutionState(self.ES_WAKELOCK)
if platform.system() == "Darwin":
a = self.PM_WAKELOCK
if a != self._PMassertion:
self.releaseWakelock()
if self._assertID.value ==0:
if self._PMassertion is not None and a != self._PMassertion:
self.release_wakelock()
if self._PMassertID.value ==0:
self._PMerrcode, self._PMassertID = self._IOPMAssertionCreateWithName(a,self._kIOPMAssertionLevelOn,"gogrepoc")
self._PMassertion = a
if (not (platform.system() == "Windows" or platform.system() == "Darwin")) and ('PyQt5.QtDBus' in sys.modules):
self.inhibitor = self._get_inhibitor()
self.inhibitor.inhibit()
Expand All @@ -2688,8 +2693,9 @@ def release_wakelock(self):
if platform.system() == "Windows":
ctypes.windll.kernel32.SetThreadExecutionState(self.ES_CONTINUOUS)
if platform.system() == "Darwin":
self._PMerrcode = self._IOPMAssertionRelease(self._assertID)
self._PMerrcode = self._IOPMAssertionRelease(self._PMassertID)
self._PMassertID.value = 0
self._PMassertion = None

class DBusSystemInhibitor:

Expand Down

0 comments on commit 2e1b3d4

Please sign in to comment.