~ubuntu-branches/ubuntu/quantal/lsb/quantal-proposed

« back to all changes in this revision

Viewing changes to initdutils.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lawrence
  • Date: 2008-08-18 16:34:24 UTC
  • mto: (1.1.3 squeeze)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20080818163424-pz9dtrbfm8zjnuts
Tags: 3.2-20
* Revert change in 3.2-16 that broke killproc due to my misunderstanding
  of the spec.  (Closes: #495587)
* pidofproc now also checks for /var/run/$base.pid if -p is not specified,
  fixing conformance with the spec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Support for scanning init scripts for LSB info
2
2
 
3
3
import re, sys, os, cStringIO
 
4
import cPickle
4
5
 
5
6
try:
6
7
    assert True
50
51
LSBLIB = '/var/lib/lsb'
51
52
FACILITIES = os.path.join(LSBLIB, 'facilities')
52
53
DEPENDS = os.path.join(LSBLIB, 'depends')
 
54
LSBINSTALL = os.path.join(LSBLIB, 'lsbinstall')
53
55
 
54
56
beginre = re.compile(re.escape('### BEGIN INIT INFO'))
55
57
endre = re.compile(re.escape('### END INIT INFO'))
80
82
    for header, body in inheaders.iteritems():
81
83
        # Ignore empty headers
82
84
        if not body.strip():
83
 
            break
 
85
            continue
84
86
        
85
87
        if header in ('Default-Start', 'Default-Stop'):
86
88
            headers[header] = map(int, body.split())
144
146
        print >> fh, '%s: %s' % (initfile, ' '.join(facilities))
145
147
    fh.close()
146
148
 
 
149
# filemap entries are mappings, { (package, filename) : instloc }
 
150
def load_lsbinstall_info():
 
151
    if not os.path.exists(LSBINSTALL):
 
152
        return {}
 
153
    
 
154
    fh = open(LSBINSTALL, 'rb')
 
155
    filemap = cPickle.load(fh)
 
156
    fh.close()
 
157
 
 
158
    # Just in case it's corrupted somehow
 
159
    if not isinstance(filemap, dict):
 
160
        return {}
 
161
 
 
162
    return filemap
 
163
 
 
164
def save_lsbinstall_info(filemap):
 
165
    if not filemap:
 
166
        try:
 
167
            os.unlink(LSBINSTALL)
 
168
        except OSError:
 
169
            pass
 
170
        return
 
171
    
 
172
    fh = open(LSBINSTALL, 'wb')
 
173
    cPickle.dump(fh, filemap)
 
174
    fh.close()
 
175
 
147
176
if __name__ == '__main__':
148
177
    print scan_initfile('init-fragment')