def flocker_push_file(self, src, dst=None, key=None): self._flocker_validate_availability() # check that src is a file within the workspace if not src.startswith('/'): src = os.path.join(self.path, src) if not os.path.exists(src): raise Exception('pushed file does not exist: %s' % src) if not os.path.isfile(src): raise Exception('pushed file is not a file: %s' % src) if not src.startswith(self.path): raise Exception('pushed file not stored inside workspace: %s' % src) if not dst: dst = os.path.basename(src) if dst.startswith('/'): raise Exception('pushed file destination is absolute path: %s' % dst) if not self.ftpclient: self.ftpclient = ftpclient.FtpClient(self, self.config['flocker'], key=key) self.ftpclient.push_file(src, dst) metadata = self.ftpclient.get_metadata() metadata['key'] = self.ftpclient.dirname return metadata
def flocker_initial(self, existing_key=None, custom_key=None): self._flocker_validate_availability() if existing_key and custom_key: raise Exception( 'existing_key and custom_key cannot be set at the same time.') if existing_key: if not self.ftpclient: self.ftpclient = ftpclient.FtpClient(self, self.config['flocker'], key=existing_key) else: self.ftpclient.switch_dirname(existing_key=existing_key) if custom_key: if not self.ftpclient: self.ftpclient = ftpclient.FtpClient(self, self.config['flocker']) self.ftpclient.switch_dirname(custom_key=custom_key) else: self.ftpclient.switch_dirname(custom_key=custom_key)
def flocker_set_metadata(self, key=None, contact=None, asset=None, comment=None): self._flocker_validate_availability() if not self.ftpclient: self.ftpclient = ftpclient.FtpClient(self, self.config['flocker']) self.ftpclient.set_metadata(contact, asset, comment) metadata = self.ftpclient.get_metadata() return metadata
def flocker_get_file(self, remote, local): self._flocker_validate_availability() if local: local = self._valid_path(local) else: raise Exception('Local file should be valid path: %s' % remote) if remote.startswith('/'): raise Exception('Remote file should be relative path: %s' % remote) if not self.ftpclient: self.ftpclient = ftpclient.FtpClient(self, self.config['flocker']) self.ftpclient.get_file(remote, local)
def flocker_push_string(self, string, dst, key=None, timeout=30): self._flocker_validate_availability() if type(string) not in [str, unicode]: raise Exception('pushed string is not a string: %s' % type(string)) if dst.startswith('/'): raise Exception('pushed file destination is absolute path: %s' % dst) if not self.ftpclient: self.ftpclient = ftpclient.FtpClient(self, self.config['flocker'], key=key) self.ftpclient.push_string(string, dst, timeout) metadata = self.ftpclient.get_metadata() metadata['key'] = self.ftpclient.dirname return metadata