-
Notifications
You must be signed in to change notification settings - Fork 9
/
launch.py
executable file
·2183 lines (1807 loc) · 82 KB
/
launch.py
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
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2012-2014 Bitergia
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Authors :
# Luis Cañas-Díaz <[email protected]>
# Daniel Izquierdo Cortázar <[email protected]>
# Alvaro del Castillo San Felix <[email protected]>
#
# launch.py
#
# This script automates the execution of some of the metrics grimoire
# tools (Bicho, MLStats, CVSAnaly). It uses configuration files to get
# the parameters. Finally it execute R scripts in order to generate the
# JSON files
import logging
import logging.handlers
import os
import subprocess
import sys
import time
import distutils.dir_util
import json
import datetime as dt
from optparse import OptionGroup, OptionParser
from tempfile import NamedTemporaryFile
from ConfigParser import SafeConfigParser
import MySQLdb
# conf variables from file(see read_main_conf)
options = {}
# global var for logs
main_log = None
MAX_LOG_BYTES = 10000000 #10MB
MAX_LOG_FILES = 5 #6 files (.log, .log.1, ... , .log.5)
log_files = None
# global var for directories
project_dir = ''
msg_body = ''#project_dir + '/log/launch.log'
scm_dir = ''#os.getcwd() + '/../scm/'
conf_dir = ''#os.getcwd() + '/../conf/'
json_dir = ''
production_dir = ''
tools = {
'scm' :'/usr/local/bin/cvsanaly2',
'its': '/usr/local/bin/bicho',
'scr': '/usr/local/bin/bicho',
'mls': '/usr/local/bin/mlstats',
'irc': '/usr/local/bin/irc_analysis.py',
'mediawiki': '/usr/local/bin/mediawiki_analysis.py',
'confluence': '/usr/local/bin/confluence_analysis.py',
'sibyl': '/usr/local/bin/sibyl.py',
'octopus': '/usr/local/bin/octopus',
'pullpo': '/usr/local/bin/pullpo',
'eventizer': '/usr/local/bin/eventizer',
'r': '/usr/bin/R',
'rremoval': '/usr/local/bin/rremoval',
'git': '/usr/bin/git',
'svn': '/usr/bin/svn',
'mysqldump': '/usr/bin/mysqldump',
'compress': '/usr/bin/7zr',
'rm': '/bin/rm',
'rsync': '/usr/bin/rsync',
'sortinghat': '/usr/local/bin/sortinghat',
'mg2sh': '/usr/local/bin/mg2sh',
'sh2mg': '/usr/local/bin/sh2mg',
}
# Config files where lists of repositories are found.
# It is expected to find a repository per line
BICHO_TRACKERS = "bicho_trackers.conf"
BICHO_TRACKERS_BLACKLIST = "bicho_trackers_blacklist.conf"
BICHO_1_TRACKERS = "bicho_1_trackers.conf"
BICHO_1_TRACKERS_BLACKLIST = "bicho_1_trackers_blacklist.conf"
CVSANALY_REPOSITORIES = "cvsanaly_repositories.conf"
CVSANALY_REPOSITORIES_BLACKLIST = "cvsanaly_repositories_blacklist.conf"
GERRIT_PROJECTS = "gerrit_trackers.conf"
GERRIT_PROJECTS_BLACKLIST = "gerrit_trackers_blacklist.conf"
MLSTATS_MAILING_LISTS = "mlstats_mailing_lists.conf"
MLSTATS_MAILING_LISTS_BLACKLIST = "mlstats_mailing_lists_blacklist.conf"
PUPPET_RELEASES = "puppet_releases.conf"
DOCKER_PACKAGES = "docker_packages.conf"
def get_options():
parser = OptionParser(usage='Usage: %prog [options]',
description='Update data, process it and obtain JSON files',
version='0.1')
parser.add_option('-d','--dir', dest='project_dir',
help='Path with the configuration of the project', default=None)
parser.add_option('-q','--quiet', action='store_true', dest='quiet_mode',
help='Disable messages in standard output', default=False)
parser.add_option('-s','--section', dest='section',
help='Section to be executed', default=None)
parser.add_option('-t','--data-source', dest='subtask',
help='Sub section to be executed (only for r)', default=None)
parser.add_option('--filter', dest='filter',
help='Filter to be used (repository, company, project, country ...)', default=None)
parser.add_option('-g', '--debug', action='store_true', dest='debug',
help='Enable debug mode', default=False)
parser.add_option('--python', dest='python', action="store_true",
help='Use python script for getting metrics. (obsolete)')
(ops, args) = parser.parse_args()
if ops.project_dir is None:
parser.print_help()
print("Project dir is required")
sys.exit(1)
return ops
def initialize_globals(pdir):
global project_dir
global msg_body
global scm_dir
global irc_dir
global conf_dir
global downs_dir
global json_dir
global repos_dir
global scripts_dir
global production_dir
global identities_dir
global downloads_dir
global r_dir
global log_files
project_dir = pdir
msg_body = project_dir + '/log/launch.log'
scm_dir = project_dir + '/scm/'
irc_dir = project_dir + '/irc/'
conf_dir = project_dir + '/conf/'
downs_dir = project_dir + '/downloads/'
json_dir = project_dir + '/json/'
repos_dir = conf_dir + "repositories/"
scripts_dir = project_dir + '/scripts/'
production_dir = project_dir + '/production/'
identities_dir = project_dir + '/tools/VizGrimoireUtils/identities/'
downloads_dir = project_dir + '/tools/VizGrimoireUtils/downloads/'
r_dir = project_dir + '/tools/GrimoireLib/vizGrimoireJS/'
# global var for logs
log_files = {
'cvsanaly' : project_dir + '/log/retrieval_cvsanaly.log',
'bicho' : project_dir + '/log/retrieval_bicho.log',
'gerrit' : project_dir + '/log/retrieval_gerrit.log',
'mlstats' : project_dir + '/log/retrieval_mlstats.log',
'irc' : project_dir + '/log/retrieval_irc.log',
'mediawiki' : project_dir + '/log/retrieval_mediawiki.log',
'confluence' : project_dir + '/log/retrieval_confluence.log',
'sibyl' : project_dir + '/log/retrieval_sibyl.log',
'octopus_puppet' : project_dir + '/log/retrieval_octopus_puppet.log',
'octopus_docker' : project_dir + '/log/retrieval_octopus_docker.log',
'octopus_github' : project_dir + '/log/retrieval_octopus_github.log',
'octopus_gerrit' : project_dir + '/log/retrieval_octopus_gerrit.log',
'sortinghat_affiliations' : project_dir + '/log/sortinghat_affiliations.log',
'sortinghat' : project_dir + '/log/sortinghat.log',
'pullpo' : project_dir + '/log/retrieval_pullpo.log',
'eventizer' : project_dir + '/log/retrieval_eventizer.log',
'identities' : project_dir + '/log/identities.log',
}
def read_main_conf():
parser = SafeConfigParser()
conf_file = project_dir + '/conf/main.conf'
fd = open(conf_file, 'r')
parser.readfp(fd)
fd.close()
sec = parser.sections()
for s in sec:
options[s] = {}
opti = parser.options(s)
for o in opti:
# first, some special cases
if o == 'debug':
options[s][o] = parser.getboolean(s,o)
elif o in ('trackers', 'projects', 'pre_scripts', 'post_scripts'):
data_sources = parser.get(s,o).split(',')
options[s][o] = [ds.replace('\n', '') for ds in data_sources]
else:
options[s][o] = parser.get(s,o)
return options
def repositories(file_path):
""" Returns the list of repositories found in file_path
:param file_patch: file where the repositories are found
:returns: a list of repositories
"""
global conf_dir
file_path = os.path.join(conf_dir, file_path)
repositories = open(file_path).read().splitlines()
return repositories
# git specific: search all repos in a directory recursively
def get_scm_repos(dir = scm_dir):
all_repos = []
if (dir == ''): dir = scm_dir
if not os.path.isdir(dir): return all_repos
repos = os.listdir(dir)
for r in repos:
repo_dir_git = os.path.join(dir,r,".git")
repo_dir_svn = os.path.join(dir,r,".svn")
if os.path.isdir(repo_dir_git) or os.path.isdir(repo_dir_svn):
all_repos.append(os.path.join(dir,r))
sub_repos = get_scm_repos(os.path.join(dir,r))
for sub_repo in sub_repos:
all_repos.append(sub_repo)
return all_repos
def update_scm(scm_log, dir = scm_dir):
main_log.info("SCM is being updated")
repos = get_scm_repos()
updated = False
log_file = log_files['cvsanaly']
for r in repos:
os.chdir(r)
if os.path.isdir(os.path.join(dir,r,".git")):
os.system("GIT_ASKPASS=echo git fetch origin >> %s 2>&1" %(log_file))
errcode = os.system("GIT_ASKPASS=echo git reset --hard origin/master -- >> %s 2>&1" %(log_file))
if errcode != 0:
# Sometimes master branch does not exists and it's replaced by trunk
os.system("GIT_ASKPASS=echo git reset --hard origin/trunk -- >> %s 2>&1" %(log_file))
elif os.path.isdir(os.path.join(dir,r,".svn")):
os.system("svn update >> %s 2>&1" %(log_file))
else: scm_log.info(r + " not git nor svn.")
scm_log.info(r + " update ended")
if updated: main_log.info("[OK] SCM updated")
def check_tool(cmd):
return os.path.isfile(cmd) and os.access(cmd, os.X_OK)
return True
def check_tools():
tools_ok = True
for tool in tools:
if not check_tool(tools[tool]):
main_log.info(tools[tool]+" not found or not executable.")
tools_ok = False
if not tools_ok:
main_log.info("Missing tools. Some reports could not be created.")
def launch_checkdbs():
dbs = []
db_user = options['generic']['db_user']
db_password = options['generic']['db_password']
if options['generic'].has_key('db_identities'):
dbs.append(options['generic']['db_identities'])
if options['generic'].has_key('db_cvsanaly'):
dbs.append(options['generic']['db_cvsanaly'])
if options['generic'].has_key('db_bicho'):
dbs.append(options['generic']['db_bicho'])
if options['generic'].has_key('db_bicho_1'):
dbs.append(options['generic']['db_bicho_1'])
# mlstats creates the db if options['generic'].has_key('db_mlstats'):
if options['generic'].has_key('db_gerrit'):
dbs.append(options['generic']['db_gerrit'])
if options['generic'].has_key('db_irc'):
dbs.append(options['generic']['db_irc'])
if options['generic'].has_key('db_mediawiki'):
dbs.append(options['generic']['db_mediawiki'])
if options['generic'].has_key('db_releases'):
dbs.append(options['generic']['db_releases'])
# LEGACY qaforums. Use sibyl in new deployments.
if options['generic'].has_key('db_qaforums'):
dbs.append(options['generic']['db_qaforums'])
if options['generic'].has_key('db_sibyl'):
dbs.append(options['generic']['db_sibyl'])
if options['generic'].has_key('db_downloads'):
dbs.append(options['generic']['db_downloads'])
if options['generic'].has_key('db_pullpo'):
dbs.append(options['generic']['db_pullpo'])
if options['generic'].has_key('db_eventizer'):
dbs.append(options['generic']['db_eventizer'])
# sortinghat creates the db itself if options['generic'].has_key('db_sortinghat'):
if options['generic'].has_key('db_projects'):
dbs.append(options['generic']['db_projects'])
# Octopus db
if options['generic'].has_key('db_octopus'):
dbs.append(options['generic']['db_octopus'])
for dbname in dbs:
try:
db = MySQLdb.connect(user = db_user, passwd = db_password, db = dbname)
db.close()
except:
main_log.error("Can't connect to " + dbname)
print("ERROR: Can't connect to " + dbname)
db = MySQLdb.connect(user = db_user, passwd = db_password)
cursor = db.cursor()
query = "CREATE DATABASE " + dbname + " CHARACTER SET utf8"
cursor.execute(query)
db.close()
main_log.info(dbname+" created")
def launch_scripts(scripts):
# Run a list of scripts
for script in scripts:
cmd = os.path.join(scripts_dir, script) + " >> %s 2>&1" % msg_body
main_log.info("Running %s" % cmd)
os.system(cmd)
main_log.info("%s script completed" % script)
def launch_pre_tool_scripts(tool):
if tool not in options:
return
if options[tool].has_key('pre_scripts'):
main_log.info("Running %s pre scripts" % tool)
launch_scripts(options[tool]['pre_scripts'])
main_log.info("%s pre scripts completed" % tool)
else:
main_log.info("No %s pre scripts configured" % tool)
def launch_post_tool_scripts(tool):
if tool not in options:
return
if options[tool].has_key('post_scripts'):
main_log.info("Running %s post scripts" % tool)
launch_scripts(options[tool]['post_scripts'])
main_log.info("%s post scripts completed" % tool)
else:
main_log.info("No %s post scripts configured" % tool)
def launch_cvsanaly():
log_file = log_files['cvsanaly']
cvsanaly_log = logs(log_file, MAX_LOG_BYTES, MAX_LOG_FILES)
# using the conf executes cvsanaly for the repos inside scm dir
if options.has_key('cvsanaly'):
if not check_tool(tools['scm']):
return
update_scm(cvsanaly_log)
main_log.info("cvsanaly is being executed")
launched = False
db_name = options['generic']['db_cvsanaly']
db_user = options['generic']['db_user']
db_pass = options['generic']['db_password']
if (db_pass == ""): db_pass = "''"
# we launch cvsanaly against the repos
repos = get_scm_repos()
# pre-scripts
launch_pre_tool_scripts('cvsanaly')
for r in repos:
launched = True
os.chdir(r)
if options['cvsanaly'].has_key('extensions'):
cmd = tools['scm'] + " -u %s -p %s -d %s --extensions=%s >> %s 2>&1" \
%(db_user, db_pass, db_name, options['cvsanaly']['extensions'], log_file)
else:
cmd = tools['scm'] + " -u %s -p %s -d %s >> %s 2>&1" \
%(db_user, db_pass, db_name, log_file)
cvsanaly_log.info(cmd)
os.system(cmd)
if launched:
main_log.info("[OK] cvsanaly executed")
# post-scripts
launch_post_tool_scripts('cvsanaly')
else:
main_log.info("[skipped] cvsanaly was not executed")
else:
main_log.info("[skipped] cvsanaly not executed, no conf available")
def launch_bicho(section = None):
do_bicho('bicho')
# find additional configs
do_bicho('bicho_1')
def do_bicho(section = None):
# reads a conf file with all of the information and launches bicho
if section is None: section = 'bicho'
if not section.startswith("bicho"):
main_log.error("Wrong bicho section name " + section)
if options.has_key(section):
if not check_tool(tools['its']):
return
main_log.info("bicho is being executed")
launched = False
database = options['generic']['db_' + section]
db_user = options['generic']['db_user']
db_pass = options['generic']['db_password']
delay = options[section]['delay']
backend = options[section]['backend']
backend_user = backend_password = None
backend_token = None
num_issues_query = None
if options[section].has_key('backend_user'):
backend_user = options[section]['backend_user']
if options[section].has_key('backend_password'):
backend_password = options[section]['backend_password']
if options[section].has_key('backend_token'):
backend_token = options[section]['backend_token']
if options[section].has_key('num-issues-query'):
num_issues_query = options[section]['num-issues-query']
# Retrieving trackers from config file or from an external config file
if options[section].has_key('trackers'):
trackers = options[section]['trackers']
else:
trackers = repositories(BICHO_TRACKERS)
if section == "bicho_1" and not options[section].has_key('trackers'):
trackers = repositories(BICHO_1_TRACKERS)
log_table = None
debug = options[section]['debug']
if options[section].has_key('log_table'):
log_table = options[section]['log_table']
log_file = log_files['bicho']
bicho_log = logs(log_file, MAX_LOG_BYTES, MAX_LOG_FILES)
# we compose some flags
flags = ""
if debug:
flags = flags + " -g"
# we'll only create the log table in the last execution
cont = 0
last = len(trackers)
# pre-scripts
launch_pre_tool_scripts(section)
for t in trackers:
launched = True
cont = cont + 1
if cont == last and log_table:
flags = flags + " -l"
user_opt = ''
# Authentication parameters
if backend_token:
user_opt = '--backend-token=%s' % (backend_token)
elif backend_user and backend_password:
user_opt = '--backend-user=%s --backend-password=%s' % (backend_user, backend_password)
if num_issues_query:
user_opt = user_opt + ' --num-issues=%s' % (num_issues_query)
cmd = tools['its'] + " --db-user-out=%s --db-password-out=%s --db-database-out=%s -d %s -b %s %s -u %s %s >> %s 2>&1" \
% (db_user, db_pass, database, str(delay), backend, user_opt, t, flags, log_file)
bicho_log.info(cmd)
os.system(cmd)
if launched:
main_log.info("[OK] bicho executed")
# post-scripts
launch_post_tool_scripts(section)
else:
main_log.info("[skipped] bicho was not executed")
else:
main_log.info("[skipped] bicho not executed, no conf available for " + section)
def launch_gather():
""" This tasks will execute in parallel all data gathering tasks """
main_log.info("Executing all data gathering tasks in parallel")
from multiprocessing import Process, active_children
gather_tasks_order = ['cvsanaly','bicho','gerrit','mlstats',
'irc','mediawiki', 'downloads', 'sibyl',
'octopus','pullpo','eventizer']
for section in gather_tasks_order:
p = Process(target=tasks_section_gather[section])
p.start()
# Wait until all processes finish
while True:
active = active_children()
if len(active) == 0:
break
else:
time.sleep(0.5)
def remove_gerrit_repositories(repositories, db_user, db_pass, database):
for project in repositories:
main_log.info("Removing %s " % (project))
# Remove not found projects.
# WARNING: if a repository name is different from the one in the database
# list of repositories, this piece of code may remove all
# of the repositories in the database.
# An example would be how Gerrit returns the name of the projects, while
# Bicho stores such information in URL format.
proc = subprocess.Popen([tools['rremoval'], "-u", db_user, "-p", db_pass,
"-d", database, "-b", "bicho", "-r", project],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process_output = proc.communicate()
def update_gerrit_repositories(db_user, db_pass, database, trackers):
# Retrieving projects from database
proc = subprocess.Popen([tools['rremoval'], "-u", db_user, "-p", db_pass,
"-d", database, "-b", "bicho", "-l"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process_output = proc.communicate()
db_projects = eval(process_output[0])
# Retrieving projects
if options['gerrit'].has_key('projects'):
projects = options['gerrit']['projects']
projects = [str(trackers[0]) + "_" + project.replace('"', '') for project in projects]
else:
all_projects = repositories(repos_dir + GERRIT_PROJECTS)
# Open repositories to be analyzed
projects_blacklist = repositories(repos_dir + GERRIT_PROJECTS_BLACKLIST)
projects = [project for project in all_projects if project not in projects_blacklist ]
# Using format from Bicho database to manage Gerrit URLs
projects = [str(trackers[0]) + "_" + project for project in projects]
projects_blacklist = [str(trackers[0]) + "_" + project for project in projects_blacklist]
# Removing blacklist projects if they are found in the database
projects_blacklist = [project for project in projects_blacklist if project in db_projects]
main_log.info("Removing the following projects found in the blacklist and in the database")
# Checking if more than a 5% of the total list is going to be removed.
# If so, a warning message is raised and no project is removed.
if len(projects) == 0 or float(len(projects_blacklist))/float(len(projects)) > 0.05:
main_log.info("WARNING: More than a 5% of the total number of projects is required to be removed. No action.")
else:
remove_gerrit_repositories(projects_blacklist, db_user, db_pass, database)
# Removing those projects that are found in the database, but not in
# the list of projects.
to_remove_projects = [project for project in db_projects if project not in projects]
main_log.info("Removing the following deprecated projects from the database")
if len(projects) == 0 or float(len(to_remove_projects)) / float(len(projects)) >= 0.05:
main_log.info("WARNING: More than a 5% of the total number of projects is required to be removed. No action.")
else:
remove_gerrit_repositories(to_remove_projects, db_user, db_pass, database) # Retrieving projects
if options['gerrit'].has_key('projects'):
projects = options['gerrit']['projects']
projects = [str(trackers[0]) + "_" + project.replace('"', '') for project in projects]
else:
all_projects = repositories(repos_dir + GERRIT_PROJECTS)
# Open repositories to be analyzed
projects_blacklist = repositories(repos_dir + GERRIT_PROJECTS_BLACKLIST)
projects = [project for project in all_projects if project not in projects_blacklist ]
# Using format from Bicho database to manage Gerrit URLs
projects = [str(trackers[0]) + "_" + project for project in projects]
projects_blacklist = [str(trackers[0]) + "_" + project for project in projects_blacklist]
# Removing blacklist projects if they are found in the database
projects_blacklist = [project for project in projects_blacklist if project in db_projects]
main_log.info("Removing the following projects found in the blacklist and in the database")
# Checking if more than a 5% of the total list is going to be removed.
# If so, a warning message is raised and no project is removed.
if len(projects) == 0 or float(len(projects_blacklist))/float(len(projects)) > 0.05:
main_log.info("WARNING: More than a 5% of the total number of projects is required to be removed. No action.")
else:
remove_gerrit_repositories(projects_blacklist, db_user, db_pass, database)
# Removing those projects that are found in the database, but not in
# the list of projects.
to_remove_projects = [project for project in db_projects if project not in projects]
main_log.info("Removing the following deprecated projects from the database")
if len(projects) == 0 or float(len(to_remove_projects)) / float(len(projects)) >= 0.05:
main_log.info("WARNING: More than a 5% of the total number of projects is required to be removed. No action.")
else:
remove_gerrit_repositories(to_remove_projects, db_user, db_pass, database)
return projects
def launch_gerrit():
# reads a conf file with all of the information and launches bicho
if options.has_key('gerrit'):
backend = options['gerrit']['backend']
if not check_tool(tools['scr']):
return
main_log.info("bicho (gerrit) is being executed")
launched = False
database = options['generic']['db_gerrit']
db_user = options['generic']['db_user']
db_pass = options['generic']['db_password']
delay = options['gerrit']['delay']
backend = options['gerrit']['backend']
trackers = options['gerrit']['trackers']
debug = options['gerrit']['debug']
log_table = None
if options['gerrit'].has_key('log_table'):
log_table = options['gerrit']['log_table']
log_file = log_files['gerrit']
gerrit_log = logs(log_file, MAX_LOG_BYTES, MAX_LOG_FILES)
flags = ""
if debug:
flags = flags + " -g"
if backend == 'gerrit':
projects = update_gerrit_repositories(db_user, db_pass, database, trackers)
projects = [project.replace(str(trackers[0]) + "_", "") for project in projects]
elif backend == 'reviewboard':
projects = options['gerrit']['projects']
projects = [str(trackers[0]) + "/groups/" + project.replace('"', '') for project in projects]
else:
main_log.info("[skipped] bicho (gerrit) not executed. Backend %s not found." % backend)
return
# pre-scripts
launch_pre_tool_scripts('gerrit')
# we'll only create the log table in the last execution
cont = 0
last = len(projects)
# Re-formating the projects name
for project in projects:
launched = True
cont = cont + 1
if cont == last and log_table:
flags = flags + " -l"
g_user = ''
if options['gerrit'].has_key('user'):
g_user = '--backend-user ' + options['gerrit']['user']
if backend == 'gerrit':
cmd = tools['scr'] + " --db-user-out=%s --db-password-out=%s --db-database-out=%s -d %s -b %s %s -u %s --gerrit-project=%s %s >> %s 2>&1" \
% (db_user, db_pass, database, str(delay), backend, g_user, trackers[0], project, flags, log_file)
elif backend == 'reviewboard':
cmd = tools['scr'] + " --db-user-out=%s --db-password-out=%s --db-database-out=%s -d %s -b %s -u %s %s >> %s 2>&1" \
% (db_user, db_pass, database, str(delay), backend, project, flags, log_file)
else:
main_log.info("[skipped] bicho (gerrit) not executed. Backend %s not found." % backend)
return
gerrit_log.info(cmd)
os.system(cmd)
if launched:
main_log.info("[OK] bicho (gerrit) executed")
# post-scripts
launch_post_tool_scripts('gerrit')
else:
main_log.info("[skipped] bicho (gerrit) not executed")
else:
main_log.info("[skipped] bicho (gerrit) not executed, no conf available")
def launch_mlstats():
if options.has_key('mlstats'):
if not check_tool(tools['mls']):
return
main_log.info("mlstats is being executed")
launched = False
db_admin_user = options['generic']['db_user']
db_user = db_admin_user
db_pass = options['generic']['db_password']
db_name = options['generic']['db_mlstats']
# Retrieving mailing lists
if options['mlstats'].has_key('mailing_lists'):
mlists = options['mlstats']['mailing_lists'].split(",")
mlists = [m.strip(' "') for m in mlists]
else:
mlists = repositories(MLSTATS_MAILING_LISTS)
force = ''
if options['mlstats'].has_key('force'):
if options['mlstats']['force'] is True:
force = '--force'
log_file = log_files['mlstats']
mlstats_log = logs(log_file, MAX_LOG_BYTES, MAX_LOG_FILES)
# pre-scripts
launch_pre_tool_scripts('mlstats')
for m in mlists:
launched = True
cmd = tools['mls'] + " %s --no-report --db-user=\"%s\" --db-password=\"%s\" --db-name=\"%s\" --db-admin-user=\"%s\" --db-admin-password=\"%s\" \"%s\" >> %s 2>&1" \
%(force, db_user, db_pass, db_name, db_admin_user, db_pass, m, log_file)
mlstats_log.info(cmd)
os.system(cmd)
if launched:
main_log.info("[OK] mlstats executed")
# post-scripts
launch_post_tool_scripts('mlstats')
else:
main_log.info("[skipped] mlstats not executed")
else:
main_log.info("[skipped] mlstats was not executed, no conf available")
def launch_irc():
if options.has_key('irc'):
if not check_tool(tools['irc']):
return
main_log.info("irc_analysis is being executed")
launched = False
db_admin_user = options['generic']['db_user']
db_user = db_admin_user
db_pass = options['generic']['db_password']
db_name = options['generic']['db_irc']
format = 'plain'
if options['irc'].has_key('format'):
format = options['irc']['format']
channels = os.listdir(irc_dir)
os.chdir(irc_dir)
log_file = log_files['irc']
irc_log = logs(log_file, MAX_LOG_BYTES, MAX_LOG_FILES)
# pre-scripts
launch_pre_tool_scripts('irc')
if format == 'slack':
if options['irc'].has_key('token'):
token = options['irc']['token']
launched = True
cmd = tools['irc'] + " --db-user=\"%s\" --db-password=\"%s\" --database=\"%s\" --token %s --format %s>> %s 2>&1" \
% (db_user, db_pass, db_name, token, format, log_file)
irc_log.info(cmd)
os.system(cmd)
else:
main_log.error("Slack IRC supports need token option.")
else:
for channel in channels:
if not os.path.isdir(os.path.join(irc_dir,channel)): continue
launched = True
cmd = tools['irc'] + " --db-user=\"%s\" --db-password=\"%s\" --database=\"%s\" --dir=\"%s\" --channel=\"%s\" --format %s>> %s 2>&1" \
% (db_user, db_pass, db_name, channel, channel, format, log_file)
irc_log.info(cmd)
os.system(cmd)
if launched:
main_log.info("[OK] irc_analysis executed")
# post-scripts
launch_post_tool_scripts('irc')
else:
main_log.info("[skipped] irc_analysis not executed")
else:
main_log.info("[skipped] irc_analysis was not executed, no conf available")
def launch_mediawiki():
if options.has_key('mediawiki'):
backend = options['mediawiki']['backend']
if backend == 'mediawiki':
launch_mediawiki_analysis()
elif backend == 'confluence':
launch_confluence_analysis()
else:
main_log.info("[skipped] mediawiki %s backend not available" % backend)
else:
main_log.info("[skipped] mediawiki was not executed, no conf available")
def launch_mediawiki_analysis():
if options.has_key('mediawiki'):
if not check_tool(tools['mediawiki']):
return
main_log.info("mediawiki_analysis is being executed")
launched = False
db_admin_user = options['generic']['db_user']
db_user = db_admin_user
db_pass = options['generic']['db_password']
db_name = options['generic']['db_mediawiki']
sites = options['mediawiki']['sites']
log_file = log_files['mediawiki']
mediawiki_log = logs(log_file, MAX_LOG_BYTES, MAX_LOG_FILES)
# pre-scripts
launch_pre_tool_scripts('mediawiki')
for site in sites.split(","):
launched = True
# ./mediawiki_analysis.py --database acs_mediawiki_rdo_2478 --db-user root --url http://openstack.redhat.com
cmd = tools['mediawiki'] + " --db-user=\"%s\" --db-password=\"%s\" --database=\"%s\" --url=\"%s\" >> %s 2>&1" \
%(db_user, db_pass, db_name, sites, log_file)
mediawiki_log.info(cmd)
os.system(cmd)
if launched:
main_log.info("[OK] mediawiki_analysis executed")
# post-scripts
launch_post_tool_scripts('mediawiki')
else:
main_log.info("[skipped] mediawiki_analysis not executed")
else:
main_log.info("[skipped] mediawiki_analysis was not executed, no conf available")
def launch_confluence_analysis():
if options.has_key('mediawiki'):
if not check_tool(tools['confluence']):
return
main_log.info("confluence_analysis is being executed")
launched = False
db_admin_user = options['generic']['db_user']
db_user = db_admin_user
db_pass = options['generic']['db_password']
db_name = options['generic']['db_mediawiki']
url = options['mediawiki']['url']
spaces = options['mediawiki']['spaces']
log_file = log_files['confluence']
confluence_log = logs(log_file, MAX_LOG_BYTES, MAX_LOG_FILES)
# pre-scripts
launch_pre_tool_scripts('mediawiki')
for space in spaces.split(","):
launched = True
# ./confluence_analysis.py -d acs_confluence_geode -u root -p root https://cwiki.apache.org/confluence/
cmd = tools['confluence'] + " -u \"%s\" -p \"%s\" -d \"%s\" \"%s\" \"%s\" >> %s 2>&1" \
% (db_user, db_pass, db_name, url, space, log_file)
confluence_log.info(cmd)
os.system(cmd)
if launched:
main_log.info("[OK] confluence_analysis executed")
# post-scripts
launch_post_tool_scripts('mediawiki')
else:
main_log.info("[skipped] confluence_analysis not executed")
else:
main_log.info("[skipped] confluence_analysis was not executed, no conf available")
def launch_downloads():
# check if downloads option exists. If it does, downloads are executed
if options.has_key('downloads'):
main_log.info("downloads does not execute any tool. Only pre and post scripts")
# pre-scripts
launch_pre_tool_scripts('downloads')
# post-scripts
launch_post_tool_scripts('downloads')
def launch_sibyl():
# check if sibyl option exists
if options.has_key('sibyl'):
if not check_tool(tools['sibyl']):
return
if not options['sibyl'].has_key('url'):
return
main_log.info("sibyl is being executed")
launched = False
db_user = options['generic']['db_user']
db_pass = options['generic']['db_password']
# db_name = options['generic']['db_qaforums']
db_name = options['generic']['db_sibyl']
url = options['sibyl']['url']
backend = options['sibyl']['backend']
api_key = tags = ""
if 'api_key' in options['sibyl']:
api_key = " -k \"" + options['sibyl']['api_key'] + "\""
if 'tags' in options['sibyl']:
tags = " --tags \"" + options['sibyl']['tags'] + "\""
log_file = log_files['sibyl']
sibyl_log = logs(log_file, MAX_LOG_BYTES, MAX_LOG_FILES)
# pre-scripts
launch_pre_tool_scripts('sibyl')
cmd = tools['sibyl'] + " --db-user=\"%s\" --db-password=\"%s\" --database=\"%s\" --url=\"%s\" --type=\"%s\" %s %s >> %s 2>&1" \
%(db_user, db_pass, db_name, url, backend, api_key, tags, log_file)
sibyl_log.info(cmd)
os.system(cmd)
# TODO: it's needed to check if the process correctly finished
launched = True
if launched:
main_log.info("[OK] sibyl executed")
else:
main_log.info("[skipped] sibyl not executed")
else:
main_log.info("[skipped] sibyl was not executed, no conf available")
def pull_directory(path):
pr = subprocess.Popen(['/usr/bin/git', 'fetch', 'origin'],
cwd=os.path.dirname(path),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
(out, error) = pr.communicate()
pr = subprocess.Popen(['/usr/bin/git', 'reset', '--hard', 'origin/master', '--'],
cwd=os.path.dirname(path),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
(out, error) = pr.communicate()
def push_directory(path):
pr = subprocess.Popen(['/usr/bin/git', 'add', './*'],
cwd=os.path.dirname(path),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
(out, error) = pr.communicate()
pr = subprocess.Popen(['/usr/bin/git', 'commit', '-m', 'Updated by the Owl Bot'],
cwd=os.path.dirname(path),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
(out, error) = pr.communicate()
pr = subprocess.Popen(['/usr/bin/git', 'push', 'origin', 'master'],
cwd=os.path.dirname(path),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
(out, error) = pr.communicate()
def launch_octopus():
launch_octopus_puppet()
launch_octopus_docker()
launch_octopus_github()
launch_octopus_gerrit()
def launch_octopus_export(cmd, backend):
""" Exports the list of repositories to the specific config file"""
# Adding the '--export' option, this disables the rest of the Octopus options
cmd = cmd + ' --export '
if backend == 'puppet':
output = PUPPET_RELEASES
elif backend == 'docker':
output = DOCKER_PACKAGES
elif backend == 'github':
output = CVSANALY_REPOSITORIES
elif backend == 'gerrit':
output = GERRIT_PROJECTS
if not os.path.isdir(repos_dir):
main_log.info("WARNING: '" + repos_dir + "' does not exist")
if os.path.isdir(repos_dir):
# This tries to fetch and push new data when exporting octopus info
pull_directory(repos_dir)
os.system(cmd + " > " + repos_dir + output)
if os.path.isdir(repos_dir):
# This tries to push new changes in the file
push_directory(repos_dir)
def launch_octopus_puppet():
# check if octopus_puppet option exists
if options.has_key('octopus_puppet'):