Skip to content

Commit

Permalink
Contributing.md, logger, and wizard fix (#40)
Browse files Browse the repository at this point in the history
* Added crash handler that will log to file, added contributing.

* Fixed fileutil input.

* No longer building CLI.

* Adding more debug logging, fixed log message not incrementing count.

* Updated readme and contributing to include more info.

* removed whoa_different dir from hanging around, log message update.

* Updated contributing, added newline at end of gitignore.
  • Loading branch information
n2qzshce authored Jun 3, 2021
1 parent 416fcb1 commit b817314
Show file tree
Hide file tree
Showing 20 changed files with 389 additions and 269 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/pyinstaller-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name: Build executeable

env:
semver: 1.7.2.${{ github.run_number }}
semver: 1.8.0.${{ github.run_number }}
python-version: 3.8
KIVY_GL_BACKEND: 'angle_sdl2'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -52,13 +52,8 @@ jobs:
python -m unittest discover -v
- name: Build GUI executable
run: |
pyinstaller radio_sync_gui_${{ matrix.short-name }}.spec
${{ matrix.move-command }} dist/radio_sync_gui${{ matrix.exe-extension }} radio_sync-${{ matrix.short-name }}_gui-${{ env.semver }}${{ matrix.exe-extension }}
7z a -tzip radio_sync-${{ matrix.short-name }}-${{ env.semver }}.zip radio_sync-${{ matrix.short-name }}_gui-${{ env.semver }}${{ matrix.exe-extension }}
- name: Build CLI executable
run: |
pyinstaller -F radio_sync.py -n radio_sync-${{ matrix.short-name }}-${{ env.semver }}${{ matrix.exe-extension }} --icon images/radio_sync.ico
${{ matrix.move-command }} dist/radio_sync-${{ matrix.short-name }}-${{ env.semver }}${{ matrix.exe-extension }} ./
pyinstaller radio_sync_${{ matrix.short-name }}.spec
${{ matrix.move-command }} dist/radio_sync${{ matrix.exe-extension }} radio_sync-${{ matrix.short-name }}-${{ env.semver }}${{ matrix.exe-extension }}
7z a -tzip radio_sync-${{ matrix.short-name }}-${{ env.semver }}.zip radio_sync-${{ matrix.short-name }}-${{ env.semver }}${{ matrix.exe-extension }}
- name: Upload executable
id: upload_executable
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ in
out
sample
__pycache__
ham-radio-sync.log
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Contribution guidelines

Contributions are welcome and encouraged! Pull requests may be submitted by anyone.
In order to keep the code maintainable, the following guidelines are in place.

### Code style
* Indentations use tabs, variables use `snake_case`, classes use `CamelCase`.
* When possible, functionality should be packaged in classes or methods in a
unit-testable manner.
* Line endings are CRLF.
* Implementations of classes should have methods in the same order.
* Use f-strings and single quoted strings where possible.

### Required development software
* Python 3.8
* pip3

### Features and functionality
* Please discuss any new features or changes you'd like to make with the
repository owner(s) before submitting your pull request: we're excited to
hear about your ideas!
* All new functionality needs unit tests to exercise its behavior, where
pragmatic. This helps minimize regression issues and shows how code runs.

### Becoming a code maintainer
If you are interested in becoming a regular contributor to ham-radio-sync,
please reach out and ask! The best channel of contact is through github.

### Forks, derivatives, etc
This project is offered as an open-source project, and will be offered that
way indefinitely. We ask that any projects that are inspired by or associated
with projects here cite appropriately, including a link to this repository.

## We look forward to your pull request!
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,33 @@ Currently supported radios:
* Kenwood 71/710 Series via MCP2

### How it works
This is a command line tool that will get you setting up your radios as quickly
This is a tool that will get you setting up your radios as quickly
as possible.
1. Run the Wizard to generate the input CSVs.
2. Add your channels and configuration information to the input CSVs.
3. Select your radios and create radio plugs!
4. Import your radio plugs into your radio programming application.
5. Upload to your radio, and you're done.

##### Windows defender will warn you about opening the GUI version. Click on the `more info` dialogue to run.
### Windows defender will warn you about opening the GUI version. Click on the `more info` dialogue to run.
##### Why does Windows Defender warn about this executable?
Microsoft wants a signed executable, which requires a purchase from one of their licensed vendors. [Read more about it
here](https://docs.microsoft.com/en-us/windows-hardware/drivers/dashboard/get-a-code-signing-certificate). These purchases
are in the hundreds of dollars, which is outside the budget of this open-source project.

Static text link: https://docs.microsoft.com/en-us/windows-hardware/drivers/dashboard/get-a-code-signing-certificate

Please thoroughly research any program you run on your computer to verify its origin and trustworthiness!

##### I don't want to run an executable I don't trust, but I still want to use Ham Radio Sync.

Ham Radio Sync is written in Python 3, and can be run and built using a python 3 runtime environment: https://www.python.org

If you are unfamiliar with the process of building and writing executables, consider asking a knowledgeable individual for
their input, and you can always send a message to the developers through Github if you have any questions.

### General requirements
* You may want some knowledge of how to run a command line application.
* A Windows or Mac computer you can use to run an executable.
* The executable should be placed in a directory by itself. This will allow for
the `wizard` to create the necessary `in` and `out` folders.

Expand Down
192 changes: 25 additions & 167 deletions radio_sync.py
Original file line number Diff line number Diff line change
@@ -1,110 +1,30 @@
import argparse
import asyncio
import logging
import os
import sys

import src.ham.util.radio_types
import src.radio_sync_version_check
from src import radio_sync_version
from src.ham.migration.migration_manager import MigrationManager
from src.ham.radio_generator import RadioGenerator
from src.ham.util.path_manager import PathManager
from src.ham.wizard import Wizard
from src.ham.util.file_util import GlobalConstants


def main():
logger = logging.getLogger()
formatter = logging.Formatter(fmt='%(asctime)s.%(msecs)03d %(levelname)7s %(filename).6s:%(lineno)3s: %(message)s', datefmt="%Y-%m-%d %H:%M:%S")
def setup_logger():
os.environ["KIVY_NO_CONSOLELOG"] = "1"
os.environ["KIVY_NO_FILELOG"] = "1"
logger = logging.getLogger('radio_sync')
formatter = GlobalConstants.logging_formatter

handler = logging.StreamHandler(stream=sys.stdout)
handler.setFormatter(formatter)

logger.setLevel(logging.INFO)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
logging.root = logger

logging.warning("COMMAND LINE IS DEPRECATED. NEWER FEATURES MAY NOT BE SUPPORTED.")

parser = argparse.ArgumentParser(
prog='Ham Radio channel wizard',
description='''Convert a ham channel list to various radio formats. All of these options can be chained
to run multiple steps in order.''')
async def main():
from src.ui.app_window import AppWindow

parser.add_argument(
'--clean', '-c',
action='store_true',
default=False,
required=False,
help='Destroys input and output directories along with all their contents.',
)

parser.add_argument(
'--migrate-check',
action='store_true',
default=False,
required=False,
help='Checks for outdated columns.',
)

parser.add_argument(
'--migrate', '-m',
action='store_true',
default=False,
required=False,
help='Safely updates your input files to the latest version.',
)

parser.add_argument(
'--migrate-cleanup',
action='store_true',
default=False,
required=False,
help='Removes .bak files created during migration process.',
)

parser.add_argument(
'--wizard', '-w',
action='store_true',
default=False,
required=False,
help='Runs the setup wizard and creates minimum needed files',
)

parser.add_argument(
'--input', '-i',
default=False,
required=False,
help='Sets the input folder',
)

parser.add_argument(
'--output', '-o',
default=False,
required=False,
help='Sets the output folder',
)

parser.add_argument(
'--force', '-f',
action='store_true',
default=False,
required=False,
help="Defaults to 'yes' for all prompts (DANGEROUS)",
)

parser.add_argument(
'--radios', '-r',
choices=src.ham.util.radio_types.radio_choices(),
default=[],
nargs='+',
help=f"""Target radios to create."""
)

parser.add_argument(
'--version',
action='store_true',
default=False,
required=False,
help='Display app version.',
)
parser = argparse.ArgumentParser()

parser.add_argument(
'--debug',
Expand All @@ -113,83 +33,21 @@ def main():
required=False,
help='Enable debug logging.',
)

arg_values = parser.parse_args()

op_performed = False

if arg_values.debug:
logger.setLevel(logging.DEBUG)
logging.debug("Logging level set to debug.")

PathManager.set_input_path('in')
if arg_values.input:
PathManager.set_input_path(arg_values.input)
logging.info(f"Input directory set to {PathManager.get_input_path()}")

PathManager.set_output_path('out')
if arg_values.output:
PathManager.set_output_path(arg_values.output)
logging.info(f"Input directory set to {PathManager.get_output_path()}")

if arg_values.force:
logging.warning("FORCE HAS BEEN SET. ALL PROMPTS WILL DEFAULT YES. Files may be destroyed.")

if arg_values.clean:
logging.info("Running cleanup.")
wizard = Wizard()
wizard.cleanup()
op_performed = True

if arg_values.wizard:
logging.info("Running wizard.")
wizard = Wizard()

if PathManager.input_path_exists(''):
logging.info(f"Your input directory is located at: `{PathManager.get_input_path()}`")
logging.warning("INPUT DIRECTORY ALREADY EXISTS!! Input files will be overwritten. Continue? (y/n)[n]")
prompt = input()
if prompt != 'y':
logging.info("Wizard cancelled")
return
else:
logging.warning('Input directory will be overwritten')
wizard.bootstrap(arg_values.force)
op_performed = True

if arg_values.migrate_check:
logging.info("Running migration check")
migrations = MigrationManager()
migrations.log_check_migrations()
op_performed = True

if arg_values.migrate:
logging.info("Running migration")
migrations = MigrationManager()
migrations.migrate()
op_performed = True

if arg_values.migrate_cleanup:
logging.info("Running migration")
migrations = MigrationManager()
migrations.remove_backups()
op_performed = True

if arg_values.version:
logging.info(f"App version {src.radio_sync_version.version}")
src.radio_sync_version_check.check_version()
op_performed = True

if len(arg_values.radios) > 0:
logging.info("Running radio generator.")
radio_generator = RadioGenerator(arg_values.radios)
radio_generator.generate_all_declared()
op_performed = True

if not op_performed:
parser.print_usage()

AppWindow.force_debug = True

setup_logger()
app_window = AppWindow()
try:
await app_window.async_run()
logging.info("---APP EXIT SUCCESSFULLY---")
except Exception as e:
logging.error("---FATAL ERROR ENCOUNTERED. APP EXITED.---", e)
return


main()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Loading

0 comments on commit b817314

Please sign in to comment.