Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save backup images after every download #698

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
43 changes: 43 additions & 0 deletions chirp/wxui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion tools/check_commit.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

BASE="$1"
BASE=${1:-origin/master}
RETCODE=0

RED='\033[1;31m'
Expand All @@ -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

Expand Down Expand Up @@ -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)"
Expand Down