Пример #1
0
    def test_migration_one(self):
        FileUtil.safe_delete_dir('in')
        FileUtil.safe_delete_dir('out')
        self.manager._migrate_one()

        self.assertTrue(os.path.exists('in'))
        self.assertTrue(os.path.exists('out'))
Пример #2
0
    def _create_input(self):
        FileUtil.safe_create_dir(PathManager.get_input_path())
        create_files = {
            'channels': self._create_channel_file,
            'digital_contacts': self._create_dmr_data,
            'zones': self._create_zone_data,
            'user': self._create_dmr_user_data,
        }

        for key in create_files:
            create_files[key]()
Пример #3
0
 def test_sets_different_path(self):
     os.mkdir('./whoa_different')
     PathManager.set_input_path('whoa_different')
     w = PathManager.open_input_file('x.tst', 'w+')
     w.write('different test success')
     w.close()
     f = open('./whoa_different/x.tst', 'r')
     line = f.readline()
     f.close()
     self.assertEqual(line, 'different test success')
     FileUtil.safe_delete_dir('./whoa_different')
Пример #4
0
	def setUp(self):
		super().setUp()
		self.validator = Validator()
		self.validator.flush_names()
		logging.getLogger().setLevel(logging.CRITICAL)
		FileUtil.safe_delete_dir('in')
		FileUtil.safe_delete_dir('out')
		FileUtil.safe_create_dir('in')
		FileUtil.safe_create_dir('out')

		cols = dict()
		cols['name'] = 'National 2m'
		cols['medium_name'] = 'Natl 2m'
		cols['short_name'] = 'NATL 2M'
		cols['zone_id'] = ''
		cols['rx_freq'] = '146.52'
		cols['rx_ctcss'] = ''
		cols['rx_dcs'] = ''
		cols['rx_dcs_invert'] = ''
		cols['tx_power'] = 'High'
		cols['tx_offset'] = ''
		cols['tx_ctcss'] = ''
		cols['tx_dcs'] = ''
		cols['tx_dcs_invert'] = ''
		cols['digital_timeslot'] = ''
		cols['digital_color'] = ''
		cols['digital_contact_id'] = ''
		cols['latitude'] = ''
		cols['longitude'] = ''
		self.radio_cols = cols
Пример #5
0
 def setUp(self):
     FileUtil.safe_delete_dir('in')
     FileUtil.safe_delete_dir('out')
     FileUtil.safe_create_dir('in')
     FileUtil.safe_create_dir('out')
     PathManager.set_input_path('./in')
     PathManager.set_output_path('./out')
Пример #6
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'] = ''
Пример #7
0
 def setUp(self):
     super().setUp()
     logging.getLogger().setLevel(logging.ERROR)
     FileUtil.safe_delete_dir('./in')
     FileUtil.safe_delete_dir('./out')
     FileUtil.safe_delete_dir('./whoa_different')
     os.mkdir('./in')
     os.mkdir('./out')
     self.manager = MigrationManager()
Пример #8
0
	def _migrate_one(self):
		logging.info('Running migration step 1: Creating directories...')
		FileUtil.safe_create_dir('in')
		FileUtil.safe_create_dir('out')
Пример #9
0
 def cleanup(self):
     FileUtil.safe_delete_dir(PathManager.get_input_path())
     FileUtil.safe_delete_dir(PathManager.get_output_path())
Пример #10
0
 def _create_output(self):
     FileUtil.safe_create_dir(PathManager.get_output_path())
     return
Пример #11
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
Пример #12
0
 def setUp(self):
     super().setUp()
     logging.getLogger().setLevel(logging.ERROR)
     FileUtil.safe_delete_dir('in')
     FileUtil.safe_delete_dir('out')
     self.manager = MigrationManager()
Пример #13
0
	def setUp(self):
		super().setUp()
		FileUtil.safe_delete_dir('in')
		FileUtil.safe_delete_dir('out')
		self.wizard = Wizard()
Пример #14
0
 def test_delete_no_exception(self):
     os.mkdir('del_test')
     self.assertTrue(os.path.exists('del_test'))
     FileUtil.safe_delete_dir('del_test')
     FileUtil.safe_delete_dir('del_test')
     self.assertFalse(os.path.exists('del_test'))
Пример #15
0
 def test_no_exception(self):
     self.assertFalse(os.path.exists('./in'))
     FileUtil.safe_create_dir('./in')
     FileUtil.safe_create_dir('./in')
     self.assertTrue(os.path.exists('./in'))