summaryrefslogtreecommitdiff
blob: ddce96815b2de937d10ff9580848d3e818dce4f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
#!/usr/bin/python
# -*- Mode: python -*-

# Copyright (C) 2001-2019 Artifex Software, Inc.
# All Rights Reserved.
#
# This software is provided AS-IS with no warranty, either express or
# implied.
#
# This software is distributed under license and may not be copied,
# modified or distributed except as expressly authorized under the terms
# of the license contained in the file LICENSE in this distribution.
#
# Refer to licensing information at http://www.artifex.com or contact
# Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
# CA 94945, U.S.A., +1(415)492-9861, for further information.
#


# overview
# 	update revision (default is HEAD)
# 	run all testfiles with all parameter sets using the gs executable - calculate each checksum
# 	compare checksums with 1) previous results 2) baseline checksums
# 	report baseline changes
# 	email results
# 
# temporary output:
#	the output images from gs execution are not saved
#
# permanent output:
# 	checksum database for the day (an "anydbm" database [testfile-device,checksum]
# 
# input:
# 	testing.cfg - configuration many significant variables (in /home/regression/regression, or .)
# 	command line - control details of execution
# 	files in compare file directory (ususally /home/regression/comparefiles)
# 	The following are "anydbm" databases as described above
#	 	database of checksums of the raster files in /home/regression/raster
#	 	databases of past nightly runs in /home/regression/regression/daily (only the most recent is used)
# 	baseline.log - log of updates to baseline raster files (in /home/regression/regression/baseline) [text file]
# 	
# Note that the raster files themselves are not used in this process.
# 
# Hierarchy of python scripts
# 	run_nightly.py
#		gsconf.py - read testing.cfg and create an object defining the environment for all other scripts
# 		run_regression.py - execute gs, calculate checksum, insert into database
#			gs_checkall.py
#				gs_checkraster.py
#				gs_checkpdfwrite.py
#					gsparamset.py - define the "parameter set" - the set of output devices to be tested for each file
#					gstestgs.py, gstestutil.py - run gs (used the built-in Python unit test harness)
#					gssum.py - checksum calculation and database addition
#			
# 		testdiff.py - compare three checksum databases
# 		get_baseline_log.py - extract recent changes to the baseline.log 
#
#
#
#



import os
import sys, shutil
import re
import time
import optparse, myoptparse
import string
import build_revision
import gsconf, gsparamsets
import anydbm
from popen2 import Popen4

# configuration variables

myself="unknown"
myversion="2.01"

def logMessage(message,file,revision,printMessage=True):
    message_time=time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime())
    message=myself+" "+revision+" "+message_time+" "+message
    if printMessage:
        print message
    message+="\n"
    if file:
        file.write(message)
        file.flush()

def die(msg):
    sendmail(gsconf.report_from, gsconf.report_to, "error running regression", msg)
    sys.exit(0)

def read_all_lines(f):
    file = open(f, 'r')
    lines = file.readlines()
    file.close()
    return string.join(lines, '')

def get_count_in_db(dbname):
    try:
        db = anydbm.open(dbname, 'r')
        if not db:
            count=0
        else:
            count=len(db)
    except:
        count=0
    print dbname,count

def get_revision(dir=None):
    if dir:
        cwd=os.getcwd()
        os.chdir(dir)

    command="svn update --non-recursive"
    if os.system(command) != 0:
        message = "run_nightly.py:get_revision.py: cannot svn update"
        logMessage(message,None,"unknown")
        return "unknown"

    command="svn info"
    p = os.popen(command)
    for line in p:
        if "Revision:" in line:
            revision=line.strip('Revision: ')
            revision=revision.strip('\n')
	    break
    else:
        revision = None
    if dir:
        os.chdir(cwd)
    return revision

def change_gsproduct(file):
    tmpfile = "%s.tmp" % (file,)

    startre = re.compile("^#ifndef\ GS_PRODUCT$")
    changere = re.compile("^.*?\"[A-Za-z -]+\".*?$")
    endre = re.compile("^$")

    old = open(file, "r")
    new = open(tmpfile, "w")

    state = 0
    for line in old.readlines():
        print "checking:", line
        if state == 0:
            m = startre.search(line)
            if m:
                state = 1
                
            new.write(line)
        elif state == 1:
            m = changere.search(line)
            if m:
                state = 2
                new.write("\t\"GPL Ghostscript\"\n")
		print "rewriting '%s' to GPL Ghostscript" % line.strip()
            else:
                new.write(line)
        elif state == 2:
            m = endre.search(line)
            if m:
                state = 0

            new.write(line)

    old.close()
    new.close()

    os.unlink(file)
    os.rename(tmpfile, file)

def sendmail(frm, to, subject, text):
    import smtplib

    keyword = gsconf.mailkeyword
    if keyword:
        msg = 'From: %s\r\nTo: %s\r\nSubject: %s\r\nX-Fnord: %s\r\n\r\n%s' % (frm, to, subject, keyword, text)
    else:
        msg = 'From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s' % (frm, to, subject, text)

#   server = smtplib.SMTP(gsconf.mail_server)
#   server.sendmail(frm, to, msg)
#   server.quit()
    SENDMAIL = "/usr/sbin/sendmail" # sendmail location
    p = os.popen("%s -t" % SENDMAIL, "w")
    p.write(msg)
    p.close()

def run_nightly(options,arguments):
    global myself

    myself=options.myself
    # what do we work on?
    revision      = options.revision
    release       = options.release
    
    # what do we build
    update           = not options.noupdate
    
    options.svn       = not options.nosvn
    options.configure = not options.noconfigure
    options.make      = not options.nomake
    options.makeclean = not options.nomakeclean
    
    options.remove   = False  # never remove the gs executable, we need it for regression testing
    
    # what do we run?
    runRegression    = not options.noregression
    testRegression   = not options.notestregression
    baselineChanges  = not options.nobaselinechanges
    printRegression  = options.printregression
    
    # where do stdout and stderr go?
    options.capture  = not options.nocapture
    
    p = os.popen('hostname -s')
    if p:
        hostname = string.strip(p.readline())
        p.close()
    else:
        hostname = 'unknown host'
        
    p = os.popen('uname -m -s')
    if p:
        hostuname=string.strip(p.readline())
        p.close()
    else:
        hostuname=""

    hostname=hostname + " (" + hostuname + ')'

    if release:
        print "NOT SUPPORTED: need to build a release",release
        sys.exit(1)

    if not revision or revision == "HEAD":
        gsroot=gsconf.gsroot
        revision_value=get_revision(gsroot)
        gsinstall=gsconf.installtree
        gspath=gsconf.installtree+"bin/gs"
        revision_full="HEAD:"+revision_value
    else:
        gsroot=gsconf.root+"gs."+revision+"/"
        gsconf.checksumdb = revision
        revision_value=revision
        gsrevision_root=gsconf.root+"gs."+revision+"/"
        gspath=gsrevision_root+"bin/gs"
        gsinstall=None
        revision_full=revision_value

    logdir=gsconf.logdir
    if not os.path.exists(logdir):
        os.mkdir(logdir)

    now=time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime())
    mail_message = now+" "+revision_value+"\n"

    prefix=logdir+revision_value+"."

    update_stdout=prefix+gsconf.update_stdout
    update_stderr=prefix+gsconf.update_stderr
    make_stdout=prefix+gsconf.make_stdout
    make_stderr=prefix+gsconf.make_stderr
    config_stdout=prefix+gsconf.config_stdout
    config_stderr=prefix+gsconf.config_stderr
    install_stdout=prefix+gsconf.install_stdout
    install_stderr=prefix+gsconf.install_stderr
    
    cumulative_name=prefix+gsconf.cumulative
    
    history_name=logdir+gsconf.history        # permanent file, accumulates history across days
    
    if not os.path.exists(history_name):
        messageHistory="creating history file "+history_name
    else:
        messageHistory="opening history file "+history_name
    history_file = open(history_name, "w")    

    cumulative_file = open(cumulative_name, "w")
    message="cumulative"
    logMessage(message,cumulative_file,revision_full,printMessage=False)
    logMessage(messageHistory,cumulative_file,revision_full,printMessage=False)

    message="running on " + hostname +" my version "+myversion
    logMessage(message,cumulative_file,revision_full)
    logMessage(message,history_file,revision_full,printMessage=False)
    if options.version:
        sys.exit(1)

    if options.removeonly:
        path=gsroot
        message="removing "+path
        logMessage(message,cumulative_file,revision_full)
        shutil.rmtree(path,ignore_errors=True)
        if gsinstall:
            path=gsinstall
            message="removing "+path
            logMessage(message,cumulative_file,revision_full)
            shutil.rmtree(path,ignore_errors=True)
        sys.exit(1)

    mail_message+=message+"\n"

    if not os.path.exists(gsconf.comparefiledir + "/.svn") or \
	    os.system("svn update " + gsconf.comparefiledir) != 0:
	message = "run_nightly.py: cannot svn update " + gsconf.comparefiledir
	logMessage(message,None,"n/a")

    if not os.path.exists(gsconf.comparefiledir + "/../tests/eps" + "/.svn") or \
	    os.system("svn update " + gsconf.comparefiledir + "/../tests/eps") != 0:
	message = "run_nightly.py: cannot svn update " + gsconf.comparefiledir + "/../tests/eps"
	logMessage(message,None,"n/a")
    if os.path.exists(gsconf.comparefiledir + "/../tests/eps"):
        os.system("ln -f -s " + gsconf.comparefiledir + "/../tests/eps/* " + gsconf.comparefiledir)
    if not os.path.exists(gsconf.comparefiledir + "/../tests/ps" + "/.svn") or \
	    os.system("svn update " + gsconf.comparefiledir + "/../tests/ps") != 0:
	message = "run_nightly.py: cannot svn update " + gsconf.comparefiledir + "/../tests/ps"
	logMessage(message,None,"n/a")
    if os.path.exists(gsconf.comparefiledir + "/../tests/ps"):
        os.system("ln -f -s " + gsconf.comparefiledir + "/../tests/ps/* " + gsconf.comparefiledir)
    if not os.path.exists(gsconf.comparefiledir + "/../tests/pdf" + "/.svn") or \
	    os.system("svn update " + gsconf.comparefiledir + "/../tests/pdf") != 0:
	message = "run_nightly.py: cannot svn update " + gsconf.comparefiledir + "/../tests/pdf"
	logMessage(message,None,"n/a")
    if os.path.exists(gsconf.comparefiledir + "/../tests/pdf"):
        os.system("ln -f -s " + gsconf.comparefiledir + "/../tests/pdf/* " + gsconf.comparefiledir)
    comparefiles = os.listdir(gsconf.comparefiledir)
    count=len(comparefiles)

    message="comparefiles from "+gsconf.comparefiledir+" number of files "+str(count)
    logMessage(message,cumulative_file,revision_full)
    logMessage(message,history_file,revision_full,printMessage=False)
    mail_message+=message+"\n"

    # use the smallest that is requested
    if options.oneset:    
        gsparamsets.testparamsets = gsparamsets.testparamsets_one
        gsparamsets.pdftestparamsets = gsparamsets.pdftestparamsets_one
        gsparamsets.testparamsets_name = "one"
    elif options.minset:
        gsparamsets.testparamsets = gsparamsets.testparamsets_minimum
        gsparamsets.pdftestparamsets = gsparamsets.pdftestparamsets_minimum
        gsparamsets.testparamsets_name = "minimum"
    elif options.maxset:    
        gsparamsets.testparamsets = gsparamsets.testparamsets_maximum
        gsparamsets.pdftestparamsets = gsparamsets.pdftestparamsets_full
        gsparamsets.testparamsets_name = "maximum"
    elif options.fullset:    
        gsparamsets.testparamsets = gsparamsets.testparamsets_full
        gsparamsets.pdftestparamsets = gsparamsets.pdftestparamsets_full
        gsparamsets.testparamsets_name = "full"
    else:
        pass # use default in gsparamsets

    gsparamsets.testparamsets = gsparamsets.testparamsets_one
    gsparamsets.pdftestparamsets = gsparamsets.pdftestparamsets_full
    gsparamsets.testparamsets_name = "one+pdf"


    message="test parameter set name: "+gsparamsets.testparamsets_name
    logMessage(message,cumulative_file,revision_full)
    logMessage(message,history_file,revision_full,printMessage=False)
    mail_message+=message+"\n"

    message="logging to "+prefix+"*"
    logMessage(message,cumulative_file,revision_full)
    mail_message+=message+"\n"

    message="sending mail to "+gsconf.report_to
    logMessage(message,cumulative_file,revision_full)
    logMessage(message,history_file,revision_full,printMessage=False)

    if update:
        message="starting update_ghostscript"
        logMessage(message,cumulative_file,revision_full)
    
        (err,message) = build_revision.update_ghostscript(revision,release,
                                                          gsroot,
                                                          options,
                                                          update_stdout,update_stderr,
                                                          config_stdout,config_stderr,
                                                          make_stdout,make_stderr,
                                                          install_stdout,install_stderr,
                                                          cumulative_file
                                                          )
        if err != 0:
            die(message)
    else:
        message="skipping update of ghostscript tree and executable"
        logMessage(message,cumulative_file,revision_full)

    message = "running makemissing"
    logMessage(message,cumulative_file,revision_full)
    os.system("./makemissing 2>logs/makemissing.stderr >logs/makemissing.stdout")


    prefix=logdir+revision_value+"."

    baselines_name=prefix+gsconf.baselines
    differences_name=prefix+gsconf.differences
    regression_name=prefix+gsconf.regression
    email_name=prefix+gsconf.email

    if not os.path.exists(gspath):
        message=myself+" FATAL "+"the gs executable does not exist "+gspath
        logMessage(message,cumulative_file,revision_full)
        die(message)

    regression_file = open(regression_name, "w")
    message="regression"
    logMessage(message,regression_file,revision_full,printMessage=False)

    message="revision of executable "+revision_full
    logMessage(message,regression_file,revision_full,printMessage=False)
    logMessage(message,history_file,revision_full,printMessage=False)
    mail_message+=message+"\n"

    revision_name=prefix+revision
    revision_file = open(revision_name, "w")
    revision_file.close()

    # create string "regression_results" for regression results
    regression_results = '\n'
    if runRegression:
        print

        message="starting regression testing on "+revision
        logMessage(message,regression_file,revision_full,printMessage=False)
        logMessage(message,cumulative_file,revision_full)

        timearg=" --time="+"\""+now+"\""
        trackarg=" --track"

        # revision can be HEAD
        if revision != "HEAD":
            revisionarg=" --revision="+revision
        else: revisionarg=""
   
        # revision_value always has the revision number, also for HEAD
        revision_valuearg=" --revision_value="+revision_value

        if release:
            releasearg=" --release="+release
        else: releasearg=""
    
        command=gsconf.run_regression_script + releasearg + revisionarg + revision_valuearg + timearg + trackarg

        if options.capture:
            capture=" 2>&1"
            command+=capture

        message=command
        logMessage(message,regression_file,revision_full,printMessage=False)
        logMessage(message,cumulative_file,revision_full)

        regression_results += '\nThe complete list of regressions for today:\n'
        regression_results += command +"\n"

        p = os.popen(command)
        if p == None:
            message="cannot open and run the regression script."
            logMessage(message,cumulative_file,revision_full)
            die(message)

        pattern = 'ok$'
        for line in p.readlines():
            if printRegression: print line
            if not re.search(pattern, line):
                regression_results += line
        p.close()

        # count number of entries in daily db
        if gsconf.__dict__.has_key("checksumdb") and gsconf.checksumdb:
            newchecksum=gsconf.checksumdb
        else:
            newchecksum=time.strftime("%Y%m%d", time.localtime())

    else:
        message="skipping regression testing"
        logMessage(message,regression_file,revision_full,printMessage=False)
        logMessage(message,cumulative_file,revision_full)

        regression_results+="gs regression processing was skipped"
    # end if runRegression

    regression_results += '\n'

    # create string "difference_results" for regression results
    if testRegression:
        print

        if gsconf.__dict__.has_key("checksumdb") and gsconf.checksumdb:
            newchecksum=gsconf.checksumdb
        else:
            newchecksum=time.strftime("%Y%m%d", time.localtime())

#        message="verify existence of the checksum database "+newchecksum
#        logMessage(message,cumulative_file,revision_full,printMessage=False)
#        logMessage(message,regression_file,revision_full)

        message="starting difference_results"
        logMessage(message,cumulative_file,revision_full,printMessage=False)
        logMessage(message,regression_file,revision_full)

        if options.oldrevision:
            oldchecksum=options.oldrevision
        else:
            # find the most recent checksum file in the gsconf.dailydir
            oneday=24*60*60
            testtime=time.time()
            for count in range(1,30):
                testtime-=oneday
                oldchecksum=time.strftime("%Y%m%d", time.localtime(testtime))
                datafile=gsconf.dailydir+oldchecksum+".db"
                if os.path.exists(datafile):
                    try:
                        db = anydbm.open(datafile)
                        if db:
                            db_hasdata=True
                            db.close()
                            if db_hasdata:
                                message="old checksum database used "+datafile
                                logMessage(message,cumulative_file,revision_full,printMessage=True)
                                break
                            else:
                                message="old checksum database empty "+datafile
                                logMessage(message,cumulative_file,revision_full,printMessage=True)
                    except:
                        message="old checksum database could not be opened "+datafile
                        logMessage(message,cumulative_file,revision_full,printMessage=True)
                else:
                    message="old checksum database does not exist "+datafile
                    logMessage(message,cumulative_file,revision_full,printMessage=True)
            else:
                message="cannot find any recent checksum database file",
                logMessage(message,cumulative_file,revision_full)
                message="FATAL cannot find any recent checksum database file"
                logMessage(message,cumulative_file,revision_full)
                die(message)

        oldchecksumpath = gsconf.dailydir + oldchecksum + ".db"
        if not os.path.exists(oldchecksumpath):
            message=myself+" FATAL "+"the old checksum database does not exist "+oldchecksumpath
            logMessage(message,cumulative_file,revision_full)
            die(message)

        recent_ctime = time.ctime(testtime)

        message="found recent checksum database "+oldchecksum
        logMessage(message,cumulative_file,revision_full,printMessage=False)
        logMessage(message,regression_file,revision_full)
        logMessage(message,history_file,revision_full,printMessage=False)

        difference_results = 'The following regression changes happened since recent report: '+oldchecksum
        difference_results += '\n'

        command=gsconf.testdiff_script + " " + oldchecksum + " " + newchecksum
        if options.capture:
            capture=" 2>&1"
            command+=capture

        logMessage(command,regression_file,revision_full,printMessage=False)
        logMessage(command,cumulative_file,revision_full)
        p = os.popen(command)
        if p:
            for line in p.readlines():
                if printRegression: print line
                difference_results += line
            p.close()
        else:
            difference_results = difference_results + 'no results from difference script\n'

        message="get baseline updates"
        logMessage(message,regression_file,revision_full,printMessage=False)
        logMessage(message,cumulative_file,revision_full)


        message="marcos: about to call get_baseline_log_script"
        logMessage(message,cumulative_file,revision_full)

        # Get updated baseline_changes
        baseline_changes = 'The following files had their baselines updated:\n'

        command=gsconf.get_baseline_log_script + " '" + recent_ctime + "'"
        baseline_changes += command+"\n"

        logMessage(command,cumulative_file,revision_full)
        p = Popen4(command,1)
        if p:
            for line in p.fromchild.readlines():
                baseline_changes += line
                p.wait()
        else:
            baseline_changes = baseline_changes + 'no results from baseline script\n'
            baseline_changes += "\n"

        message="marcos: done with get_baseline_log_script"
        logMessage(message,cumulative_file,revision_full)

        logMessage(baseline_changes,regression_file,revision_full)
        logMessage(difference_results,regression_file,revision_full)
    else:
        difference_results="difference testing was skipped"
    difference_results += '\n'
    # end if testRegression
    
    message="marcos: writing to differences file"
    logMessage(message,cumulative_file,revision_full)

    differences_file = open(differences_name, "w")
    message="differences"
    differences_file.write(message)
    logMessage(message,differences_file,revision_full,printMessage=False)


    if baselineChanges:
        print

        baselines_file = open(baselines_name, "w")
        message="baseline changes"
        baselines_file.write(message)
        logMessage(baseline_changes,baselines_file,revision_full,printMessage=False)

    else:
        baseline_changes = "difference testing was skipped"
        
    message="marcos: done writing to differences file"
    logMessage(message,cumulative_file,revision_full)

    # end if baselineChanges

    mail_message+=difference_results+"\n"
    mail_message+=regression_results+"\n"
    mail_message+=baseline_changes+"\n"

    email_file = open(email_name, "w")
    subject='gs regression report - %s - revision: %s' % (now,revision_full)

    message="subject "+subject
    logMessage(message,cumulative_file,revision_full)
    logMessage(message,email_file,revision_full,printMessage=False)

    message="send mail to "+gsconf.report_to
    logMessage(message,cumulative_file,revision_full)
    logMessage(message,email_file,revision_full,printMessage=False)

    logMessage(mail_message,email_file,revision_full,printMessage=False)
    email_file.close()

    if options.printmailmessage:
        print
        print "mail_message start"
        print mail_message
        print "mail_message end"    
        print

    while True:
        try:
            print "sendmail"
            sendmail(gsconf.report_from, gsconf.report_to, subject, mail_message)
            break
            time.sleep(5)
        except:
            print "sendmail fail"
            time.sleep(15)
            pass

    message="done"
    logMessage(message,cumulative_file,revision_full)

    regression_file.close()
    cumulative_file.close()
    history_file.close()

    print regression_name
    print cumulative_name
    print regression_name

    return 0

#########################################################

if __name__ == "__main__":

    os.umask(0002)

    optionsParser=optparse.OptionParser()

    optionsParser.add_option('--version',action='store_true',help="get my version")

    optionsParser.add_option('--removeonly',action='store_true',help="remove the build directory - do nothing else")

    optionsParser.add_option('--noupdate',action='store_true',help="do not update the gs executable")
    # "update" includes svn, configure, makeclean, clean, install

    optionsParser.add_option('--nosvn',action='store_true',help="do not update the source from the svn repository")
    optionsParser.add_option('--noconfigure',action='store_true',help="do not run auto configure")
    optionsParser.add_option('--nomakeclean',action='store_true',help="do not make clean before make")
    optionsParser.add_option('--nomake',action='store_true',help="do not make")

    optionsParser.add_option('--nocapture',action='store_true',help="do not capture stdout and stderr from commands")


    optionsParser.add_option('--noregression',action='store_true',help="do not run regression")
    optionsParser.add_option('--notestregression',action='store_true',help="do not test regression")
    optionsParser.add_option('--nobaselinechanges',action='store_true',help="do not analyze baselinechanges")
    optionsParser.add_option('--printregression',action='store_true',help="print regression output")
    optionsParser.add_option('--printmailmessage',action='store_true',help="print mail message")

    optionsParser.add_option('--fullset',action='store_true',help="full gsparamsets")
    optionsParser.add_option('--minset',action='store_true',help="minimum gsparamsets")
    optionsParser.add_option('--maxset',action='store_true',help="maximum gsparamsets")
    optionsParser.add_option('--oneset',action='store_true',help="one gsparamsets")    

    optionsParser.add_option('--release',action='store_true',help="under contruction")
    optionsParser.add_option('--oldrevision',action='store',help="old revision for checksum comparison",default=None)

    (options,arguments)=myoptparse.parseCommandLine(optionsParser,deviceSkip=True,testfileSkip=True,listfileSkip=True)

    if options.version:
        print options.myself,"version",myversion
        sys.exit(1)

    result = run_nightly(options,arguments)

    sys.exit(result)