Changeset 14
- Timestamp:
- 05/17/06 17:09:19 (7 years ago)
- Files:
-
- branches/mk/cheesecake/cheesecake_index.py (modified) (6 diffs)
- branches/mk/cheesecake/config.py (modified) (3 diffs)
- branches/mk/tests/test_config.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/mk/cheesecake/cheesecake_index.py
r11 r14 119 119 """ 120 120 121 def __init__(self, name="", url="", path="", sandbox=None, 121 def __init__(self, name="", url="", path="", sandbox=None, config=None, 122 122 verbose=False, quiet=False): 123 123 """ … … 133 133 if not os.path.isdir(self.sandbox): 134 134 os.mkdir(self.sandbox) 135 self.config = config 135 136 self.verbose = verbose 136 137 self.quiet = quiet … … 208 209 self.critical_cheese_dirs = ["doc", "test"] 209 210 210 def get_config(self ):211 def get_config(self, config_dir=None): 211 212 """ 212 213 Retrieve values from configuration file 213 214 """ 214 self.config = get_pkg_config(self.short_pkg_name )215 self.config = get_pkg_config(self.short_pkg_name, config_dir) 215 216 for config_var in ["INDEX_PYPI_DOWNLOAD", "INDEX_PYPI_DISTANCE", 216 217 "INDEX_URL_DOWNLOAD", "INDEX_UNPACK", "INDEX_UNPACK_DIR", … … 967 968 default="/tmp/cheesecake_sandbox", 968 969 help="directory where package will be unpacked (default=/tmp/cheesecake_sandbox)") 970 parser.add_option("-c", "--config", dest="config", 971 default=None, 972 help="directory with custom configuration (default=~/.cheesecake)") 969 973 parser.add_option("-v", "--verbose", action="store_true", dest="verbose", 970 974 default=False, help="verbose output (default=False)") … … 984 988 path = options.path 985 989 sandbox = options.sandbox 990 config = options.config 986 991 verbose = options.verbose 987 992 quiet = options.quiet … … 992 997 993 998 try: 994 c = Cheesecake(name=name, url=url, path=path, sandbox=sandbox, verbose=verbose, quiet=quiet) 999 c = Cheesecake(name=name, url=url, path=path, sandbox=sandbox, 1000 config=config, verbose=verbose, quiet=quiet) 995 1001 c.compute_cheesecake_index() 996 1002 except CheesecakeError, e: branches/mk/cheesecake/config.py
r13 r14 34 34 ) 35 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 "~": 36 def get_pkg_config(package, global_config_dir=None): 37 if global_config_dir is None: 38 global_config_dir = os.path.join("~", ".cheesecake") 39 40 # try resolving the user's home directory 41 global_config_dir = os.path.expanduser(global_config_dir) 42 43 if "~" in global_config_dir: 41 44 # can't get it...fall back to defaults 42 45 print "Couldn't expand ~ (home directory)" … … 44 47 else: 45 48 # 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 if not os.path.isdir(global_config_dir): 50 os.mkdir(global_config_dir) 49 51 # check for config. file and create it if it's not there 50 cfile = os.path.join( cheesecake_dir, "%s_config.py" % package)52 cfile = os.path.join(global_config_dir, "%s_config.py" % package) 51 53 if not os.path.isfile(cfile): 52 54 try: … … 61 63 except OSError, e: 62 64 pass 63 64 65 else: 65 66 # if we find the file, update _config with contents of the file 66 sys.path.insert(0, cheesecake_dir)67 sys.path.insert(0, global_config_dir) 67 68 try: 68 69 my_config = __import__('%s_config' % package, globals(), locals()).my_config branches/mk/tests/test_config.py
r11 r14 1 1 import os, sys, shutil 2 import tempfile 2 3 import _path_cheesecake 3 4 … … 26 27 for key, value in my_config.items(): 27 28 assert config.get(key) == value 29 30 31 class TestCheesecakeCustomConfigDir(object): 32 def setUp(self): 33 self.pkg_name = "random_project" 34 # Make temporary directory and place config file there. 35 self.custom_config_dir = tempfile.mkdtemp() 36 fd = file(os.path.join(self.custom_config_dir, 37 "%s_config.py" % self.pkg_name), "w") 38 fd.write("my_config = {'INDEX_FILE': 15}\n") 39 fd.close() 40 41 def tearDown(self): 42 #shutil.rmtree(self.custom_config_dir) 43 pass 44 45 def test_custom_config_dir(self): 46 from cheesecake import config 47 config_dict = config.get_pkg_config(self.pkg_name, 48 self.custom_config_dir) 49 # Make sure that default has been overriden. 50 assert config_dict['INDEX_FILE'] == 15
