aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/appnope/py2
diff options
context:
space:
mode:
authornkozlovskiy <nmk@ydb.tech>2023-09-29 12:24:06 +0300
committernkozlovskiy <nmk@ydb.tech>2023-09-29 12:41:34 +0300
commite0e3e1717e3d33762ce61950504f9637a6e669ed (patch)
treebca3ff6939b10ed60c3d5c12439963a1146b9711 /contrib/python/appnope/py2
parent38f2c5852db84c7b4d83adfcb009eb61541d1ccd (diff)
downloadydb-e0e3e1717e3d33762ce61950504f9637a6e669ed.tar.gz
add ydb deps
Diffstat (limited to 'contrib/python/appnope/py2')
-rw-r--r--contrib/python/appnope/py2/.dist-info/METADATA52
-rw-r--r--contrib/python/appnope/py2/.dist-info/top_level.txt1
-rw-r--r--contrib/python/appnope/py2/LICENSE22
-rw-r--r--contrib/python/appnope/py2/README.md30
-rw-r--r--contrib/python/appnope/py2/appnope/__init__.py13
-rw-r--r--contrib/python/appnope/py2/appnope/_dummy.py30
-rw-r--r--contrib/python/appnope/py2/appnope/_nope.py134
-rw-r--r--contrib/python/appnope/py2/ya.make24
8 files changed, 306 insertions, 0 deletions
diff --git a/contrib/python/appnope/py2/.dist-info/METADATA b/contrib/python/appnope/py2/.dist-info/METADATA
new file mode 100644
index 0000000000..9c7b757060
--- /dev/null
+++ b/contrib/python/appnope/py2/.dist-info/METADATA
@@ -0,0 +1,52 @@
+Metadata-Version: 2.1
+Name: appnope
+Version: 0.1.3
+Summary: Disable App Nap on macOS >= 10.9
+Home-page: http://github.com/minrk/appnope
+Author: Min Ragan-Kelley
+Author-email: benjaminrk@gmail.com
+License: BSD
+Platform: UNKNOWN
+Classifier: License :: OSI Approved :: BSD License
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.2
+Classifier: Programming Language :: Python :: 3.3
+Description-Content-Type: text/markdown
+License-File: LICENSE
+
+# `appnope`
+
+Simple package for disabling App Nap on macOS >= 10.9,
+which can be problematic.
+
+To disable App Nap:
+
+```python
+import appnope
+appnope.nope()
+```
+
+To reenable, for some reason:
+
+```python
+appnope.nap()
+```
+
+or to only disable App Nap for a particular block:
+
+```
+with appnope.nope_scope():
+ do_important_stuff()
+```
+
+It uses ctypes to wrap a `[NSProcessInfo beginActivityWithOptions]` call to disable App Nap.
+
+To install:
+
+ pip install appnope
+
+
diff --git a/contrib/python/appnope/py2/.dist-info/top_level.txt b/contrib/python/appnope/py2/.dist-info/top_level.txt
new file mode 100644
index 0000000000..010137fae0
--- /dev/null
+++ b/contrib/python/appnope/py2/.dist-info/top_level.txt
@@ -0,0 +1 @@
+appnope
diff --git a/contrib/python/appnope/py2/LICENSE b/contrib/python/appnope/py2/LICENSE
new file mode 100644
index 0000000000..ad412c036f
--- /dev/null
+++ b/contrib/python/appnope/py2/LICENSE
@@ -0,0 +1,22 @@
+this project is licensed under 2-clause BSD
+
+Copyright (c) 2013, Min Ragan-Kelley
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/contrib/python/appnope/py2/README.md b/contrib/python/appnope/py2/README.md
new file mode 100644
index 0000000000..151250c3d3
--- /dev/null
+++ b/contrib/python/appnope/py2/README.md
@@ -0,0 +1,30 @@
+# `appnope`
+
+Simple package for disabling App Nap on macOS >= 10.9,
+which can be problematic.
+
+To disable App Nap:
+
+```python
+import appnope
+appnope.nope()
+```
+
+To reenable, for some reason:
+
+```python
+appnope.nap()
+```
+
+or to only disable App Nap for a particular block:
+
+```
+with appnope.nope_scope():
+ do_important_stuff()
+```
+
+It uses ctypes to wrap a `[NSProcessInfo beginActivityWithOptions]` call to disable App Nap.
+
+To install:
+
+ pip install appnope
diff --git a/contrib/python/appnope/py2/appnope/__init__.py b/contrib/python/appnope/py2/appnope/__init__.py
new file mode 100644
index 0000000000..bcf87f4917
--- /dev/null
+++ b/contrib/python/appnope/py2/appnope/__init__.py
@@ -0,0 +1,13 @@
+__version__ = '0.1.3'
+
+import re
+import sys
+import platform
+
+def _v(version_s):
+ return tuple(int(s) for s in re.findall("\d+", version_s))
+
+if sys.platform != "darwin" or _v(platform.mac_ver()[0]) < _v("10.9"):
+ from ._dummy import *
+else:
+ from ._nope import *
diff --git a/contrib/python/appnope/py2/appnope/_dummy.py b/contrib/python/appnope/py2/appnope/_dummy.py
new file mode 100644
index 0000000000..a55ec5bfcd
--- /dev/null
+++ b/contrib/python/appnope/py2/appnope/_dummy.py
@@ -0,0 +1,30 @@
+#-----------------------------------------------------------------------------
+# Copyright (C) 2013 Min RK
+#
+# Distributed under the terms of the 2-clause BSD License.
+#-----------------------------------------------------------------------------
+
+from contextlib import contextmanager
+
+def beginActivityWithOptions(options, reason=""):
+ return
+
+def endActivity(activity):
+ return
+
+def nope():
+ return
+
+def nap():
+ return
+
+
+@contextmanager
+def nope_scope(
+ options=0,
+ reason="Because Reasons"
+ ):
+ yield
+
+def napping_allowed():
+ return True \ No newline at end of file
diff --git a/contrib/python/appnope/py2/appnope/_nope.py b/contrib/python/appnope/py2/appnope/_nope.py
new file mode 100644
index 0000000000..d83e826797
--- /dev/null
+++ b/contrib/python/appnope/py2/appnope/_nope.py
@@ -0,0 +1,134 @@
+#-----------------------------------------------------------------------------
+# Copyright (C) 2013 Min RK
+#
+# Distributed under the terms of the 2-clause BSD License.
+#-----------------------------------------------------------------------------
+
+from contextlib import contextmanager
+
+import ctypes
+import ctypes.util
+
+objc = ctypes.cdll.LoadLibrary(ctypes.util.find_library('objc'))
+_ = ctypes.cdll.LoadLibrary(ctypes.util.find_library('Foundation'))
+
+void_p = ctypes.c_void_p
+ull = ctypes.c_uint64
+
+objc.objc_getClass.restype = void_p
+objc.sel_registerName.restype = void_p
+objc.objc_msgSend.restype = void_p
+objc.objc_msgSend.argtypes = [void_p, void_p]
+
+msg = objc.objc_msgSend
+
+def _utf8(s):
+ """ensure utf8 bytes"""
+ if not isinstance(s, bytes):
+ s = s.encode('utf8')
+ return s
+
+def n(name):
+ """create a selector name (for methods)"""
+ return objc.sel_registerName(_utf8(name))
+
+def C(classname):
+ """get an ObjC Class by name"""
+ ret = objc.objc_getClass(_utf8(classname))
+ assert ret is not None, "Couldn't find Class %s" % classname
+ return ret
+
+# constants from Foundation
+
+NSActivityIdleDisplaySleepDisabled = (1 << 40)
+NSActivityIdleSystemSleepDisabled = (1 << 20)
+NSActivitySuddenTerminationDisabled = (1 << 14)
+NSActivityAutomaticTerminationDisabled = (1 << 15)
+NSActivityUserInitiated = (0x00FFFFFF | NSActivityIdleSystemSleepDisabled)
+NSActivityUserInitiatedAllowingIdleSystemSleep = (NSActivityUserInitiated & ~NSActivityIdleSystemSleepDisabled)
+NSActivityBackground = 0x000000FF
+NSActivityLatencyCritical = 0xFF00000000
+
+def beginActivityWithOptions(options, reason=""):
+ """Wrapper for:
+
+ [ [ NSProcessInfo processInfo]
+ beginActivityWithOptions: (uint64)options
+ reason: (str)reason
+ ]
+ """
+ NSProcessInfo = C('NSProcessInfo')
+ NSString = C('NSString')
+
+ objc.objc_msgSend.argtypes = [void_p, void_p, void_p]
+ reason = msg(NSString, n("stringWithUTF8String:"), _utf8(reason))
+ objc.objc_msgSend.argtypes = [void_p, void_p]
+ info = msg(NSProcessInfo, n('processInfo'))
+ objc.objc_msgSend.argtypes = [void_p, void_p, ull, void_p]
+ activity = msg(info,
+ n('beginActivityWithOptions:reason:'),
+ ull(options),
+ void_p(reason)
+ )
+ return activity
+
+def endActivity(activity):
+ """end a process activity assertion"""
+ NSProcessInfo = C('NSProcessInfo')
+ objc.objc_msgSend.argtypes = [void_p, void_p]
+ info = msg(NSProcessInfo, n('processInfo'))
+ objc.objc_msgSend.argtypes = [void_p, void_p, void_p]
+ msg(info, n("endActivity:"), void_p(activity))
+
+_theactivity = None
+
+def nope():
+ """disable App Nap by setting NSActivityUserInitiatedAllowingIdleSystemSleep"""
+ global _theactivity
+ _theactivity = beginActivityWithOptions(
+ NSActivityUserInitiatedAllowingIdleSystemSleep,
+ "Because Reasons"
+ )
+
+def nap():
+ """end the caffeinated state started by `nope`"""
+ global _theactivity
+ if _theactivity is not None:
+ endActivity(_theactivity)
+ _theactivity = None
+
+def napping_allowed():
+ """is napping allowed?"""
+ return _theactivity is None
+
+@contextmanager
+def nope_scope(
+ options=NSActivityUserInitiatedAllowingIdleSystemSleep,
+ reason="Because Reasons"
+ ):
+ """context manager for beginActivityWithOptions.
+
+ Within this context, App Nap will be disabled.
+ """
+ activity = beginActivityWithOptions(options, reason)
+ try:
+ yield
+ finally:
+ endActivity(activity)
+
+__all__ = [
+ "NSActivityIdleDisplaySleepDisabled",
+ "NSActivityIdleSystemSleepDisabled",
+ "NSActivitySuddenTerminationDisabled",
+ "NSActivityAutomaticTerminationDisabled",
+ "NSActivityUserInitiated",
+ "NSActivityUserInitiatedAllowingIdleSystemSleep",
+ "NSActivityBackground",
+ "NSActivityLatencyCritical",
+ "beginActivityWithOptions",
+ "endActivity",
+ "nope",
+ "nap",
+ "napping_allowed",
+ "nope_scope",
+]
diff --git a/contrib/python/appnope/py2/ya.make b/contrib/python/appnope/py2/ya.make
new file mode 100644
index 0000000000..3cd0afec9c
--- /dev/null
+++ b/contrib/python/appnope/py2/ya.make
@@ -0,0 +1,24 @@
+# Generated by devtools/yamaker (pypi).
+
+PY2_LIBRARY()
+
+VERSION(0.1.3)
+
+LICENSE(BSD-2-Clause)
+
+NO_LINT()
+
+PY_SRCS(
+ TOP_LEVEL
+ appnope/__init__.py
+ appnope/_dummy.py
+ appnope/_nope.py
+)
+
+RESOURCE_FILES(
+ PREFIX contrib/python/appnope/py2/
+ .dist-info/METADATA
+ .dist-info/top_level.txt
+)
+
+END()