Changeset 14

Show
Ignore:
Timestamp:
05/17/06 17:09:19 (7 years ago)
Author:
mk
Message:

Allow user to specify configuration directory.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mk/cheesecake/cheesecake_index.py

    r11 r14  
    119119    """ 
    120120 
    121     def __init__(self, name="", url="", path="", sandbox=None,  
     121    def __init__(self, name="", url="", path="", sandbox=None, config=None, 
    122122                verbose=False, quiet=False): 
    123123        """ 
     
    133133        if not os.path.isdir(self.sandbox): 
    134134            os.mkdir(self.sandbox) 
     135        self.config = config 
    135136        self.verbose = verbose 
    136137        self.quiet = quiet 
     
    208209        self.critical_cheese_dirs = ["doc", "test"] 
    209210 
    210     def get_config(self): 
     211    def get_config(self, config_dir=None): 
    211212        """ 
    212213        Retrieve values from configuration file 
    213214        """ 
    214         self.config = get_pkg_config(self.short_pkg_name
     215        self.config = get_pkg_config(self.short_pkg_name, config_dir
    215216        for config_var in ["INDEX_PYPI_DOWNLOAD", "INDEX_PYPI_DISTANCE", 
    216217            "INDEX_URL_DOWNLOAD", "INDEX_UNPACK", "INDEX_UNPACK_DIR", 
     
    967968                      default="/tmp/cheesecake_sandbox",  
    968969                      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)") 
    969973    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", 
    970974                      default=False, help="verbose output (default=False)") 
     
    984988    path = options.path 
    985989    sandbox = options.sandbox 
     990    config = options.config 
    986991    verbose = options.verbose 
    987992    quiet = options.quiet 
     
    992997 
    993998    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) 
    9951001        c.compute_cheesecake_index() 
    9961002    except CheesecakeError, e: 
  • branches/mk/cheesecake/config.py

    r13 r14  
    3434) 
    3535 
    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 "~": 
     36def 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: 
    4144        # can't get it...fall back to defaults 
    4245        print "Couldn't expand ~ (home directory)" 
     
    4447    else: 
    4548        # 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) 
    4951        # 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) 
    5153        if not os.path.isfile(cfile): 
    5254            try: 
     
    6163            except OSError, e: 
    6264                pass 
    63  
    6465        else: 
    6566            # 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) 
    6768            try: 
    6869                my_config = __import__('%s_config' % package, globals(), locals()).my_config 
  • branches/mk/tests/test_config.py

    r11 r14  
    11import os, sys, shutil 
     2import tempfile 
    23import _path_cheesecake 
    34 
     
    2627        for key, value in my_config.items(): 
    2728            assert config.get(key) == value 
     29 
     30 
     31class 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