Jason R. Coombs avatar Jason R. Coombs committed 0ac77c7

Use no_sleep context from jaraco.windows

Comments (0)

Files changed (2)

jaraco/media/handbrake.py

 import datetime
 import threading
 import importlib
-import platform
-import contextlib
-import ctypes
 
 from jaraco.util import ui
 from path import path
 from jaraco.util.string import local_format as lf
+try:
+	from jaraco.windows.power import no_sleep
+except ImportError:
+	from jaraco.util.context import null_context as no_sleep
 
 from . import dvd
 from . import config
 		title_no += 1
 		episode += 1
 
-@contextlib.contextmanager
-def no_sleep():
-	"""
-	Context that prevents the computer from going to sleep on Windows. On
-	other platforms, is a null context.
-	"""
-	if not platform.system() == 'Windows':
-		yield
-		return
-	try:
-		ES_CONTINUOUS = 0x80000000
-		ES_AWAYMODE_REQUIRED = 0x40
-		ES_SYSTEM_REQUIRED = 0x2
-		ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS |
-			ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED)
-		yield
-	finally:
-		ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS)
-
 def quick_brake():
 	name = dvd.infer_name()
 	title = raw_input(lf("Movie title ({name})> ")) or name
 """
 
 import sys
+import platform
+import collections
 
 import setuptools
 
 name = 'jaraco.media'
 
 py26reqs = ['jaraco.compat'] if sys.version_info < (2, 7) else []
+platform_reqs = collections.defaultdict(list,
+	Windows = ['jaraco.windows>=2.13']
+)[platform.system()]
 
 setup_params = dict(
 	name = name,
 	description = 'DVD and other multimedia tools',
 	author = 'Jason R. Coombs',
 	author_email = 'jaraco@jaraco.com',
-	url = 'http://bitbucket.org/' + name,
+	url = 'http://bitbucket.org/jaraco/' + name,
 	packages = setuptools.find_packages(),
 	namespace_packages = ['jaraco'],
 	license = 'MIT',
 			],
 	},
 	install_requires=[
-		'jaraco.util',
+		'jaraco.util>=6.1',
 		'httpagentparser',
-	] + py26reqs,
+	] + py26reqs + platform_reqs,
 	extras_require = {
 	},
 	dependency_links = [
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.