Skip to content

Commit

Permalink
Move PROGRAM_UPDATE_LEVELS to picard.constants
Browse files Browse the repository at this point in the history
- Move PROGRAM_UPDATE_LEVELS to picard.constants
- Logging changes
- Formatting and translation clean-up
- Change picard.const.PROGRAM_UPDATE_LEVELS to numeric keys
- Add releases endpoint to picard.const.PLUGINS_API
- Refactor to remove duplicated code in mainwindow.py
- General cleanup of debug log translations
- Use intermediate variables to cache config information
  • Loading branch information
rdswift authored and zas committed Aug 29, 2018
1 parent df3ca29 commit fbd5cca
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 130 deletions.
16 changes: 1 addition & 15 deletions picard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,12 @@
PICARD_APP_NAME = "Picard"
PICARD_VERSION = (2, 0, 4, 'dev', 1)


# optional build version
# it should be in the form '<platform>_<YYMMDDHHMMSS>'
# ie. win32_20140415091256
PICARD_BUILD_VERSION_STR = ""

PROGRAM_UPDATE_LEVELS = {
'stable': {
'level': 0,
'title': 'Stable releases only',
},
'beta': {
'level': 1,
'title': 'Stable and Beta releases',
},
'dev': {
'level': 2,
'title': 'Stable, Beta and Dev releases',
},
}


class VersionError(Exception):
pass
Expand Down
30 changes: 28 additions & 2 deletions picard/const/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from collections import OrderedDict
import os
import sys

Expand Down Expand Up @@ -101,13 +102,14 @@
'beta.musicbrainz.org',
]

# Plugins API
# Plugins and Release Versions API
PLUGINS_API = {
'host': 'picard.musicbrainz.org',
'port': 443,
'endpoint': {
'plugins': '/api/v2/plugins/',
'download': '/api/v2/download/'
'download': '/api/v2/download/',
'releases': '/api/releases',
}
}

Expand All @@ -116,3 +118,27 @@

# Maximum number of covers to draw in a stack in CoverArtThumbnail
MAX_COVERS_TO_STACK = 4

# Update levels available for automatic checking
PROGRAM_UPDATE_LEVELS = OrderedDict(
[
(
0, {
'name': 'stable',
'title': N_('Stable releases only'),
}
),
(
1, {
'name': 'beta',
'title': N_('Stable and Beta releases'),
}
),
(
2, {
'name': 'dev',
'title': N_('Stable, Beta and Dev releases'),
}
),
]
)
3 changes: 1 addition & 2 deletions picard/tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
uniqify,
versions,
)
from picard.util.checkupdate import UpdateCheckManager
from picard.webservice import WebService
from picard.webservice.api_helpers import (
AcoustIdAPIHelper,
Expand All @@ -97,8 +98,6 @@
from picard.ui.searchdialog.artist import ArtistSearchDialog
from picard.ui.searchdialog.track import TrackSearchDialog

from picard.util.checkupdate import UpdateCheckManager


# A "fix" for https://bugs.python.org/issue1438480
def _patched_shutil_copystat(src, dst, *, follow_symlinks=True):
Expand Down
50 changes: 32 additions & 18 deletions picard/ui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
from picard import (
config,
log,
PROGRAM_UPDATE_LEVELS,
)
from picard.album import Album
from picard.cluster import Cluster
from picard.const import PROGRAM_UPDATE_LEVELS
from picard.file import File
from picard.formats import supported_formats
from picard.plugin import ExtensionPoint
Expand Down Expand Up @@ -176,19 +176,7 @@ def keyPressEvent(self, event):
def show(self):
self.restoreWindowState()
super().show()
for key in PROGRAM_UPDATE_LEVELS.keys():
if PROGRAM_UPDATE_LEVELS[key]['level'] == config.setting["update_level"]:
update_level_text = key
do_auto_update_check = config.setting['check_for_updates'] and config.setting['update_check_days'] > 0 and datetime.date.today().toordinal() >= config.persist['last_update_check'] + config.setting['update_check_days']
log.debug(_("{check_status} start-up check for program updates. Today: {today_date}, Last check: {last_check} (Check interval: {check_interval} days), Update level: {update_level}".format(
check_status='Initiating' if do_auto_update_check else 'Skipping',
today_date=datetime.date.today(),
last_check=str(datetime.date.fromordinal(config.persist['last_update_check'])) if config.persist['last_update_check'] > 0 else 'never',
check_interval=config.setting['update_check_days'],
update_level=update_level_text if update_level_text else 'unknown',
)))
if do_auto_update_check:
self.tagger.updatecheckmanager.check_update(show_always=False, update_level=config.setting["update_level"], callback=update_last_check_date)
self.auto_update_check()
self.metadata_box.restore_state()

def closeEvent(self, event):
Expand Down Expand Up @@ -551,7 +539,7 @@ def create_actions(self):
self.open_folder_action.triggered.connect(self.open_folder)

self.check_update_action = QtWidgets.QAction(_("&Check for Update"), self)
self.check_update_action.triggered.connect(self.check_for_update)
self.check_update_action.triggered.connect(self.do_update_check)

def toggle_rename_files(self, checked):
config.setting["rename_files"] = checked
Expand Down Expand Up @@ -1108,10 +1096,36 @@ def paste(self):
self.tagger.paste_files(target)
self.paste_action.setEnabled(False)

def check_for_update(self):
self.tagger.updatecheckmanager.check_update(show_always=True, update_level=config.setting["update_level"], callback=update_last_check_date)
def do_update_check(self):
self.check_for_update(True)

def auto_update_check(self):
check_for_updates = config.setting['check_for_updates']
update_check_days = config.setting['update_check_days']
last_update_check = config.persist['last_update_check']
update_level = config.setting['update_level']
today = datetime.date.today().toordinal()
do_auto_update_check = check_for_updates and update_check_days > 0 and today >= last_update_check + update_check_days
log.debug('{check_status} start-up check for program updates. Today: {today_date}, Last check: {last_check} (Check interval: {check_interval} days), Update level: {update_level} ({update_level_name})'.format(
check_status='Initiating' if do_auto_update_check else 'Skipping',
today_date=datetime.date.today(),
last_check=str(datetime.date.fromordinal(last_update_check)) if last_update_check > 0 else 'never',
check_interval=update_check_days,
update_level=update_level,
update_level_name=PROGRAM_UPDATE_LEVELS[update_level]['name'] if update_level in PROGRAM_UPDATE_LEVELS else 'unknown',
))
if do_auto_update_check:
self.check_for_update(False)

def check_for_update(self, show_always):
self.tagger.updatecheckmanager.check_update(
show_always=show_always,
update_level=config.setting['update_level'],
callback=update_last_check_date
)

def update_last_check_date(is_success):
log.debug('Processing update_last_check_date callback with argument: %s' % (is_success,))
if is_success:
config.persist['last_update_check'] = datetime.date.today().toordinal()
else:
log.debug('The update check was unsuccessful. The last update date will not be changed.')
19 changes: 7 additions & 12 deletions picard/ui/options/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
from PyQt5 import QtCore
from PyQt5.QtWidgets import QInputDialog

from picard import (
config,
from picard import config
from picard.collection import load_user_collections
from picard.const import (
MUSICBRAINZ_SERVERS,
PROGRAM_UPDATE_LEVELS,
)
from picard.collection import load_user_collections
from picard.const import MUSICBRAINZ_SERVERS
from picard.util import webbrowser2

from picard.ui.options import (
Expand Down Expand Up @@ -76,14 +76,9 @@ def load(self):
self.ui.ignore_file_mbids.setChecked(config.setting["ignore_file_mbids"])
self.ui.check_for_updates.setChecked(config.setting["check_for_updates"])
self.ui.update_level.clear()
index = 0
for key in PROGRAM_UPDATE_LEVELS.keys():
self.ui.update_level.addItem(
_(PROGRAM_UPDATE_LEVELS[key]['title']),
PROGRAM_UPDATE_LEVELS[key]['level'])
if PROGRAM_UPDATE_LEVELS[key]['level'] == config.setting["update_level"]:
self.ui.update_level.setCurrentIndex(index)
index += 1
for level, description in PROGRAM_UPDATE_LEVELS.items():
self.ui.update_level.addItem(_(description['title']), level)
self.ui.update_level.setCurrentIndex(self.ui.update_level.findData(config.setting["update_level"]))
self.ui.update_check_days.setValue(config.setting["update_check_days"])

def save(self):
Expand Down
9 changes: 1 addition & 8 deletions picard/ui/ui_options_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Ui_GeneralOptionsPage(object):
def setupUi(self, GeneralOptionsPage):
GeneralOptionsPage.setObjectName("GeneralOptionsPage")
GeneralOptionsPage.resize(304, 435)
GeneralOptionsPage.resize(283, 435)
self.vboxlayout = QtWidgets.QVBoxLayout(GeneralOptionsPage)
self.vboxlayout.setObjectName("vboxlayout")
self.groupBox = QtWidgets.QGroupBox(GeneralOptionsPage)
Expand Down Expand Up @@ -116,17 +116,13 @@ def setupUi(self, GeneralOptionsPage):
self.update_level.setSizePolicy(sizePolicy)
self.update_level.setEditable(False)
self.update_level.setObjectName("update_level")
self.update_level.addItem("")
self.update_level.addItem("")
self.update_level.addItem("")
self.gridLayout_2.addWidget(self.update_level, 0, 1, 1, 1)
self.verticalLayout_2.addLayout(self.gridLayout_2)
self.vboxlayout.addWidget(self.groupBox_3)
spacerItem1 = QtWidgets.QSpacerItem(181, 21, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.vboxlayout.addItem(spacerItem1)

self.retranslateUi(GeneralOptionsPage)
self.update_level.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(GeneralOptionsPage)
GeneralOptionsPage.setTabOrder(self.server_host, self.server_port)

Expand All @@ -145,7 +141,4 @@ def retranslateUi(self, GeneralOptionsPage):
self.check_for_updates.setText(_("Check for updates during start-up"))
self.label_2.setText(_("Days between checks:"))
self.label_3.setText(_("Updates to check:"))
self.update_level.setItemText(0, _("Stable releases only"))
self.update_level.setItemText(1, _("Stable and Beta releases"))
self.update_level.setItemText(2, _("Stable, Beta and Dev releases"))

Loading

0 comments on commit fbd5cca

Please sign in to comment.