Changeset 583
- Timestamp:
- 10/17/07 17:29:49 (1 year ago)
- Files:
-
- pagoda/trunk/Pagoda/pagoda/command.py (modified) (2 diffs)
- pagoda/trunk/Pagoda/pagoda/site/manager.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pagoda/trunk/Pagoda/pagoda/command.py
r573 r583 68 68 while not site.get('dburi', ''): 69 69 site['dburi'] = raw_input( 70 "Enter site dburi [ex. sqlite:/// devdata.sqlite]: "70 "Enter site dburi [ex. sqlite:///mysite.sqlite]: " 71 71 ) 72 72 while not site.get('domains', ''): … … 118 118 ).lower() 119 119 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 123 130 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 9 9 __all__ = ['is_site', 'create_site', 'list_sites', 'remove_site'] 10 10 11 SITES_CONFIG_SECTION = SITES_DIR_PREFIX = "sites" 12 RESOURCES = ['static', 'templates', 'attachments'] 11 SITES_CONFIG_SECTION = SITES_DIR_PREFIX = 'sites' 12 RESOURCES = ['static', 'templates', 'attachments', 'trash'] 13 TRASH_DIR = 'trash' 13 14 CONFIG = None 14 15 … … 62 63 return False 63 64 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`. 65 def _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) 68 73 69 74 Valid resource names are stored in RESOURCES variable in this module. … … 79 84 (site_name, resource_name, RESOURCES) 80 85 ) 86 87 # Determine resource path 81 88 sites = get_config() 82 89 resource_module_path = sites.get(site_name).get(resource_name, None) … … 85 92 "Resource %r not found in Site %r." % (resource_name, site_name) 86 93 ) 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 88 106 89 107 def remove_site(site_name): … … 96 114 so for sites that use the controlling app's resources, those will have to be 97 115 removed manually. 116 117 Returns a list of paths that will need to be removed manually 98 118 99 119 """ … … 106 126 107 127 # Remove site-specific resource directories 128 app_resources = [] 108 129 for resource in RESOURCES: 109 resource_path = _get_site_resource(site_name, resource)130 is_site_specific, resource_path = _get_resource(site_name, resource) 110 131 # 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: 113 133 shutil.rmtree(resource_path) 134 else: 135 app_resources.append(resource_path) 114 136 115 137 # Remove site directory, if it exists 116 138 package = get_package_name() 117 site_dir = pkg_resources.resource_filename(118 p ackage,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 120 142 ) 121 143 if os.path.exists(site_dir): … … 126 148 del sites[site_name] 127 149 save_site_config() 150 151 # Return list of non-site-specific resource directories 152 return app_resources 128 153 129 154 def list_sites(): … … 145 170 package = get_package_name() 146 171 if not use_app_resources: 147 site_dir = pkg_resources.resource_filename(148 p ackage,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 150 175 ) 151 176 make_module(site_dir) 152 177 153 # Create any necessary directory structure for new site, 154 # and store resource paths in configuration 178 # Determine where resources should be saved 155 179 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) 157 181 module_prefix = [package, SITES_DIR_PREFIX, site_name] 158 182 else: 159 183 path_prefix = "" 160 184 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]: 162 197 module = ".".join(module_prefix + [resource]) 163 198 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) 169 212 170 213 # Write config to disk … … 175 218 package = get_package_name() 176 219 config_filepath = os.path.abspath( 177 pkg_resources.resource_filename(178 p ackage,179 "%s/sites.cfg" % SITES_DIR_PREFIX220 os.path.join( 221 pkg_resources.resource_filename(package, SITES_DIR_PREFIX), 222 'sites.cfg' 180 223 ) 181 224 ) 225 182 226 # If sites.cfg doesn't exist, create it and its parent directories 183 227 if not os.path.exists(config_filepath):
