def stack_files(self, timeslice_info_list, stack_dataset_path, band1_vrt_path=None, overwrite=False):
        if os.path.exists(stack_dataset_path) and not overwrite:
            logger.debug('Stack VRT file %s already exists', stack_dataset_path)
            return
        
        band_no = timeslice_info_list[0]['tile_layer'] # Should all be the same
        build_vrt = True
        if band_no == 1: # First band
            intermediate_path = stack_dataset_path # No post-processing required
        elif band1_vrt_path: # band1_vrt_path provided - use this as source for new VRT
            intermediate_path = band1_vrt_path
            build_vrt = False
        else: # No band1_vrt_path provided
            intermediate_path = re.sub('\.vrt$', '.tmp', stack_dataset_path)
        
        file_list_path = re.sub('\.vrt$', '.txt', stack_dataset_path)
        if build_vrt:
            logger.info('Creating %d layer stack VRT file %s', len(timeslice_info_list), stack_dataset_path)
            list_file = open(file_list_path, 'w')
            list_file.write('\n'.join([timeslice_info['tile_pathname'] for timeslice_info in timeslice_info_list]))
            list_file.close()
            del list_file

            command_string = 'gdalbuildvrt'
            if not self.debug:
                command_string += ' -q'
#            command_string += ' -separate -overwrite %s \\\n%s' % (
#                intermediate_path,
#                ' \\\n'.join([timeslice_info['tile_pathname'] for timeslice_info in timeslice_info_list])
#                )
            command_string += ' -separate -input_file_list %s -overwrite %s' % (
                file_list_path,
                intermediate_path
                )
            if not self.debug:
                command_string += file_list_path % '\nrm %s'
        else:
            command_string = ''
        
        if band_no > 1: # Need to post process intermediate VRT file
            if command_string:
                command_string += '\n'
            command_string += 'cat %s | sed s/\<SourceBand\>1\<\\\\/SourceBand\>/\<SourceBand\>%d\<\\\\/SourceBand\>/g > %s' % (intermediate_path, band_no, stack_dataset_path)
#                command_string += '\nchmod 777 %s' % stack_dataset_path
            if build_vrt: # Intermediate file created for band > 1
                if not self.debug: # Remove temporary intermediate file just created
                    command_string += '\nrm %s' % intermediate_path
            else:
                logger.info('Creating %d layer stack VRT file %s from %s', len(timeslice_info_list), stack_dataset_path, intermediate_path)

        
        logger.debug('command_string = %s', command_string)
    
        result = execute(command_string=command_string)
    
        if result['stdout']:
            log_multiline(logger.info, result['stdout'], 'stdout from ' + command_string, '\t') 

        if result['stderr']:
            log_multiline(logger.debug, result['stderr'], 'stderr from ' + command_string, '\t')
            
        if result['returncode']:
            raise Exception('%s failed', command_string) 
                  
        temporal_stack_dataset = gdal.Open(stack_dataset_path)
        assert temporal_stack_dataset, 'Unable to open VRT %s' % stack_dataset_path

        for band_index in range(len(timeslice_info_list)):
            band = temporal_stack_dataset.GetRasterBand(band_index + 1)
            
            # Copy dict and convert to strings for metadata
            metadata_dict = dict(timeslice_info_list[band_index])
            for key in metadata_dict.keys():
                metadata_dict[key] = str(metadata_dict[key])
                
            band.SetMetadata(metadata_dict)
            log_multiline(logger.debug, band.GetMetadata(), 'band.GetMetadata()', '\t')
            
            # Need to set nodata values for each band - can't seem to do it in gdalbuildvrt
            nodata_value = timeslice_info_list[band_index]['nodata_value']
            if nodata_value is not None:
                logger.debug('nodata_value = %s', nodata_value)
                band.SetNoDataValue(nodata_value)
            
        temporal_stack_dataset.FlushCache()
dataset/ETHPy150Open GeoscienceAustralia/agdc/src/stacker.py/Stacker.stack_files/swapped operands of `%`