~ubuntu-branches/ubuntu/trusty/aptoncd/trusty

« back to all changes in this revision

Viewing changes to APTonCD/core/scanpkgs.py

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-19 21:41:06 UTC
  • mfrom: (3 sid) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20090819214106-7g72fpzgvl722w6k
* New maintainer (Closes: #542459, #484637, #542501)
* New upstream release
  - Fix the executable flag on non executable files. This fix last lintian
    warnings
* debian/rules: prepared for python2.6 (include of python.mk and use of 
  $(py_setup_install_args) )

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#   thanks to Dave Arter <davea@sucs.org>
 
3
#   Copyright (c) 2005 Dave Arter
 
4
from subprocess import Popen
 
5
from subprocess import PIPE
 
6
 
 
7
class  AptFtpArchive:
 
8
 
 
9
    """Mkisofs is a wrapper for the mkisofs program. It simplifies
 
10
    calls to mkisofs and tracks its progress. An optional hook is
 
11
    provided which will be called whenever a percentage progress is
 
12
    reported by mkisofs."""
 
13
 
 
14
    def __init__(self):
 
15
        self.progress_hook = None
 
16
        self.progress = 0.0
 
17
        self.retval = None
 
18
 
 
19
    def set_progress_hook(self, hook = None):
 
20
 
 
21
        """Sets the progress hook function to the argument hook. The
 
22
        function specified by hook should accept a floating point number
 
23
        as its only argument."""
 
24
 
 
25
        if (callable(hook)):
 
26
            self.progress_hook = hook
 
27
 
 
28
    def _set_progress(self, progress):
 
29
        try:
 
30
            self.progress = float(progress)
 
31
        except ValueError:
 
32
            pass
 
33
 
 
34
    def report_progress(self):
 
35
 
 
36
        """Calls the progress hook if one has been specified."""
 
37
        if callable(self.progress_hook):
 
38
            self.progress_hook(self.progress)
 
39
 
 
40
    def execute(self, command, path, destination):
 
41
 
 
42
        """Takes a source file path and creates an iso file with it, which
 
43
        is written to the isofile path. mkisofs is called with option -r.
 
44
        See the mkisofs manual for details"""
 
45
        args = command
 
46
        inFile = open(destination,'w')
 
47
        process = Popen(args, 1, stdout=inFile, stderr=PIPE, cwd = path, shell = True )
 
48
        self.retval = process.poll()
 
49
        while (self.retval is None):
 
50
            self._set_progress(-1)
 
51
            self.report_progress()
 
52
            self.retval = process.poll()
 
53
 
 
54
        inFile.close()
 
55
 
 
56
    def get_retval(self):
 
57
 
 
58
        """Gets the value returned by mkisofs or None if it hasn't
 
59
        finished a run."""
 
60
 
 
61
        return self.retval