[Python-modules-commits] [pyvirtualdisplay] 02/06: Import pyvirtualdisplay_0.2.1.orig.tar.gz

Sandro Tosi morph at moszumanska.debian.org
Wed Dec 14 00:18:22 UTC 2016


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository pyvirtualdisplay.

commit 4e40bbab0f5c225ca25f140dba7be647fccf4d01
Author: Sandro Tosi <morph at debian.org>
Date:   Tue Dec 13 19:13:55 2016 -0500

    Import pyvirtualdisplay_0.2.1.orig.tar.gz
---
 PKG-INFO                              | 11 +++++++-
 PyVirtualDisplay.egg-info/PKG-INFO    | 11 +++++++-
 PyVirtualDisplay.egg-info/SOURCES.txt |  1 +
 README.rst                            |  9 +++++++
 pyvirtualdisplay/about.py             |  2 +-
 pyvirtualdisplay/abstractdisplay.py   | 47 ++++++++++++++++++++++++++++++++---
 pyvirtualdisplay/display.py           |  5 ++--
 pyvirtualdisplay/xauth.py             | 37 +++++++++++++++++++++++++++
 8 files changed, 115 insertions(+), 8 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 035545f..11e0498 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: PyVirtualDisplay
-Version: 0.2
+Version: 0.2.1
 Summary: python wrapper for Xvfb, Xephyr and Xvnc
 Home-page: https://github.com/ponty/pyvirtualdisplay
 Author: ponty
@@ -156,6 +156,15 @@ Description: pyvirtualdisplay is a python wrapper for Xvfb_, Xephyr_ and Xvnc_
                       proc.wait()
           #-#
         
+        xauth
+        =====
+        
+        Some programs require a functional Xauthority file. PyVirtualDisplay can
+        generate one and set the appropriate environment variables if you pass
+        ``use_xauth=True`` to the ``Display`` constructor. Note however that this
+        feature needs ``xauth`` installed, otherwise a
+        ``pyvirtualdisplay.xauth.NotFoundError`` is raised.
+        
         
         .. _setuptools: http://peak.telecommunity.com/DevCenter/EasyInstall
         .. _pip: http://pip.openplans.org/
diff --git a/PyVirtualDisplay.egg-info/PKG-INFO b/PyVirtualDisplay.egg-info/PKG-INFO
index 035545f..11e0498 100644
--- a/PyVirtualDisplay.egg-info/PKG-INFO
+++ b/PyVirtualDisplay.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: PyVirtualDisplay
-Version: 0.2
+Version: 0.2.1
 Summary: python wrapper for Xvfb, Xephyr and Xvnc
 Home-page: https://github.com/ponty/pyvirtualdisplay
 Author: ponty
@@ -156,6 +156,15 @@ Description: pyvirtualdisplay is a python wrapper for Xvfb_, Xephyr_ and Xvnc_
                       proc.wait()
           #-#
         
+        xauth
+        =====
+        
+        Some programs require a functional Xauthority file. PyVirtualDisplay can
+        generate one and set the appropriate environment variables if you pass
+        ``use_xauth=True`` to the ``Display`` constructor. Note however that this
+        feature needs ``xauth`` installed, otherwise a
+        ``pyvirtualdisplay.xauth.NotFoundError`` is raised.
+        
         
         .. _setuptools: http://peak.telecommunity.com/DevCenter/EasyInstall
         .. _pip: http://pip.openplans.org/
diff --git a/PyVirtualDisplay.egg-info/SOURCES.txt b/PyVirtualDisplay.egg-info/SOURCES.txt
index 7d3923b..5b7d403 100644
--- a/PyVirtualDisplay.egg-info/SOURCES.txt
+++ b/PyVirtualDisplay.egg-info/SOURCES.txt
@@ -23,6 +23,7 @@ pyvirtualdisplay/about.py
 pyvirtualdisplay/abstractdisplay.py
 pyvirtualdisplay/display.py
 pyvirtualdisplay/smartdisplay.py
+pyvirtualdisplay/xauth.py
 pyvirtualdisplay/xephyr.py
 pyvirtualdisplay/xvfb.py
 pyvirtualdisplay/xvnc.py
diff --git a/README.rst b/README.rst
index e070815..a0cdaff 100644
--- a/README.rst
+++ b/README.rst
@@ -148,6 +148,15 @@ vncserver
               proc.wait()
   #-#
 
+xauth
+=====
+
+Some programs require a functional Xauthority file. PyVirtualDisplay can
+generate one and set the appropriate environment variables if you pass
+``use_xauth=True`` to the ``Display`` constructor. Note however that this
+feature needs ``xauth`` installed, otherwise a
+``pyvirtualdisplay.xauth.NotFoundError`` is raised.
+
 
 .. _setuptools: http://peak.telecommunity.com/DevCenter/EasyInstall
 .. _pip: http://pip.openplans.org/
diff --git a/pyvirtualdisplay/about.py b/pyvirtualdisplay/about.py
index b650ceb..fc79d63 100644
--- a/pyvirtualdisplay/about.py
+++ b/pyvirtualdisplay/about.py
@@ -1 +1 @@
-__version__ = '0.2'
+__version__ = '0.2.1'
diff --git a/pyvirtualdisplay/abstractdisplay.py b/pyvirtualdisplay/abstractdisplay.py
index 1c91ab8..dfea620 100644
--- a/pyvirtualdisplay/abstractdisplay.py
+++ b/pyvirtualdisplay/abstractdisplay.py
@@ -3,8 +3,11 @@ import fnmatch
 import logging
 import os
 import time
+import tempfile
 from threading import Lock
 
+from pyvirtualdisplay import xauth
+
 mutex = Lock()
 
 log = logging.getLogger(__name__)
@@ -24,15 +27,20 @@ class AbstractDisplay(EasyProcess):
     Common parent for Xvfb and Xephyr
     '''
 
-    def __init__(self):
+    def __init__(self, use_xauth=False):
         mutex.acquire()
-        try:        
+        try:
             self.display = self.search_for_display()
             while self.display in USED_DISPLAY_NR_LIST:
-                self.display+=1            
+                self.display+=1
             USED_DISPLAY_NR_LIST.append(self.display)
         finally:
             mutex.release()
+        if xauth and not xauth.is_installed():
+            raise xauth.NotFoundError()
+        self.use_xauth = use_xauth
+        self._old_xauth = None
+        self._xauth_filename = None
         EasyProcess.__init__(self, self._cmd)
 
     @property
@@ -88,6 +96,8 @@ class AbstractDisplay(EasyProcess):
 
         :rtype: self
         '''
+        if self.use_xauth:
+            self._setup_xauth()
         EasyProcess.start(self)
 
         # https://github.com/ponty/PyVirtualDisplay/issues/2
@@ -108,4 +118,35 @@ class AbstractDisplay(EasyProcess):
         '''
         self.redirect_display(False)
         EasyProcess.stop(self)
+        if self.use_xauth:
+            self._clear_xauth()
         return self
+
+    def _setup_xauth(self):
+        '''
+        Set up the Xauthority file and the XAUTHORITY environment variable.
+        '''
+        handle, filename = tempfile.mkstemp(prefix='PyVirtualDisplay.',
+                                            suffix='.Xauthority')
+        self._xauth_filename = filename
+        os.close(handle)
+        # Save old environment
+        self._old_xauth = {}
+        self._old_xauth['AUTHFILE'] = os.getenv('AUTHFILE')
+        self._old_xauth['XAUTHORITY'] = os.getenv('XAUTHORITY')
+
+        os.environ['AUTHFILE'] = os.environ['XAUTHORITY'] = filename
+        cookie = xauth.generate_mcookie()
+        xauth.call('add', self.new_display_var, '.', cookie)
+
+    def _clear_xauth(self):
+        '''
+        Clear the Xauthority file and restore the environment variables.
+        '''
+        os.remove(self._xauth_filename)
+        for varname in ['AUTHFILE', 'XAUTHORITY']:
+            if self._old_xauth[varname] is None:
+                del os.environ[varname]
+            else:
+                os.environ[varname] = self._old_xauth[varname]
+        self._old_xauth = None
diff --git a/pyvirtualdisplay/display.py b/pyvirtualdisplay/display.py
index 3be910d..a799058 100644
--- a/pyvirtualdisplay/display.py
+++ b/pyvirtualdisplay/display.py
@@ -13,8 +13,9 @@ class Display(AbstractDisplay):
     :param bgcolor: background color ['black' or 'white']
     :param visible: True -> Xephyr, False -> Xvfb
     :param backend: 'xvfb', 'xvnc' or 'xephyr', ignores ``visible``
+    :param xauth: If a Xauthority file should be created.
     '''
-    def __init__(self, backend=None, visible=False, size=(1024, 768), color_depth=24, bgcolor='black', **kwargs):
+    def __init__(self, backend=None, visible=False, size=(1024, 768), color_depth=24, bgcolor='black', use_xauth=False, **kwargs):
         self.color_depth = color_depth
         self.size = size
         self.bgcolor = bgcolor
@@ -35,7 +36,7 @@ class Display(AbstractDisplay):
             color_depth=color_depth,
             bgcolor=bgcolor,
             **kwargs)
-        AbstractDisplay.__init__(self)
+        AbstractDisplay.__init__(self, use_xauth=use_xauth)
 
     @property
     def display_class(self):
diff --git a/pyvirtualdisplay/xauth.py b/pyvirtualdisplay/xauth.py
new file mode 100644
index 0000000..2605b0e
--- /dev/null
+++ b/pyvirtualdisplay/xauth.py
@@ -0,0 +1,37 @@
+'''Utility functions for xauth.'''
+import os
+import hashlib
+
+import easyprocess
+
+
+class NotFoundError(Exception):
+    '''Error when xauth was not found.'''
+    pass
+
+
+def is_installed():
+    '''
+    Return whether or not xauth is installed.
+    '''
+    try:
+        easyprocess.EasyProcess(['xauth', '-h']).check_installed()
+    except easyprocess.EasyProcessCheckInstalledError:
+        return False
+    else:
+        return True
+
+
+def generate_mcookie():
+    '''
+    Generate a cookie string suitable for xauth.
+    '''
+    data = os.urandom(16)  # 16 bytes = 128 bit
+    return hashlib.md5(data).hexdigest()
+
+
+def call(*args):
+    '''
+    Call xauth with the given args.
+    '''
+    easyprocess.EasyProcess(['xauth'] + list(args)).call()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pyvirtualdisplay.git



More information about the Python-modules-commits mailing list