Skip to content

Commit 2e1b3d4

Browse files
committed
Fix Wakelock on Mac, better Munging Fix
1 parent 6abd6b0 commit 2e1b3d4

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

gogrepoc.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# -*- coding: utf-8 -*-
32

43
from __future__ import print_function
@@ -343,7 +342,8 @@ def myreplacementclose(m):
343342
else:
344343
return m.group(0)
345344

346-
if compiledregexmungeopen.search(ad):
345+
mungeDetected = compiledregexmungeopen.search(ad)
346+
if mungeDetected:
347347
info("detected AttrDict error in manifest")
348348
ad = compiledregexmungeopen.sub("{",ad)
349349
ad = compiledregexmungeclose.sub("}",ad)
@@ -354,6 +354,9 @@ def myreplacementclose(m):
354354

355355
if (sys.version_info[0] >= 3):
356356
ad = re.sub(r"'size': ([0-9]+)L,",r"'size': \1,",ad)
357+
db = eval(ad)
358+
if (mungeDetected):
359+
save_manifest(db)
357360
return eval(ad)
358361
except IOError:
359362
return []
@@ -1008,7 +1011,6 @@ def process_argv(argv):
10081011

10091012
return args
10101013

1011-
10121014
# --------
10131015
# Commands
10141016
# --------
@@ -1202,6 +1204,8 @@ def cmd_update(os_list, lang_list, skipknown, updateonly, partial, ids, skipids,
12021204
else:
12031205
info('fetching game product data (page %d / %d)...' % (i, json_data['totalPages']))
12041206
data_response = request(updateSession,api_url,args={'mediaType': media_type,'sortBy': 'title','page': str(i)})
1207+
# with open("text.html","w+",encoding='utf-8') as f:
1208+
# f.write(data_response.text)
12051209
try:
12061210
json_data = data_response.json()
12071211
except ValueError:
@@ -1749,9 +1753,9 @@ def ioloop(tid, path, response, out):
17491753
responseTimer = threading.Timer(HTTP_TIMEOUT,killresponse,[response])
17501754
responseTimer.start()
17511755
except (requests.exceptions.ConnectionError,requests.packages.urllib3.exceptions.ProtocolError) as e:
1752-
error("server response issue while downloading content for %s" % (path))
1756+
error("server response issue while downloading content for %s" % (path))
17531757
except (OpenSSL.SSL.Error) as e:
1754-
error("SSL issue while downloading content for %s" % (path))
1758+
error("SSL issue while downloading content for %s" % (path))
17551759
responseTimer.cancel()
17561760
#info("Exiting I/O Loop - " + path)
17571761
return dlsz
@@ -2486,7 +2490,6 @@ def update_self():
24862490
with open_notrunc('rolling.tar.gz') as w:
24872491
w.write(rawResponse)
24882492

2489-
24902493
def main(args):
24912494
stime = datetime.datetime.now()
24922495

@@ -2627,6 +2630,7 @@ def __init__(self):
26272630
self._PMassertion = None
26282631
self._PMassertID = ctypes.c_uint32(0)
26292632
self._PMerrcode = None
2633+
self._IOPMAssertionRelease = self.libIOKit.IOPMAssertionRelease
26302634

26312635

26322636
def _CFSTR(self,py_string):
@@ -2639,7 +2643,7 @@ def _IOPMAssertionCreateWithName(self,assert_name, assert_level, assert_msg):
26392643
assertID = ctypes.c_uint32(0)
26402644
p_assert_name = self.raw_ptr(self._CFSTR(assert_name))
26412645
p_assert_msg = self.raw_ptr(self._CFSTR(assert_msg))
2642-
errcode = libIOKit.IOPMAssertionCreateWithName(p_assert_name,
2646+
errcode = self.libIOKit.IOPMAssertionCreateWithName(p_assert_name,
26432647
assert_level, p_assert_msg, ctypes.byref(assertID))
26442648
return (errcode, assertID)
26452649

@@ -2676,10 +2680,11 @@ def take_wakelock(self):
26762680
ctypes.windll.kernel32.SetThreadExecutionState(self.ES_WAKELOCK)
26772681
if platform.system() == "Darwin":
26782682
a = self.PM_WAKELOCK
2679-
if a != self._PMassertion:
2680-
self.releaseWakelock()
2681-
if self._assertID.value ==0:
2683+
if self._PMassertion is not None and a != self._PMassertion:
2684+
self.release_wakelock()
2685+
if self._PMassertID.value ==0:
26822686
self._PMerrcode, self._PMassertID = self._IOPMAssertionCreateWithName(a,self._kIOPMAssertionLevelOn,"gogrepoc")
2687+
self._PMassertion = a
26832688
if (not (platform.system() == "Windows" or platform.system() == "Darwin")) and ('PyQt5.QtDBus' in sys.modules):
26842689
self.inhibitor = self._get_inhibitor()
26852690
self.inhibitor.inhibit()
@@ -2688,8 +2693,9 @@ def release_wakelock(self):
26882693
if platform.system() == "Windows":
26892694
ctypes.windll.kernel32.SetThreadExecutionState(self.ES_CONTINUOUS)
26902695
if platform.system() == "Darwin":
2691-
self._PMerrcode = self._IOPMAssertionRelease(self._assertID)
2696+
self._PMerrcode = self._IOPMAssertionRelease(self._PMassertID)
26922697
self._PMassertID.value = 0
2698+
self._PMassertion = None
26932699

26942700
class DBusSystemInhibitor:
26952701

0 commit comments

Comments
 (0)