multirunner.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # -*- coding: utf-8 -*-
  2. from __future__ import print_function
  3. import sys
  4. import os
  5. import argparse
  6. import itertools
  7. import subprocess
  8. def main():
  9. parser = argparse.ArgumentParser(
  10. description='Run tests with new')
  11. parser.add_argument('--location', '-l', required=True, action='append',
  12. dest='locations', metavar='LOCATION',
  13. help='Directories with reports')
  14. parser.add_argument('--location-type', '-t', action='append',
  15. dest='location_types',
  16. default=[], metavar='TYPE',
  17. help='Add repeated values to a list',
  18. )
  19. parser.add_argument('--grassbin', required=True,
  20. help='Use file timestamp instead of date in test summary')
  21. # TODO: rename since every src can be used?
  22. parser.add_argument('--grasssrc', required=True,
  23. help='GRASS GIS source code (to take tests from)')
  24. parser.add_argument('--grassdata', required=True,
  25. help='GRASS GIS data base (GISDBASE)')
  26. parser.add_argument('--create-main-report',
  27. help='Create also main report for all tests',
  28. action="store_true", default=False, dest='main_report')
  29. args = parser.parse_args()
  30. gisdb = args.grassdata
  31. locations = args.locations
  32. locations_types = args.location_types
  33. # TODO: if locations empty or just one we can suppose the same all the time
  34. if len(locations) != len(locations_types):
  35. print("ERROR: Number of locations and their tags must be the same", file=sys.stderr)
  36. return 1
  37. main_report = args.main_report
  38. grasssrc = args.grasssrc # TODO: can be guessed from dist
  39. # TODO: create directory accoring to date and revision and create reports there
  40. # some predefined variables, name of the GRASS launch script + location/mapset
  41. #grass7bin = 'C:\Program Files (x86)\GRASS GIS 7.0.svn\grass70svn.bat'
  42. grass7bin = args.grassbin # TODO: can be used if pressent
  43. ########### SOFTWARE
  44. # query GRASS 7 itself for its GISBASE
  45. # we assume that GRASS GIS' start script is available and in the PATH
  46. # the shell=True is here because of MS Windows? (code taken from wiki)
  47. startcmd = grass7bin + ' --config path'
  48. p = subprocess.Popen(startcmd, shell=True,
  49. stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  50. out, err = p.communicate()
  51. if p.returncode != 0:
  52. print("ERROR: Cannot find GRASS GIS 7 start script (%s):\n%s" % (startcmd, err), file=sys.stderr)
  53. return 1
  54. gisbase = out.strip('\n')
  55. # set GISBASE environment variable
  56. os.environ['GISBASE'] = gisbase
  57. # define GRASS Python environment
  58. grass_python_dir = os.path.join(gisbase, "etc", "python")
  59. sys.path.append(grass_python_dir)
  60. ########### DATA
  61. # define GRASS DATABASE
  62. # Set GISDBASE environment variable
  63. os.environ['GISDBASE'] = gisdb
  64. # import GRASS Python package for initialization
  65. import grass.script.setup as gsetup
  66. # launch session
  67. # we need some location and mapset here
  68. # TODO: can init work without it or is there some demo location in dist?
  69. location = locations[0].split(':')[0]
  70. mapset = 'PERMANENT'
  71. gsetup.init(gisbase, gisdb, location, mapset)
  72. reports = []
  73. for location, location_type in itertools.izip(locations, locations_types):
  74. # here it is quite a good place to parallelize
  75. # including also type to make it unique and preserve it for sure
  76. report = 'report_for_' + location + '_' + location_type
  77. absreport = os.path.abspath(report)
  78. p = subprocess.Popen([sys.executable, '-tt',
  79. '-m', 'grass.gunittest.main',
  80. '--grassdata', gisdb, '--location', location,
  81. '--location-type', location_type,
  82. '--output', absreport],
  83. cwd=grasssrc)
  84. returncode = p.wait()
  85. reports.append(report)
  86. if main_report:
  87. # TODO: solve the path to source code (work now only for grass source code)
  88. arguments = [sys.executable, grasssrc + '/lib/python/guittest/' + 'multireport.py', '--timestapms']
  89. arguments.extend(reports)
  90. p = subprocess.Popen(arguments)
  91. returncode = p.wait()
  92. if returncode != 0:
  93. print("ERROR: Creation of main report failed.", file=sys.stderr)
  94. return 1
  95. return 0
  96. if __name__ == '__main__':
  97. sys.exit(main())