def job_prep(self): """This is a job setup function. The job prep will parse the payload and determine the best course of action """ for key, val in self.pay_load: self.container = key work_q = generators.manager_queue(iters=val) # Prep Nova for Upload self.oscmd = novacommands.NovaAuth(self.args, work_q) if self.args.get('con_per_dir'): head, sep, tail = val[0].partition(key) self.base_path = '%s%s' % (head, sep) elif self.args.get('archive'): self.base_path = '%s%s' % (os.getenv('HOME'), os.sep) elif self.args.get('delete'): self.base_path = None elif self.args.get('download'): real_path = os.path.realpath(self.args.get('source')) if not os.path.isdir(real_path): self.mkdir_p(real_path) print('Downloaded Objects will be found here : "%s"' % real_path) self.base_path = real_path elif os.path.isdir(self.args.get('source')): self.base_path = os.path.realpath(self.args.get('source')) else: break_down = os.path.realpath(self.args.get('source')) _fn = os.path.basename(break_down) self.base_path = break_down.strip(_fn) # Prep our Container if any([self.args.get('download'), self.args.get('delete')]): pass else: self.oscmd.container_create(self.container) if self.args.get('cdn_enabled'): self.oscmd.enable_cdn(self.container) # If not verbose or Debug mode, show me a nice spinner _it = IndicatorThread(work_q=work_q) if not any([self.args.get('verbose'), self.args.get('debug'), self.args.get('os_verbose'), self.args.get('quiet')]): thd = _it.indicator_thread() else: thd = None generators.worker_proc(job_action=self.run_function, multipools=self.multipools, work_q=work_q) if thd: thd.terminate()
def archive(self): """The archive function was made to simply build a Tarball. With this method multiple "sources" can be used as they will simply preserve the upload source from within the tarball. """ from turbolift.operations import IndicatorThread for source in self.tur_arg['source']: if not os.path.exists(source): raise exceptions.NoSource('Source Provided is broken or does' ' not exist %s' % source) self.basic_file_structure() self.tur_arg['multipools'] = 1 _it = IndicatorThread().indicator_thread() _cf = compressfiles.Compressor(self.tur_arg, self.gfn).compress_files() _it.terminate() cfs = os.path.getsize(_cf) print('MESSAGE\t: Uploading... %s bytes' % cfs) pay_load = {self.tur_arg['container']: [_cf]} cfactions.CloudFilesActions(tur_arg=self.tur_arg, pay_load=pay_load.items()).job_prep() # Nuke the left over file if there was one. if self.tur_arg.get('no_cleanup'): print('MESSAGE\t: Archive Location = %s' % _cf) else: print('MESSAGE\t: Removing Local Copy of the Archive') if os.path.exists(_cf): os.remove(_cf) else: print('File "%s" Did not exist so there was nothing to delete.' % _cf)