def load_resource(self, ignore_prefix='_'): """ Move resource files to output dir Example: <themes/default/resources/css/main.css> will bee moved to <output/css/main.css> """ # this method must be called after load_config method config = getattr(self, '_config', None) assert 'theme_dir' in config assert 'output_dir' in config topdir = os.path.join(config['theme_dir'], 'resources') dst_dir = os.path.join(config['output_dir'], config['root'].strip('/')) topdir = topdir.rstrip(os.path.sep) assert os.path.isdir(topdir) self._files = {} for root, dirs, files in os.walk(topdir): for dir in dirs: if dir.startswith(ignore_prefix): dirs.remove(dir) for file in files: if file.startswith(ignore_prefix): continue src_path = os.path.join(root, file) dst_sub = src_path[len(topdir):] # dst_sub should have os.path.sep prefixed dst_path = dst_dir + dst_sub safe_copy(src_path, dst_path) self._files[file] = config['root'].rstrip('/') + dst_sub
def set_link(self): cate = self.category.name if cate is not 'uncategorized': self.link = self._config['root'] + cate + '/' + self.name + '/' else: self.link = self._config['root'] + self.name + '/' # TODO to be removed from here # set source if cate is not 'uncategorized': dst_dir = os.path.join(self._config['output_dir'], self._config['root'].strip('/'), cate, self.name + '.txt') else: dst_dir = os.path.join(self._config['output_dir'], self._config['root'].strip('/'), self.name + '.txt') # if not dst_dir.endswith(os.path.sep): # dst_dir += os.path.sep safe_copy(self.path, dst_dir) if cate is not 'uncategorized': self.source = self._config['root'] + cate + '/' + \ self.name + '.txt' else: self.source = self._config['root'] + self.name + '.txt'