Changeset 583

Show
Ignore:
Timestamp:
10/17/07 17:29:49 (1 year ago)
Author:
ian
Message:

Sites now have trash directories for each resource

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pagoda/trunk/Pagoda/pagoda/command.py

    r573 r583  
    6868        while not site.get('dburi', ''): 
    6969            site['dburi'] = raw_input( 
    70                 "Enter site dburi [ex. sqlite:///devdata.sqlite]: " 
     70                "Enter site dburi [ex. sqlite:///mysite.sqlite]: " 
    7171            ) 
    7272        while not site.get('domains', ''): 
     
    118118            ).lower() 
    119119        if confirmation.startswith('r'): 
    120             print "Removing site: %s" % site_name 
    121             remove_site(site_name) 
    122             print "Success: Site removed." % site_name 
     120            print "Removing site: %r" % site_name 
     121            remaining_resource_dirs = remove_site(site_name) 
     122            print "Success: Site %r removed." % site_name 
     123            if remaining_resource_dirs: 
     124                print("\nNote: The following resource directories were not \n" 
     125                      "removed because they are in use by the controlling \n" 
     126                      "TurboGears application.\n" 
     127                      "These directories will need to be removed manually:\n") 
     128                for dir in remaining_resource_dirs: 
     129                    print dir 
    123130        else: 
    124             print "No changes were made." % site_name 
    125  
    126          
     131            print "No changes were made." 
  • pagoda/trunk/Pagoda/pagoda/site/manager.py

    r578 r583  
    99__all__ = ['is_site', 'create_site', 'list_sites', 'remove_site'] 
    1010 
    11 SITES_CONFIG_SECTION = SITES_DIR_PREFIX = "sites" 
    12 RESOURCES = ['static', 'templates', 'attachments'] 
     11SITES_CONFIG_SECTION = SITES_DIR_PREFIX = 'sites' 
     12RESOURCES = ['static', 'templates', 'attachments', 'trash'] 
     13TRASH_DIR = 'trash' 
    1314CONFIG = None 
    1415 
     
    6263        return False 
    6364 
    64 def _get_site_resource(site_name, resource_name): 
    65     """Return the file path to a site resource. 
    66  
    67     For the specified site, return the physical file path to `resource_name`. 
     65def _get_resource(site_name, resource_name): 
     66    """Return a tuple containing the file path to a site resource. 
     67 
     68    For the specified site, return the physical file path to `resource_name`, 
     69    and a flag indicating if it is a site-specific resource (as opposed to 
     70    a resource from the controlling TurboGears application) 
     71     
     72    Return tuple looks like: (is_site_specific, resource_path) 
    6873 
    6974    Valid resource names are stored in RESOURCES variable in this module. 
     
    7984            (site_name, resource_name, RESOURCES) 
    8085        ) 
     86         
     87    # Determine resource path 
    8188    sites = get_config() 
    8289    resource_module_path = sites.get(site_name).get(resource_name, None) 
     
    8592            "Resource %r not found in Site %r." % (resource_name, site_name) 
    8693        ) 
    87     return pkg_resources.resource_filename(resource_module_path, '') 
     94    resource_path = pkg_resources.resource_filename(resource_module_path, '') 
     95     
     96    # Determine if resource is site-specific or not 
     97    site_suffix = os.path.join(SITES_DIR_PREFIX, site_name, resource_name) 
     98    if resource_path.endswith(site_suffix): 
     99        is_site_specific = True 
     100    else: 
     101        is_site_specific = False 
     102         
     103    # Return results 
     104    return (is_site_specific, resource_path) 
     105     
    88106 
    89107def remove_site(site_name): 
     
    96114    so for sites that use the controlling app's resources, those will have to be  
    97115    removed manually. 
     116     
     117    Returns a list of paths that will need to be removed manually 
    98118 
    99119    """ 
     
    106126 
    107127    # Remove site-specific resource directories 
     128    app_resources = [] 
    108129    for resource in RESOURCES: 
    109         resource_path = _get_site_resource(site_name, resource) 
     130        is_site_specific, resource_path = _get_resource(site_name, resource) 
    110131        # If resource is site-specific, remove it 
    111         site_suffix = os.path.join(SITES_DIR_PREFIX, site_name, resource) 
    112         if resource_path.endswith(site_suffix): 
     132        if is_site_specific: 
    113133            shutil.rmtree(resource_path) 
     134        else: 
     135            app_resources.append(resource_path) 
    114136 
    115137    # Remove site directory, if it exists 
    116138    package = get_package_name() 
    117     site_dir = pkg_resources.resource_filename
    118         package,  
    119         "%s/%s" % (SITES_DIR_PREFIX, site_name) 
     139    site_dir = os.path.join
     140        pkg_resources.resource_filename(package, SITES_DIR_PREFIX), 
     141        site_name 
    120142    ) 
    121143    if os.path.exists(site_dir): 
     
    126148    del sites[site_name] 
    127149    save_site_config() 
     150     
     151    # Return list of non-site-specific resource directories 
     152    return app_resources 
    128153 
    129154def list_sites(): 
     
    145170    package = get_package_name() 
    146171    if not use_app_resources: 
    147         site_dir = pkg_resources.resource_filename
    148             package
    149             "%s/%s" % (SITES_DIR_PREFIX, site_name) 
     172        site_dir = os.path.join
     173            pkg_resources.resource_filename(package, SITES_DIR_PREFIX)
     174            site_name 
    150175        ) 
    151176        make_module(site_dir) 
    152177 
    153     # Create any necessary directory structure for new site, 
    154     # and store resource paths in configuration 
     178    # Determine where resources should be saved 
    155179    if not use_app_resources: 
    156         path_prefix = "%s/%s/" % (SITES_DIR_PREFIX, site_name) 
     180        path_prefix = os.path.join(SITES_DIR_PREFIX, site_name) 
    157181        module_prefix = [package, SITES_DIR_PREFIX, site_name] 
    158182    else: 
    159183        path_prefix = "" 
    160184        module_prefix = [package] 
    161     for resource in RESOURCES: 
     185 
     186    # Create main trash directory 
     187    sites[site_name][TRASH_DIR] = ".".join(module_prefix + [TRASH_DIR]) 
     188    trash_path = os.path.join( 
     189        pkg_resources.resource_filename(package, path_prefix), 
     190        TRASH_DIR 
     191    ) 
     192    make_module(trash_path) 
     193     
     194    # Create any needed resource directories for the new site, 
     195    # and store resource paths in configuration 
     196    for resource in [r for r in RESOURCES if r != TRASH_DIR]: 
    162197        module = ".".join(module_prefix + [resource]) 
    163198        sites[site_name][resource] = module 
    164         path = pkg_resources.resource_filename( 
    165             package, 
    166             "%s%s" % (path_prefix, resource) 
    167         ) 
    168         make_module(path) 
     199        # Make resource directory 
     200        resource_path = os.path.join( 
     201            pkg_resources.resource_filename(package, path_prefix),  
     202            resource 
     203        ) 
     204        make_module(resource_path) 
     205        # Make a trash directory for this resource 
     206        trash_path = os.path.join( 
     207            pkg_resources.resource_filename(package, path_prefix),  
     208            TRASH_DIR, 
     209            resource 
     210        ) 
     211        make_module(trash_path) 
    169212 
    170213    # Write config to disk 
     
    175218    package = get_package_name() 
    176219    config_filepath = os.path.abspath( 
    177         pkg_resources.resource_filename
    178             package,  
    179             "%s/sites.cfg" % SITES_DIR_PREFIX 
     220        os.path.join
     221            pkg_resources.resource_filename(package, SITES_DIR_PREFIX), 
     222            'sites.cfg' 
    180223        ) 
    181224    ) 
     225     
    182226    # If sites.cfg doesn't exist, create it and its parent directories 
    183227    if not os.path.exists(config_filepath): 

Log in as guest/pagoda to create tickets