~ktenney/+junk/docubi

« back to all changes in this revision

Viewing changes to explanans/sg.py

  • Committer: ktenney
  • Date: 2009-10-23 13:11:54 UTC
  • Revision ID: ktenney@lappy-20091023131154-0rc84r9b2jul417g
moved explanans/ to ../explanans/. explanans/ is where manuel stuff currently is

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from utility import utility
2
 
import os
3
 
import subprocess
4
 
#!/etc/env/python
5
 
 
6
 
class ScreenGrab:
7
 
    """Screen grabber
8
 
    """
9
 
 
10
 
    def __init__(self, grabapp='import', wait=False):
11
 
        """Default is to grab with Imagemagick's `import`
12
 
        """
13
 
 
14
 
        self.grabapp = grabapp
15
 
        if not wait:
16
 
            self.run()
17
 
    def run(self):
18
 
        """Call the grabber application
19
 
        """
20
 
 
21
 
        dest_dir = self._get_file_dir()
22
 
        filename = utility.get_uuid1_filename(dest_dir, 'png')
23
 
        grabcmd = "%s %s" % (self.grabapp, filename)
24
 
 
25
 
        try:
26
 
            subprocess.Popen(grabcmd.split()).wait()
27
 
 
28
 
        except OSError:
29
 
            print '\nSorry, subprocess %s failure\n' % grabcmd
30
 
            print 'will now halt\n'
31
 
            sys.exit()
32
 
    def _get_file_dir(self):
33
 
        """XXX TODO read config, environment
34
 
        """
35
 
 
36
 
        return '/home/ktenney/work/docubi/chunks/image'