diff options
| author | root <none@none> | 2006-04-26 10:48:09 +0000 |
|---|---|---|
| committer | root <none@none> | 2006-04-26 10:48:09 +0000 |
| commit | 4becf6f9e596b45401680c4947e2d92c953d5e08 (patch) | |
| tree | 3bb03a16daa8c780bf60c622dc288eb01cfca145 /config.py | |
| download | pylint-git-4becf6f9e596b45401680c4947e2d92c953d5e08.tar.gz | |
forget the past.
forget the past.
Diffstat (limited to 'config.py')
| -rw-r--r-- | config.py | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/config.py b/config.py new file mode 100644 index 000000000..d5b4e9b09 --- /dev/null +++ b/config.py @@ -0,0 +1,137 @@ +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +""" Copyright (c) 2003-2005 LOGILAB S.A. (Paris, FRANCE). + http://www.logilab.fr/ -- mailto:contact@logilab.fr + + utilities for PyLint configuration : + _ pylintrc + _ pylint.d (PYLINT_HOME) +""" + +__revision__ = "$Id: config.py,v 1.15 2005-12-13 16:26:35 syt Exp $" + +import pickle +import os +import sys +from os.path import exists, isfile, join, expanduser, abspath + +# pylint home is used to save old runs results ################################ + +if os.environ.has_key('PYLINTHOME'): + PYLINT_HOME = os.environ['PYLINTHOME'] +else: + USER_HOME = expanduser('~') + if USER_HOME == '~': + PYLINT_HOME = ".pylint.d" + else: + PYLINT_HOME = join(USER_HOME, '.pylint.d') + +if not exists(PYLINT_HOME): + try: + os.mkdir(PYLINT_HOME) + except OSError: + print >> sys.stderr, 'Unable to create directory %s' % PYLINT_HOME + +def get_pdata_path(base_name, recurs): + """return the path of the file which should contain old search data for the + given base_name with the given options values + """ + base_name = base_name.replace(os.sep, '_') + return join(PYLINT_HOME, "%s%s%s"%(base_name, recurs, '.stats')) + +def load_results(base): + """try to unpickle and return data from file if it exists and is not + corrupted + + return an empty dictionary if it doesn't exists + """ + data_file = get_pdata_path(base, 1) + try: + return pickle.load(open(data_file)) + except: + return {} + +def save_results(results, base): + """pickle results""" + data_file = get_pdata_path(base, 1) + try: + pickle.dump(results, open(data_file, 'w')) + except OSError: + print >> sys.stderr, 'Unable to create file %s' % data_file + +# location of the configuration file ########################################## + +# is there a pylint rc file in the current directory ? +if exists('pylintrc'): + PYLINTRC = abspath('pylintrc') +elif os.environ.has_key('PYLINTRC') and exists(os.environ['PYLINTRC']): + PYLINTRC = os.environ['PYLINTRC'] +else: + USER_HOME = expanduser('~') + if USER_HOME == '~' or USER_HOME == '/root': + PYLINTRC = ".pylintrc" + else: + PYLINTRC = join(USER_HOME, '.pylintrc') +if not isfile(PYLINTRC): + if isfile('/etc/pylintrc'): + PYLINTRC = '/etc/pylintrc' + else: + PYLINTRC = None + +ENV_HELP = ''' +The following environment variables are used : + * PYLINTHOME + path to the directory where data of persistent run will be stored. If not +found, it defaults to ~/.pylint.d/ or .pylint.d (in the current working +directory) . The current PYLINTHOME is %(PYLINT_HOME)s. + * PYLINTRC + path to the configuration file. If not found, it will use the first +existant file in ~/.pylintrc, /etc/pylintrc. The current PYLINTRC is +%(PYLINTRC)s. +''' % globals() + +# evaluation messages ######################################################### + +def get_note_message(note): + """return a message according to note + note is a float < 10 (10 is the highest note) + """ + assert note <= 10, "Note is %.2f. Either you cheated, or pylint's \ +broken!" % note + if note < 0: + msg = 'You have to do something quick !' + elif note < 1: + msg = 'Hey! This is really dreadful. Or maybe pylint is buggy?' + elif note < 2: + msg = "Come on! You can't be proud of this code" + elif note < 3: + msg = 'Hum... Needs work.' + elif note < 4: + msg = 'Wouldn\'t you be a bit lazy?' + elif note < 5: + msg = 'A little more work would make it acceptable.' + elif note < 6: + msg = 'Just the bare minimum. Give it a bit more polish. ' + elif note < 7: + msg = 'This is okay-ish, but I\'m sure you can do better.' + elif note < 8: + msg = 'If you commit now, people should not be making nasty \ +comments about you on c.l.py' + elif note < 9: + msg = 'That\'s pretty good. Good work mate.' + elif note < 10: + msg = 'So close to being perfect...' + else: + msg = 'Wow ! Now this deserves our uttermost respect.\nPlease send \ +your code to python-projects@logilab.org' + return msg |
