root/trunk/cheesecake/config.py

Revision 11, 2.7 kB (checked in by grig, 7 years ago)

Added ez_setup.py so that users are forced to upgrade to new version of setuptools.

Changed installation to alternate directory to use --root instead of --home.

Line 
1 """
2 Cheesecake configuration file
3 """
4
5 import os, sys
6
7 # Set defaults
8 _config = dict(
9     INDEX_PYPI_DOWNLOAD = 50,
10     INDEX_PYPI_DISTANCE = 5,
11     INDEX_URL_DOWNLOAD  = 25,
12     INDEX_UNPACK        = 25,
13     INDEX_UNPACK_DIR    = 15,
14     INDEX_INSTALL       = 50,
15     INDEX_FILE_CRITICAL = 15,
16     INDEX_FILE          = 10,
17     INDEX_REQUIRED_FILES = 100,
18     INDEX_FILE_PYC      = -20,
19     INDEX_DIR_CRITICAL  = 25,
20     INDEX_DIR           = 20,
21     INDEX_DIR_EMPTY     = 5,
22     MAX_INDEX_DOCSTRINGS = 100, # max. percentage of modules/classes/methods/functions with docstrings
23     MAX_INDEX_UNITTESTS  = 100, # max. percentage of methods/functions that are unit tested
24     MAX_INDEX_PYLINT     = 100, # max. pylint score
25     cheese_files = ["readme", "install", "changelog",
26                     "news", "faq", "todo", "thanks",
27                     "license", "announce", "setup.py",
28                     ],
29     critical_cheese_files = ["readme", "license", "setup.py"],
30     cheese_dirs = ["doc", "test", "example", "demo"],
31     critical_cheese_dirs = ["doc", "test"],
32     exclude_files = [],
33     exclude_dirs = [],
34 )
35
36 def get_pkg_config(package):
37     # try getting the user's home directory
38     homedir = "~"
39     homedir = os.path.expanduser(homedir)
40     if homedir is "~":
41         # can't get it...fall back to defaults
42         print "Couldn't expand ~ (home directory)"
43         pass
44     else:
45         # check for .cheesecake dir and create it if it's not there
46         cheesecake_dir = os.path.join(homedir, ".cheesecake")
47         if not os.path.isdir(cheesecake_dir):
48             os.mkdir(cheesecake_dir)
49         # check for config. file and create it if it's not there
50         cfile = os.path.join(cheesecake_dir, "%s_config.py" % package)
51         if not os.path.isfile(cfile):
52             try:
53                 c = open(cfile, 'w')
54                 c.write("my_config = {\n")
55                 keys = _config.keys()
56                 keys.sort()
57                 for key in keys:
58                     c.write("\t'%s': %s,\n" % (key, _config[key]))
59                 c.write("}\n")
60                 c.close()
61             except OSError, e:
62                 pass
63
64         else:
65             # if we find the file, update _config with contents of the file
66             sys.path.insert(0, cheesecake_dir)
67             try:
68                 from my_config import my_config
69                 _config.update(my_config)
70             except ImportError, e:
71                 pass
72     return _config
73
74 def get(key, default=None):
75     """
76     Get the configuration value for the given key.
77     """
78     return _config.get(key, default)
79
80 def set(key, value):
81     """
82     Set the configuration value for the given key.
83     """
84     _config[key] = value
Note: See TracBrowser for help on using the browser.