3 This script will scan an autotest server results directory for job result
4 directories that have completed and that have not yet been published on
5 a remote dashboard server matching given filtering options and for those it
6 finds it will rsync them to the tko server and mark them as published (it uses
7 a <jobdir>/.tko_published flag file to determine if a jobdir results directory
8 has been published yet).
11 import sys
, os
, re
, optparse
14 from autotest_lib
.client
.common_lib
import utils
15 from autotest_lib
.server
import frontend
17 options
= optparse
.Values()
19 USAGE
="""tko-publish [options] <resultsdir> <rsync-destination-path>
22 <resultsdir> A path to the directory having the job results
23 directories to publish.
25 <rsync-destination-path> A valid rsync destination path where to upload the
26 job result directories.
27 Example: user@machine.org:/home/autotest/results"""
28 PUBLISH_FLAGFILE
= '.tko_published'
29 RSYNC_COMMAND
= 'rsync -aqz "%s" "%s"'
32 def get_job_dirs(path
):
33 regex
= re
.compile('[1-9][0-9]*-')
36 for dir in os
.listdir(path
):
37 # skip directories not matching the job result dir pattern
38 if not regex
.match(dir):
41 dir = os
.path
.join(options
.resultsdir
, dir)
42 if (os
.path
.isdir(dir)
43 and not os
.path
.exists(os
.path
.join(dir, PUBLISH_FLAGFILE
))):
49 def publish_job(jobdir
):
50 cmd
= RSYNC_COMMAND
% (jobdir
, options
.dest
)
53 # mark the jobdir as published
54 fd
= open(os
.path
.join(jobdir
, PUBLISH_FLAGFILE
), 'w')
56 print 'Published', jobdir
60 jobdirs
= get_job_dirs(options
.resultsdir
)
63 # the way AFE API is right now is to give a whole list of jobs and can't
64 # get specific jobs so minimize the queries caching the result
65 finished_jobs
= afe
.get_jobs(finished
=True)
67 if options
.jobname_pattern
:
68 jobname_pattern
= re
.compile(options
.jobname_pattern
)
70 jobname_pattern
= None
72 # for each unpublished possible jobdir find it in the database and see
74 for jobdir
in jobdirs
:
75 job_id
= int(os
.path
.basename(jobdir
).split('-')[0])
76 job
= [job
for job
in finished_jobs
if job
.id == job_id
]
82 # does it match the jobname pattern?
83 if not jobname_pattern
.match(job
[0].name
):
86 # does it match the wanted job owner
87 if options
.job_owner
and options
.job_owner
!= job
[0].owner
:
93 if __name__
== '__main__':
94 parser
= optparse
.OptionParser(usage
=USAGE
)
95 parser
.add_option('--jobname-pattern', dest
='jobname_pattern',
96 help='Regexp pattern to match against job names, by '
97 "default there won't be any matching done",
99 parser
.add_option('--job-owner', dest
='job_owner', default
=None,
100 help='Job owner username to match against for the '
101 'published jobs, by default no matching is done.')
102 options
, args
= parser
.parse_args()
108 options
.resultsdir
= args
[0]
109 options
.dest
= args
[1]