From f55170a915f6a79d7b5cb3d474082dfdfe87eedc Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Sun, 2 Jul 2023 14:30:17 -0700 Subject: [PATCH 1/2] Save backup images after every download This makes us save a backup image of every radio we download from in the CHIRP profile directory, under backups/. This will help people who don't capture a first-time download image from their radio, as well as people who make some change that they end up not liking. Keep a year (by default) of backup images, which can be changed in the config file. Fixes #10694 --- chirp/wxui/main.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/chirp/wxui/main.py b/chirp/wxui/main.py index b2b0a5a6b..258bc5c05 100644 --- a/chirp/wxui/main.py +++ b/chirp/wxui/main.py @@ -1424,11 +1424,54 @@ def _menu_large_font(self, event): CONF.set_bool('font_large', menuitem.IsChecked(), 'state') self._update_font() + def _make_backup(self, radio): + if not isinstance(radio, chirp_common.CloneModeRadio): + LOG.debug('Not backing up %s' % radio) + return + backup_dir = chirp_platform.get_platform().config_file('backups') + now = datetime.datetime.now() + fn = os.path.join(backup_dir, + '%s_%s' % (directory.radio_class_id(radio.__class__), + now.strftime('%Y%m%dT%H%M%S.img'))) + try: + os.makedirs(backup_dir, exist_ok=True) + radio.save(fn) + LOG.info('Saved backup to %s', fn) + except Exception as e: + LOG.warning('Failed to backup %s: %s', radio, e) + return + + try: + keep_days = CONF.get_int('keep_backups_days', 'prefs') + except TypeError: + keep_days = 365 + if keep_days < 0: + # Never prune + return + try: + files = os.listdir(backup_dir) + bydate = [(os.stat(os.path.join(backup_dir, f)).st_mtime, f) + for f in files] + now = time.time() + for mtime, fn in sorted(bydate): + age = (now - mtime) // 86400 + if age > keep_days: + os.remove(os.path.join(backup_dir, fn)) + LOG.warning('Pruned backup %s older than %i days', + fn, keep_days) + elif age + 30 > keep_days: + LOG.info('Backup %s will be pruned soon', fn) + else: + break + except Exception as e: + LOG.exception('Failed to prune: %s' % e) + def _menu_download(self, event): with clone.ChirpDownloadDialog(self) as d: d.Centre() if d.ShowModal() == wx.ID_OK: radio = d._radio + self._make_backup(radio) report.report_model(radio, 'download') if isinstance(radio, chirp_common.LiveRadio): editorset = ChirpLiveEditorSet(radio, None, self._editors) From 0e5fc944d7d241d7141fc97e5839c0d597dc1851 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Sun, 2 Jul 2023 20:33:09 -0700 Subject: [PATCH 2/2] Amend check_commit and PR template Require GPLv3 license and check for violations. --- .github/pull_request_template.md | 1 + tools/check_commit.sh | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a8fb72361..68cc5141f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -8,6 +8,7 @@ The following must be true before PRs can be merged: * Commits in a single PR should be related. * Major new features or bug fixes should reference a [CHIRP issue](https://chirp.danplanet.com/projects/chirp/issues). * New drivers should be accompanied by a test image in `tests/images` (except for thin aliases where the driver is sufficiently tested already). +* All files must be GPLv3 licensed or contain no license verbiage. No additional restrictions can be placed on the usage (i.e. such as noncommercial). Please also follow these guidelines: diff --git a/tools/check_commit.sh b/tools/check_commit.sh index 6672c8443..844187a18 100755 --- a/tools/check_commit.sh +++ b/tools/check_commit.sh @@ -1,6 +1,6 @@ #!/bin/bash -BASE="$1" +BASE=${1:-origin/master} RETCODE=0 RED='\033[1;31m' @@ -14,6 +14,7 @@ function fail() { echo -e "${GREEN}Checking from $(git rev-parse --short ${BASE}):${NC}" git log --pretty=oneline --no-merges --abbrev-commit ${BASE}.. +echo git diff ${BASE}.. '*.py' | grep '^+' > added_lines @@ -53,6 +54,11 @@ if grep '/cpep8.blacklist' added_lines; then fail 'Do not add new files to cpep8.blacklist' fi +grep -i 'license' added_lines > license_lines +if grep -iv '(GNU General Public License|Free Software Foundation)' license_lines; then + fail 'Files must be GPLv3 licensed (or not contain any license language)' +fi + for file in $(git diff --name-only ${BASE}..); do if file $file | grep -q CRLF; then fail "$file : Files should be LF (Unix) format, not CR (Mac) or CRLF (Windows)"