55#
66# (c) Matthias Büchse <matthias.buechse@cloudandheat.com>
77# SPDX-License-Identifier: Apache-2.0
8+ from datetime import date
89import logging
910import os
1011import os .path
@@ -68,12 +69,14 @@ def get_subject_mapping(self, subject):
6869 def abspath (self , path ):
6970 return os .path .join (self .cwd , path )
7071
71- def build_check_command (self , scope , subject , output ):
72+ def build_check_command (self , scope , subject , sections , output ):
7273 # TODO figure out when to supply --debug here (but keep separated from our --debug)
7374 args = [
7475 sys .executable , self .scs_compliance_check , self .abspath (self .scopes [scope ]['spec' ]),
7576 '--debug' , '-C' , '-o' , output , '-s' , subject ,
7677 ]
78+ if sections :
79+ args .extend (['--sections' , sections ])
7780 for key , value in self .get_subject_mapping (subject ).items ():
7881 args .extend (['-a' , f'{ key } ={ value } ' ])
7982 return {'args' : args }
@@ -173,12 +176,13 @@ def _move_file(source_path, target_path):
173176@cli .command ()
174177@click .option ('--scope' , 'scopes' , type = str )
175178@click .option ('--subject' , 'subjects' , type = str )
179+ @click .option ('--section' , 'sections' , type = str )
176180@click .option ('--preset' , 'preset' , type = str )
177181@click .option ('--num-workers' , 'num_workers' , type = int , default = 5 )
178182@click .option ('--monitor-url' , 'monitor_url' , type = str , default = MONITOR_URL )
179183@click .option ('-o' , '--output' , 'report_yaml' , type = click .Path (exists = False ), default = None )
180184@click .pass_obj
181- def run (cfg , scopes , subjects , preset , num_workers , monitor_url , report_yaml ):
185+ def run (cfg , scopes , subjects , sections , preset , num_workers , monitor_url , report_yaml ):
182186 """
183187 run compliance tests and upload results to compliance monitor
184188 """
@@ -196,13 +200,23 @@ def run(cfg, scopes, subjects, preset, num_workers, monitor_url, report_yaml):
196200 subjects = [subject .strip () for subject in subjects .split (',' )] if subjects else []
197201 if not scopes or not subjects :
198202 raise click .UsageError ('both scope(s) and subject(s) must be non-empty' )
203+ if sections == '.auto' :
204+ today = date .today ()
205+ # https://docs.python.org/3/library/datetime.html#datetime.date.weekday
206+ # Return the day of the week as an integer, where Monday is 0 and Sunday is 6.
207+ weekday = today .weekday ()
208+ if weekday == 5 : # Saturday
209+ sections = 'light,medium,heavy'
210+ else :
211+ sections = 'light,medium'
212+ logger .info (f'auto-selected sections: { sections } ' )
199213 logger .debug (f'running tests for scope(s) { ", " .join (scopes )} and subject(s) { ", " .join (subjects )} ' )
200214 logger .debug (f'monitor url: { monitor_url } , num_workers: { num_workers } , output: { report_yaml } ' )
201215 with tempfile .TemporaryDirectory (dir = cfg .cwd ) as tdirname :
202216 report_yaml_tmp = os .path .join (tdirname , 'report.yaml' )
203217 jobs = [(scope , subject ) for scope in scopes for subject in subjects ]
204218 outputs = [os .path .join (tdirname , f'report-{ idx } .yaml' ) for idx in range (len (jobs ))]
205- commands = [cfg .build_check_command (job [0 ], job [1 ], output ) for job , output in zip (jobs , outputs )]
219+ commands = [cfg .build_check_command (job [0 ], job [1 ], sections , output ) for job , output in zip (jobs , outputs )]
206220 _run_commands (commands , num_workers = num_workers )
207221 _concat_files (outputs , report_yaml_tmp )
208222 subprocess .run (** cfg .build_sign_command (report_yaml_tmp ))
0 commit comments