@@ -528,62 +528,136 @@ def compile_all_sketches(self, url, selector, **kwargs):
528
528
assert len (sketches ) > 0
529
529
self .compile_sketches (sketches , ** kwargs )
530
530
531
- def compile_sketches (self , sketches , iframe = False , project_view = False , logfile = None , compile_type = 'sketch' , create_report = False , comment = False ):
532
- """Compiles the sketches with URLs given by the `sketches` list.
533
- `logfile` specifies a path to a file to which test results will be
534
- logged. If it is not `None`, compile errors will not cause the test
535
- to halt, but rather be logged to the given file. `logfile` may be a time
536
- format string, which will be formatted appropriately.
537
- `iframe` specifies whether the urls pointed to by `selector` are contained
538
- within an iframe.
539
- If the `--full` argument is provided (and hence
540
- `self.run_full_compile_tests` is `True`, we do not log, and limit the
541
- number of sketches compiled to 1.
531
+ def resume_log (self , logfile , compile_type , sketches ):
532
+ """Resume previous log, if any. Coves 3 cases:
533
+ Case 1: Test runs for 1st time and there is no previous log file.
534
+ Case 2: Test runs for 2nd time and there is a previous log file which contains
535
+ some of the urls that should be compiled and log file should be completed with
536
+ the rest.
537
+ Case 3: Test runs for 2nd time and there is a previous log file which contains
538
+ all the urls that should be compiled and test should be run again for all urls.
542
539
"""
543
-
544
- # Log filename
540
+ """Creates a variable in which current date and time are stored."""
545
541
log_time = gmtime ()
546
- # Keeps the logs of each compile
542
+
543
+ """Creates an empty dictionary each time that a test runs."""
547
544
log_entry = {}
548
545
546
+ """Creates an empty dictionary each time that a test runs."""
549
547
urls_visited = {}
548
+
549
+ """Calls `read_last_log` function and checks if there is a previous log file
550
+ of the same compile_type (e.g. sketch). If there is, a dictionary containing
551
+ `timestamp` and `log` keys with their corresponding values is returned.
552
+ Otherwise, a dictionary where `timestamp` and `log` values are `None` is returned.
553
+ No previous log:
554
+ {'timestamp': None, 'log': None}
555
+ Previous log exists:
556
+ {'timestamp': '2016-02-14_10-42-17',
557
+ 'log': {
558
+ 'https://staging.codebender.cc/sketch:30360': {'success': ['Arduino Uno']},
559
+ 'https://staging.codebender.cc/sketch:30352': {'success': ['Arduino Uno']}
560
+ }
561
+ }
562
+ """
550
563
last_log = read_last_log (compile_type )
551
- if compile_type != 'target_library' and last_log ['log' ]:
552
- # resume previous compile
553
- log_time = strptime (last_log ['timestamp' ], '%Y-%m-%d_%H-%M-%S' )
554
- log_entry = last_log ['log' ]
555
- for url in last_log ['log' ]:
556
- urls_visited [url ] = True
557
564
565
+ if compile_type != 'target_library' and last_log ['log' ]:
566
+ """Checks if `last_log[log]` has a value (is not `None`).
567
+ If it has, this means that there is a log file created previously and dictionaries
568
+ `log_entry` and `urls_visited` should be updated.
569
+ {'timestamp': '2016-02-14_12-44-16',
570
+ 'log': {
571
+ 'https://staging.codebender.cc/sketch:30360': {'success': ['Arduino Uno']},
572
+ 'https://staging.codebender.cc/sketch:30352': {'success': ['Arduino Uno']}
573
+ }
574
+ }
575
+ """
576
+ if last_log ['log' ]:
577
+ log_time = strptime (last_log ['timestamp' ], '%Y-%m-%d_%H-%M-%S' )
578
+
579
+ """ Test has stopped its execution for some reason, (e.g.to avoid saucelabs timeout)
580
+ and `log_entry` dictionary will be filled with the entries of `last_log[log]` values.
581
+ log_entry = {'https://staging.codebender.cc/sketch:30360': {'success': ['Arduino Uno']},
582
+ 'https://staging.codebender.cc/sketch:30352': {'success': ['Arduino Uno']}}
583
+ """
584
+ log_entry = last_log ['log' ]
585
+
586
+ """ Test has stopped its execution for some reason,(e.g.to avoid saucelabs timeout)
587
+ and `urls_visited` dictionary will be filled with the urls already visited when the test stopped.
588
+ urls_visited = {'https://staging.codebender.cc/sketch:30360': True,
589
+ 'https://staging.codebender.cc/sketch:30352': True}
590
+ """
591
+ for url in last_log ['log' ]:
592
+ urls_visited [url ] = True
593
+
594
+ """Creates an empty dictionary each time that a test runs."""
558
595
urls_to_visit = []
596
+
597
+ """If a test has stopped its execution for some reason,
598
+ (e.g.to avoid saucelabs timeout) `urls_to_visit` dictionary will
599
+ be filled with the urls that remain to be visited.
600
+ urls_to_visit = {'https://staging.codebender.cc/sketch:30358',
601
+ 'https://staging.codebender.cc/sketch:30355'}
602
+ """
559
603
for url in sketches :
560
604
if url not in urls_visited :
561
605
urls_to_visit .append (url )
562
606
607
+ """If the urls_to_visit is empty, this means that the test was completed
608
+ and should start again. `urls_to_visit` equals to all `sketches` and `log_entry`
609
+ is an empty dictionary.
610
+ """
563
611
if len (urls_to_visit ) == 0 :
564
612
urls_to_visit = sketches
565
613
log_entry = {}
566
614
log_time = gmtime ()
567
615
568
616
current_date = strftime ('%Y-%m-%d' , log_time )
569
- # Initialize DisqusWrapper
570
- disqus_wrapper = DisqusWrapper ( log_time )
617
+
618
+ """ If `logfile` has a value and is not `None` we create `log_file`."""
571
619
if logfile :
572
620
log_file = strftime (logfile , log_time )
573
621
622
+ return (urls_to_visit , log_entry , log_file , disqus_wrapper , current_date )
623
+
624
+ def create_log (self , log_file , log_entry ,compile_type ):
625
+ # Dump the test results to `log_file`.
626
+ with open (log_file , 'w' ) as f :
627
+ f .write (jsondump (log_entry ))
628
+
629
+
630
+ def compile_sketches (self , sketches , iframe = False , project_view = False , logfile = None , compile_type = 'sketch' , create_report = False , comment = False ):
631
+ """Compiles the sketches with URLs given by the `sketches` list.
632
+ `logfile` specifies a path to a file to which test results will be
633
+ logged. If it is not `None`, compile errors will not cause the test
634
+ to halt, but rather be logged to the given file. `logfile` may be a time
635
+ format string, which will be formatted appropriately.
636
+ `iframe` specifies whether the urls pointed to by `selector` are contained
637
+ within an iframe.
638
+ If the `--full` argument is provided (and hence
639
+ `self.run_full_compile_tests` is `True`, we do not log, and limit the
640
+ number of sketches compiled to 1.
641
+ """
642
+
643
+ urls_to_visit , log_entry , log_file , log_time , current_date = self .resume_log (logfile , compile_type , sketches )
644
+
645
+ # Initialize DisqusWrapper.
646
+ disqus_wrapper = DisqusWrapper (log_time )
647
+
574
648
print '\n Compiling:' , len (urls_to_visit ), 'sketches'
575
649
total_sketches = len (urls_to_visit )
576
650
tic = time .time ()
577
651
578
652
for sketch in urls_to_visit :
579
- # Read the boards map in case current sketch/example requires a special board configuration
653
+ # Read the boards map in case current sketch/example requires a special board configuration.
580
654
boards = BOARDS_DB ['default_boards' ]
581
655
url_fragments = urlparse (sketch )
582
656
if url_fragments .path in BOARDS_DB ['special_boards' ]:
583
657
boards = BOARDS_DB ['special_boards' ][url_fragments .path ]
584
658
585
659
if len (boards ) > 0 :
586
- # Run Verify
660
+ # Run Verify.
587
661
results = self .compile_sketch (sketch , boards , iframe = iframe , project_view = project_view )
588
662
else :
589
663
results = [
@@ -592,22 +666,28 @@ def compile_sketches(self, sketches, iframe=False, project_view=False, logfile=N
592
666
}
593
667
]
594
668
595
- # Used when not funning in Full mode
669
+ """If test is not running in full mode (-F option) or logfile is None
670
+ no logs are produced inside /logs directory and we continue with sketches
671
+ compilation.
672
+ """
596
673
if logfile is None or not self .run_full_compile_tests :
597
674
toc = time .time ()
598
675
continue
599
676
600
- # Register current URL into log
677
+ # Register current URL into log.
601
678
if sketch not in log_entry :
602
679
log_entry [sketch ] = {}
680
+ print "\n "
681
+ print "sketch"
682
+ print "log_entry[" + sketch + "]" , log_entry [sketch ]
603
683
604
684
test_status = '.'
605
- # Log the compilation results
685
+
686
+ # Log the compilation results.
606
687
openFailFlag = False
607
688
for result in results :
608
689
if result ['status' ] in ['success' , 'fail' , 'error' ] and result ['status' ] not in log_entry [sketch ]:
609
690
log_entry [sketch ][result ['status' ]] = []
610
-
611
691
if result ['status' ] == 'success' :
612
692
log_entry [sketch ]['success' ].append (result ['board' ])
613
693
elif result ['status' ] == 'fail' :
@@ -627,13 +707,11 @@ def compile_sketches(self, sketches, iframe=False, project_view=False, logfile=N
627
707
log_entry [sketch ]['unsupported' ] = True
628
708
test_status = 'U'
629
709
630
- # Update Disqus comments
631
- if compile_type in ['library' , 'target_library' ] and comment :
632
- log_entry = disqus_wrapper .update_comment (sketch , results , current_date , log_entry , openFailFlag , total_sketches )
710
+ self .create_log (log_file ,log_entry , compile_type )
633
711
634
- # Dump the test results to `logfile` .
635
- with open ( log_file , 'w' ) as f :
636
- f . write ( jsondump ( log_entry ) )
712
+ # Update Disqus comments .
713
+ if comment and compile_type in [ 'library' , 'target_library' ] :
714
+ log_entry = disqus_wrapper . update_comment ( sketch , results , current_date , log_entry , openFailFlag , total_sketches )
637
715
638
716
# Display progress
639
717
sys .stdout .write (test_status )
@@ -645,7 +723,7 @@ def compile_sketches(self, sketches, iframe=False, project_view=False, logfile=N
645
723
print 'Test duration:' , int (toc - tic ), 'sec'
646
724
return
647
725
648
- # Generate a report if requested
726
+ # Generate a report if requested.
649
727
if compile_type != 'target_library' and create_report :
650
728
report_creator (compile_type , log_entry , log_file )
651
729
print '\n Test duration:' , int (toc - tic ), 'sec'
0 commit comments