def channels_to_file(self, channels):
        logging.info('Writing imported files.')
        headers = RadioChannelDefault.create_empty().headers()
        writer = RadioWriter.output_writer('import_result.csv', '\r\n')
        writer.writerow(headers)
        channel_num = 1
        for chan in channels:  # who is this for chan
            channel_default = RadioChannelBuilder.casted(
                chan, radio_types.DEFAULT)
            writer.writerow(channel_default.output(channel_num))
            channel_num += 1
        writer.close()

        result_path = PathManager.get_output_path('import_result.csv')
        logging.info(
            f'Import complete! Your imported file is in `{result_path}`')
Beispiel #2
0
	def setUp(self):
		super().setUp()
		FileUtil.safe_create_dir(PathManager.get_output_path('gpx'))
		self.radio_channel = RadioChannelGpx.create_empty()
		self.digital_contacts = dict()
		cols = dict()
		cols['digital_id'] = '00000'
		cols['name'] = 'Analog'
		cols['call_type'] = 'all'
		digital_contact = DmrContact(cols)
		self.digital_contacts[0] = digital_contact

		cols['digital_id'] = '54321'
		cols['name'] = 'Contact1'
		cols['call_type'] = 'group'
		digital_contact = DmrContact(cols)
		self.digital_contacts[54321] = digital_contact

		cols = dict()
		cols['radio_id'] = '12345'
		cols['name'] = 'N0CALL DMR'
		self.digital_ids = {1: DmrId(cols)}

		self.cols = dict()
		self.cols['name'] = ''
		self.cols['medium_name'] = ''
		self.cols['short_name'] = ''
		self.cols['zone_id'] = ''
		self.cols['rx_freq'] = ''
		self.cols['rx_ctcss'] = ''
		self.cols['rx_dcs'] = ''
		self.cols['rx_dcs_invert'] = ''
		self.cols['tx_power'] = ''
		self.cols['tx_offset'] = ''
		self.cols['tx_ctcss'] = ''
		self.cols['tx_dcs'] = ''
		self.cols['tx_dcs_invert'] = ''
		self.cols['digital_timeslot'] = ''
		self.cols['digital_color'] = ''
		self.cols['digital_contact_id'] = ''
		self.cols['latitude'] = ''
		self.cols['longitude'] = ''
Beispiel #3
0
 def select_output_folder_dialog(self, event):
     self._select_folder_dialog(event, 'Set output directory',
                                PathManager.get_output_path(),
                                self._select_output_folder)
Beispiel #4
0
 def cleanup(self):
     FileUtil.safe_delete_dir(PathManager.get_input_path())
     FileUtil.safe_delete_dir(PathManager.get_output_path())
Beispiel #5
0
 def _create_output(self):
     FileUtil.safe_create_dir(PathManager.get_output_path())
     return
Beispiel #6
0
	def output_writer(cls, file_path, newline_char):
		output_path = PathManager.get_output_path(file_path)
		return RadioWriter(output_path, newline_char)
Beispiel #7
0
    def generate_all_declared(self):
        file_errors = self._validator.validate_files_exist()
        self._validator.flush_names()
        if len(file_errors) > 0:
            return False

        results = self._migrations.check_migrations_needed()
        if len(results.keys()) > 0:
            logging.warning(
                'You may be using an old version of the input files. Have you run migrations?'
            )
            logging.warning("Migrations check is under the 'File' menu.")
            sleep(1)

        for radio in radio_types.radio_choices():
            radio_folder = PathManager.get_output_path(radio)
            if not os.path.exists(radio_folder):
                continue
            logging.info(f'Deleting old output folder `{radio}`')
            FileUtil.safe_delete_dir(radio_folder)

        digital_contacts, digi_contact_errors = self._generate_digital_contact_data(
        )
        dmr_ids, dmr_id_errors = self._generate_dmr_id_data()
        zones, zone_errors = self._generate_zone_data()
        user, user_data_errors = self._generate_user_data()
        preload_errors = digi_contact_errors + dmr_id_errors + zone_errors + user_data_errors

        feed = PathManager.open_input_file('input.csv', 'r')
        csv_reader = csv.DictReader(feed)

        radio_channel_errors = []
        radio_channels = []
        line_num = 1
        for line in csv_reader:
            line_errors = self._validator.validate_radio_channel(
                line, line_num, feed.name, digital_contacts, zones)
            radio_channel_errors += line_errors
            line_num += 1

            if len(line_errors) > 0:
                continue

            radio_channel = RadioChannel(line, digital_contacts, dmr_ids)
            radio_channels.append(radio_channel)

            if radio_channel.zone_id.fmt_val(None) is not None:
                zones[radio_channel.zone_id.fmt_val()].add_channel(
                    radio_channel)
        feed.close()

        all_errors = preload_errors + radio_channel_errors
        if len(all_errors) > 0:
            logging.error('--- VALIDATION ERRORS, CANNOT CONTINUE ---')
            for err in all_errors:
                logging.error(
                    f'\t\tfile: `{err.file_name}` line:{err.line_num} validation error: {err.message}'
                )
            return False
        else:
            logging.info(
                'File validation complete, no obvious formatting errors found')

        radio_files = dict()
        headers_gen = RadioChannel.create_empty()
        FileUtil.safe_create_dir('out')

        channel_numbers = dict()
        for radio in self.radio_list:
            radio_casted = RadioChannelBuilder.casted(headers_gen, radio)
            FileUtil.safe_create_dir(f'out/{radio}')
            logging.info(f'Generating for radio type `{radio}`')

            if radio_casted.skip_radio_csv():
                logging.info(
                    f'`{radio}` uses special output style. Skipping channels csv'
                )
                continue
            output = RadioWriter.output_writer(f'{radio}/{radio}_channels.csv',
                                               '\r\n')
            file_headers = radio_casted.headers()
            output.writerow(file_headers)
            radio_files[radio] = output
            channel_numbers[radio] = 1

        logging.info('Processing radio channels')
        line = 1
        for radio_channel in radio_channels:
            logging.debug(f'Processing radio line {line}')
            if line % file_util.RADIO_LINE_LOG_INTERVAL == 0:
                logging.info(f'Processing radio line {line}')
            line += 1
            for radio in self.radio_list:
                if radio not in radio_files.keys():
                    continue

                if not radio_types.supports_dmr(
                        radio) and radio_channel.is_digital():
                    continue

                casted_channel = RadioChannelBuilder.casted(
                    radio_channel, radio)

                input_data = casted_channel.output(channel_numbers[radio])
                radio_files[radio].writerow(input_data)
                channel_numbers[radio] += 1

        additional_data = RadioAdditional(radio_channels, dmr_ids,
                                          digital_contacts, zones, user)
        for radio in self.radio_list:
            if radio in radio_files.keys():
                radio_files[radio].close()
            casted_additional_data = RadioAdditionalBuilder.casted(
                additional_data, radio)
            casted_additional_data.output()

        logging.info(f'''Radio generator complete. Your output files are in 
					`{os.path.abspath('out')}`
					The next step is to import these files into your radio programming application. (e.g. CHiRP)'''
                     )
        return True