def fetchFolderTree(self, path='/content/dam', csv_file='output/folder_tree.csv', props=['jcr:path', 'jcr:content/jcr:title']): ''' Fetches the folder structure under the given path and writes it to an output csv file ''' folder_data = [] url = Assets.URL['fetchFolderTree'] + path url = url.replace('$props', ' '.join(props)) logging.debug(url) response = self.conn.get(url) if response.success: folder_data.append(props) for folder in response.data[Assets.CFG['assets_key']]: folder_props = [] for key in props: folder_props.append(self._metaVal(folder, key)) folder_data.append(folder_props) logging.debug("Writing folder list to : " + csv_file) dir, fname = dir_n_file(csv_file, 'csv') env = Env(dir) env.writeCSV(fname, data=folder_data) else: logging.error('Error fetching folder list') logging.error('Failed due to : '+response.message) logging.error('Empty list returned') return folder_data
def list(self, path='/content/dam', csv_dump=False, csv_file='output/asset_list.csv'): ''' Get the list of all assets under the path given as parameter and optionally write it to a CSV file ''' asset_list = [] url = Assets.URL['list'] + path logging.debug('URL : '+url) response = self.conn.get(url) if response.success: for e in response.data[Assets.CFG['assets_key']]: asset_list.append(e[Assets.CFG['path_key']]) else: logging.error('Error getting the assets list') logging.error('Failed due to : '+response.message) logging.error('Empty list returned') if csv_dump or csv_file: logging.debug("Writing asset list of assets to : " + csv_file) dir, fname = dir_n_file(csv_file, 'csv') env = Env(dir) env.writeCSV(fname, list=asset_list) return asset_list
def createFolderTree(self, path='/content/dam', srcDir=None, srcList=None, ignore_error = False): ''' Creates the folder tree structure in DAM under the given path, reflecting the structure in local dir ''' dirList = [] if srcList: if isinstance(srcList, list): dirList += cleanseDirList('', srcList, path ) elif isinstance(srcList, str): headers, types, csv_data = self._csvRead(srcList, False, False) for row in csv_data: dirList += cleanseDirList('', row, path ) else: logging.error('Invalid input for srcList') if srcDir: env = Env(srcDir) dirList += cleanseDirList(srcDir, env.listDirs(), path ) logging.debug('Creating Folders for - '+ str(dirList)) overall_status = True for dir in dirList: logging.debug('Creating Folder - '+ dir) status = self.createFolder(dir) overall_status &= status return overall_status
def xprops(self, path='/content/dam', props=['jcr:path','jcr:content/metadata/dc:title'], csv_file='output/asset_props.csv'): ''' Extracts the metadata properties of the assets under the given path and writes it to an output csv file ''' asset_data = [] url = Assets.URL['xprops'] + path url = url.replace('$props', ' '.join(props)) logging.debug(url) response = self.conn.get(url) if response.success: asset_data.append(props) for asset in response.data[Assets.CFG['assets_key']]: asset_props = [] for key in props: asset_props.append(self._metaVal(asset, key)) asset_data.append(asset_props) logging.debug("Writing asset list of assets to : " + csv_file) dir, fname = dir_n_file(csv_file, 'csv') env = Env(dir) env.writeCSV(fname, data=asset_data) return True else: logging.error('Error extracting asset properties') logging.error('Failed due to : '+response.message) logging.error('Empty list returned') return False
def uploadFolder(self, dir='upload', path='/content/dam'): ''' Upload all the assets under the dir parameter. Folder structure under dir replicated onto DAM, under the path specified ''' env = Env(dir) path_map = cleansePaths(dir, env.listFiles(), path ) overall_status = True for file in path_map: logging.debug('Uploading file - '+ file) status = self.uploadAsset(file, path_map[file]) overall_status &= status return overall_status
def downloadFolder(self, path='/content/dam', dir='download', retain_dam_path=True): ''' Downlods all assets under the mentioned DAM path to the dir ''' asset_list = self.list(path) logging.debug("Asset list : "+str(asset_list)) overall_status = True if asset_list: env = Env(dir) for asset in asset_list: status = self._download(asset, env, retain_dam_path) overall_status &= status return overall_status
def downloadAsset(self, asset_path, dir='download', retain_dam_path=False): ''' Downlods the asset to the dir ''' env = Env(dir) return self._download(asset_path, env, retain_dam_path)