~richardw/jarmon/jsrrdgraph-integration

« back to all changes in this revision

Viewing changes to jarmonbuild/commands.py

  • Committer: Richard Wall
  • Date: 2011-02-16 22:29:59 UTC
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: richard@largo-20110216222959-648kujekhvy24mal
Some pyflakes / pep8 fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
import os
9
9
import shutil
10
10
import sys
11
 
import time
12
11
 
13
 
from datetime import datetime
14
12
from optparse import OptionParser
15
13
from subprocess import check_call, PIPE
16
14
from tempfile import gettempdir
20
18
import pkg_resources
21
19
 
22
20
 
23
 
JARMON_PROJECT_TITLE='Jarmon'
24
 
JARMON_PROJECT_URL='http://www.launchpad.net/jarmon'
 
21
JARMON_PROJECT_TITLE = 'Jarmon'
 
22
JARMON_PROJECT_URL = 'http://www.launchpad.net/jarmon'
25
23
 
26
24
YUIDOC_URL = 'http://yuilibrary.com/downloads/yuidoc/yuidoc_1.0.0b1.zip'
27
25
YUIDOC_MD5 = 'cd5545d2dec8f7afe3d18e793538162c'
91
89
        yuizip_path = os.path.join(tmpdir, os.path.basename(YUIDOC_URL))
92
90
        if os.path.exists(yuizip_path):
93
91
            self.log.debug('Using cached YUI doc')
 
92
 
94
93
            def producer():
95
94
                yield open(yuizip_path).read()
96
95
        else:
97
96
            self.log.debug('Downloading YUI Doc')
 
97
 
98
98
            def producer():
99
99
                with open(yuizip_path, 'w') as yuizip:
100
100
                    download = urlopen(YUIDOC_URL)
101
101
                    while True:
102
 
                        bytes = download.read(1024*10)
 
102
                        bytes = download.read(1024 * 10)
103
103
                        if not bytes:
104
104
                            break
105
105
                        else:
114
114
        if actual_md5 != YUIDOC_MD5:
115
115
            raise BuildError(
116
116
                'YUI Doc checksum error. File: %s, '
117
 
                'Expected: %s, Got: %s' % (yuizip_path, YUIDOC_MD5, actual_md5))
 
117
                'Expected: %s, '
 
118
                'Got: %s' % (yuizip_path, YUIDOC_MD5, actual_md5))
118
119
        else:
119
120
            self.log.debug('YUI Doc checksum verified')
120
121
 
145
146
                    workingbranch_dir, 'jarmonbuild', 'yuidoc_template'),),
146
147
            '--version=%s' % (buildversion,),
147
148
            '--project=%s' % (JARMON_PROJECT_TITLE,),
148
 
            '--projecturl=%s' % (JARMON_PROJECT_URL,)
 
149
            '--projecturl=%s' % (JARMON_PROJECT_URL,),
149
150
        ), stdout=PIPE, stderr=PIPE,)
150
151
 
151
152
        shutil.rmtree(yuidoc_dir)
181
182
        if status != 0:
182
183
            raise BuildError('bzr export failure. Status: %r' % (status,))
183
184
 
184
 
 
185
185
        self.log.debug('Record the branch version')
186
186
        from bzrlib.branch import Branch
187
187
        from bzrlib.version_info_formats import format_python
188
188
        v = format_python.PythonVersionInfoBuilder(
189
189
            Branch.open(workingbranch_dir))
190
 
        versionfile_path = os.path.join(build_dir, 'jarmonbuild', '_version.py')
 
190
 
 
191
        versionfile_path = os.path.join(
 
192
            build_dir, 'jarmonbuild', '_version.py')
 
193
 
191
194
        with open(versionfile_path, 'w') as f:
192
195
            v.generate(f)
193
196
 
194
 
 
195
197
        self.log.debug('Generate apidocs')
196
198
        BuildApidocsCommand().main([buildversion])
197
199
 
198
 
 
199
200
        self.log.debug('Generate archive')
200
201
        archive_root = 'jarmon-%s' % (buildversion,)
201
202
        prefix_len = len(build_dir) + 1
205
206
                for file in files:
206
207
                    z.write(
207
208
                        os.path.join(root, file),
208
 
                        os.path.join(archive_root, root[prefix_len:], file)
 
209
                        os.path.join(archive_root, root[prefix_len:], file),
209
210
                    )
210
211
        finally:
211
212
            z.close()
233
234
        rows = 12
234
235
        step = 10
235
236
 
236
 
        dss.append(DataSource(dsName='speed', dsType='GAUGE', heartbeat=2*step))
 
237
        dss.append(
 
238
            DataSource(dsName='speed', dsType='GAUGE', heartbeat=2 * step))
237
239
        rras.append(RRA(cf='AVERAGE', xff=0.5, steps=1, rows=rows))
238
240
        rras.append(RRA(cf='AVERAGE', xff=0.5, steps=12, rows=rows))
239
241
        my_rrd = RRD(filename, ds=dss, rra=rras, start=start, step=step)
240
242
        my_rrd.create()
241
243
 
242
 
        for i, t in enumerate(range(start+step, start+step+(rows*step), step)):
243
 
            self.log.debug('DATA: %s %s (%s)' % (t, i, datetime.fromtimestamp(t)))
 
244
        for i, t in enumerate(
 
245
            range(start + step, start + step + (rows * step), step)):
 
246
            self.log.debug(
 
247
                'DATA: %s %s (%s)' % (t, i, datetime.fromtimestamp(t)))
244
248
            my_rrd.bufferValue(t, i)
245
249
 
246
250
        # Add further data 1 second later to demonstrate that the rrd