From a72bbf29f6c51453198b7f0e6008140b13a6e9c5 Mon Sep 17 00:00:00 2001 From: Jesse Mullan Date: Wed, 19 Nov 2014 16:44:04 -0800 Subject: [PATCH 1/3] Added mention of travis-ci to contributing doc --- CONTRIBUTING.md | 7 +++++-- headphones/getXldProfile.py | 15 ++++++++++----- headphones/postprocessor.py | 2 +- headphones/transmission.py | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 08505c70..9b9ec65e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,7 @@ The code should work with Python 2.6 and 2.7. Note that Headphones runs on diffe Re-use existing code. Do not hesitate to add logging in your code. You can the logger module `headphones.logger.*` for this. Web requests are invoked via `headphones.request.*` and derived ones. Use these methods to automatically add proper and meaningful error handling. ### Code conventions -Altough Headphones did not adapt a code convention in the past, we try to follow the [PEP8](http://legacy.python.org/dev/peps/pep-0008/) conventions for future code. A short summary to remind you (copied from http://wiki.ros.org/PyStyleGuide): +Although Headphones did not adapt a code convention in the past, we try to follow the [PEP8](http://legacy.python.org/dev/peps/pep-0008/) conventions for future code. A short summary to remind you (copied from http://wiki.ros.org/PyStyleGuide): * 4 space indentation * 80 characters per line @@ -32,4 +32,7 @@ Altough Headphones did not adapt a code convention in the past, we try to follow * `self.__really_private_field` * `_global` -Document your code! \ No newline at end of file +Document your code! + +### Continuous Integration +Headphones has a configuration file for [travis-ci](https://travis-ci.org/). You can add your forked repo to travis to have it check your code against pep8, pylint, and pyflakes for you. Your pull request will show a green check mark or a red x on each tested commit, depending on if linting passes. diff --git a/headphones/getXldProfile.py b/headphones/getXldProfile.py index c85297cb..181751a7 100755 --- a/headphones/getXldProfile.py +++ b/headphones/getXldProfile.py @@ -1,11 +1,12 @@ import os.path -from biplist import * +import biplist from headphones import logger def getXldProfile(xldProfile): xldProfileNotFound = xldProfile + expanded = os.path.expanduser('~/Library/Preferences/jp.tmkk.XLD.plist') if not os.path.isfile(expanded): logger.warn("Could not find xld preferences at: %s", expanded) @@ -13,14 +14,18 @@ def getXldProfile(xldProfile): # Get xld preferences plist try: - preferences = readPlist(expanded) - except (InvalidPlistException, NotBinaryPlistException), e: + preferences = biplist.readPlist(expanded) + except (biplist.InvalidPlistException, biplist.NotBinaryPlistException), e: logger.error("Error reading xld preferences plist: %s", e) return(xldProfileNotFound, None, None) - xldProfile = xldProfile.lower() - profiles = preferences.get('Profiles') + if not isinstance(preferences, dict): + logger.error("Error reading xld preferences plist, not a dict: %r", preferences) + return(xldProfileNotFound, None, None) + profiles = preferences.get('Profiles', []) # pylint:disable=E1103 + + xldProfile = xldProfile.lower() for profile in profiles: profilename = profile.get('XLDProfileManager_ProfileName') diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 4de9de5d..cd95d5be 100755 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -1221,4 +1221,4 @@ def forcePostProcess(dir=None, expand_subfolders=True, album_dir=None): logger.info("Couldn't parse '%s' into any valid format. If adding " \ "albums from another source, they must be in an 'Artist - Album " \ "[Year]' format, or end with the musicbrainz release group id.", - folder_basename) \ No newline at end of file + folder_basename) diff --git a/headphones/transmission.py b/headphones/transmission.py index 2529a6a5..ec5a9f60 100644 --- a/headphones/transmission.py +++ b/headphones/transmission.py @@ -184,4 +184,4 @@ def torrentAction(method, arguments): logger.error("Error sending torrent to Transmission") return - return response \ No newline at end of file + return response From 28079165c47f0b6c4895be7842071d06d9a57801 Mon Sep 17 00:00:00 2001 From: Jesse Mullan Date: Sun, 23 Nov 2014 16:03:30 -0800 Subject: [PATCH 2/3] Fix pylint complaints about logging --- headphones/cuesplit.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/headphones/cuesplit.py b/headphones/cuesplit.py index 467c93df..64778dd1 100755 --- a/headphones/cuesplit.py +++ b/headphones/cuesplit.py @@ -546,8 +546,8 @@ def split(albumpath): for _cue in base_dir.filter('CueFile'): for _wave in base_dir.filter('WaveFile'): if _cue.header['file'] == _wave.name: - logger.info('CUE Sheet found: {0}'.format(_cue.name)) - logger.info('Music file found: {0}'.format(_wave.name)) + logger.info('CUE Sheet found: %s', _cue.name) + logger.info('Music file found: %s',_wave.name) cue = _cue wave = _wave # if no perfect match found then try without extensions @@ -556,9 +556,9 @@ def split(albumpath): for _cue in base_dir.filter('CueFile'): for _wave in base_dir.filter('WaveFile'): if ''.join(os.path.splitext(_cue.header['file'])[:-1]) == _wave.name_name: - logger.info('Possible CUE Sheet found: {0}'.format(_cue.name)) - logger.info('CUE Sheet refers music file: {0}'.format(_cue.header['file'])) - logger.info('Possible Music file found: {0}'.format(_wave.name)) + logger.info('Possible CUE Sheet found: %s', _cue.name) + logger.info('CUE Sheet refers music file: %s', _cue.header['file']) + logger.info('Possible Music file found: %s', _wave.name) cue = _cue wave = _wave cue.header['file'] = wave.name @@ -641,14 +641,14 @@ def split(albumpath): # tag FLAC files if split and CUE_META.count_tracks() == len(base_dir.tracks(ext='.flac', split=True)): for t in base_dir.tracks(ext='.flac', split=True): - logger.info('Tagging {0}...'.format(t.name)) + logger.info('Tagging %s...', t.name) t.tag() # rename FLAC files if split and CUE_META.count_tracks() == len(base_dir.tracks(ext='.flac', split=True)): for t in base_dir.tracks(ext='.flac', split=True): if t.name != t.filename(): - logger.info('Renaming {0} to {1}...'.format(t.name, t.filename())) + logger.info('Renaming %s to %s...', t.name, t.filename()) os.rename(t.name, t.filename()) os.remove(ALBUM_META_FILE_NAME) From 0146153d0a2bb54a46ddcca6b1dd5def79bf2031 Mon Sep 17 00:00:00 2001 From: Jesse Mullan Date: Sun, 23 Nov 2014 16:29:19 -0800 Subject: [PATCH 3/3] Hopefully fix pylint complaint, also lock pylint to pything 2.6 compatible version --- .travis.yml | 3 ++- headphones/cuesplit.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6aaf8f33..ffed186b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,9 +8,10 @@ language: python python: - "2.6" - "2.7" +# pylint 1.4 does not run under python 2.6 install: - pip install pyOpenSSL - - pip install pylint + - pip install pylint==1.3.1 - pip install pyflakes - pip install pep8 script: diff --git a/headphones/cuesplit.py b/headphones/cuesplit.py index 64778dd1..19414332 100755 --- a/headphones/cuesplit.py +++ b/headphones/cuesplit.py @@ -547,7 +547,7 @@ def split(albumpath): for _wave in base_dir.filter('WaveFile'): if _cue.header['file'] == _wave.name: logger.info('CUE Sheet found: %s', _cue.name) - logger.info('Music file found: %s',_wave.name) + logger.info('Music file found: %s', _wave.name) cue = _cue wave = _wave # if no perfect match found then try without extensions