def set_uploader(self, requested_uploader, keep=False): """Returns an uploader object. 1 of S3, SCP, SFTP. SFTP uploaders not supported at this time. Args: requested_uploader (string): Either s3 or scp Returns: object (instance): Uploader object """ self.keep = keep if isinstance(requested_uploader, six.string_types) is False: raise UploaderError('Must pass str to set_uploader', expected=True) self.uploader = self.mgr.get_plugin(requested_uploader, init=True) if self.uploader is None: log.debug('PLUGIN_NAMESPACE: %s', self.mgr.PLUGIN_NAMESPACE) raise UploaderPluginError('Requested uploader is not installed', expected=True) msg = 'Requested uploader: {}'.format(requested_uploader) log.debug(msg) try: _files = os.listdir(self.deploy_dir) except OSError: _files = [] files = [] for f in _files: files.append(os.path.join(self.deploy_dir, f)) self.files = remove_dot_files(files)
def set_uploader(self, requested_uploader, keep=False): """Sets the named upload plugin. Args: requested_uploader (string): Either s3 or scp """ self.keep = keep if isinstance(requested_uploader, six.string_types) is False: raise UploaderError('Must pass str to set_uploader', expected=True) self.uploader = self.mgr.get_plugin(requested_uploader, init=True) if self.uploader is None: log.debug('PLUGIN_NAMESPACE: %s', self.mgr.PLUGIN_NAMESPACE) raise UploaderPluginError('Requested uploader is not installed', expected=True) msg = 'Requested uploader: {}'.format(requested_uploader) log.debug(msg) # ToDo: Move this into it's own function. # Call this new function in the upload method try: _files = os.listdir(self.deploy_dir) except OSError: _files = [] files = [] for f in _files: files.append(os.path.join(self.deploy_dir, f)) self.files = remove_dot_files(files)
def _get_files_to_upload(self, files=None): if files: self.files = files else: try: _files = os.listdir(self.deploy_dir) except OSError: _files = [] files = [] for f in _files: files.append(os.path.join(self.deploy_dir, f)) self.files = remove_dot_files(files)
def _check_make_patch(self, json_data, name, platform): # Check to see if previous version is available to # make patch updates # Also calculates patch number log.info('Checking if patch creation is possible') if bsdiff4 is None: log.warning('Bsdiff is missing. Cannot create patches') return None src_file_path = None if os.path.exists(self.files_dir): with jms_utils.paths.ChDir(self.files_dir): files = os.listdir(os.getcwd()) files = remove_dot_files(files) # No src files to patch from. Exit quickly if len(files) == 0: return None # If latest not available in version file. Exit try: channel_dict = json_data['latest'][name]['channel'] latest = channel_dict[platform]['stable'] except KeyError: return None try: latest_platform = json_data[settings.UPDATES_KEY][name][latest] try: filename = latest_platform[platform]['file_name'] except KeyError: # ToDo: Remove in version 2.0 filename = latest_platform[platform]['filename'] # End ToDo except: return None src_file_path = os.path.join(self.files_dir, filename) try: patch_num = self.config['patches'][name] self.config['patches'][name] += 1 except KeyError: # If no patch number we will start at 1 patch_num = 1 if 'patches' not in self.config.keys(): self.config['patches'] = {} if name not in self.config['patches'].keys(): self.config['patches'][name] = patch_num + 1 num = patch_num + 1 log.debug('Patch Number: {}'.format(num)) return src_file_path, num return None
def _check_make_patch(self, json_data, name, platform): # Check to see if previous version is available to # make patch updates # Also calculates patch number log.info('Checking if patch creation is possible') if bsdiff4 is None: log.warning('Bsdiff is missing. Cannot create patches') return None src_file_path = None if os.path.exists(self.files_dir): with jms_utils.paths.ChDir(self.files_dir): files = os.listdir(os.getcwd()) files = remove_dot_files(files) # No src files to patch from. Exit quickly if len(files) == 0: return None # If latest not available in version file. Exit try: latest = json_data['latest'][name][platform] except KeyError: return None try: l_plat = json_data[settings.UPDATES_KEY][name][latest] filename = l_plat[platform]['filename'] except: return None src_file_path = os.path.join(self.files_dir, filename) try: patch_num = self.config['patches'][name] self.config['patches'][name] += 1 except KeyError: # If no patch number we will start at 100 try: patch_num = self.config['boot_strap'] except KeyError: patch_num = 100 if 'patches' not in self.config.keys(): self.config['patches'] = {} if name not in self.config['patches'].keys(): self.config['patches'][name] = patch_num + 1 num = patch_num + 1 log.debug('Patch Number: {}'.format(num)) return src_file_path, num return None
def set_uploader(self, requested_uploader): """Returns an uploader object. 1 of S3, SCP, SFTP. SFTP uploaders not supported at this time. Args: requested_uploader (string): Either s3 or scp Returns: object (instance): Uploader object """ if isinstance(requested_uploader, six.string_types) is False: raise UploaderError('Must pass str to set_uploader', expected=True) try: plugin = self.mgr[requested_uploader] except KeyError: log.debug('EP CACHE: {}'.format(self.mgr.ENTRY_POINT_CACHE)) raise UploaderPluginError('Requested uploader is not installed', expected=True) except Exception as err: # pragma: no cover log.debug('EP CACHE: {}'.format(self.mgr.ENTRY_POINT_CACHE)) log.error(str(err)) log.debug(str(err), exc_info=True) raise UploaderError('Requested uploader is not installed', expected=True) self.uploader = plugin.plugin() msg = 'Requested uploader: {}'.format(requested_uploader) log.debug(msg) try: files = os.listdir(self.deploy_dir) except OSError: files = [] files = remove_dot_files(files) self.uploader.init(object_bucket=self.object_bucket, ssh_username=self.ssh_username, ssh_remote_dir=self.ssh_remote_dir, ssh_host=self.ssh_host, files=files)
def _check_make_patch(self): # Check to see if previous version is available to # make patch updates. Also calculates patch number if self._json_data.get('latest') is not None: log.debug(json.dumps(self._json_data['latest'], indent=2)) log.debug('Checking if patch creation is possible') if bsdiff4 is None: log.warning('Bsdiff is missing. Cannot create patches') return if os.path.exists(self._files_dir): with ChDir(self._files_dir): files = os.listdir(os.getcwd()) log.debug('Found %s files in files dir', len(files)) files = remove_dot_files(files) # No src files to patch from. Exit quickly if len(files) == 0: log.debug('No src file to patch from') return _name = self._pkg_info.name _plat = self._pkg_info.platform _channel = self._pkg_info.channel if self._test is False: # If latest not available in version file. Exit try: log.debug('Looking for %s on %s', _name, _plat) latest = self._json_data['latest'][_name][_channel][_plat] log.debug('Found latest version for patches: %s', latest) except KeyError: log.debug('Cannot find latest version in version meta') return try: u_key = settings.UPDATES_KEY latest_platform = self._json_data[u_key][_name][latest] log.debug('Found latest platform for patches') try: filename = latest_platform[_plat]['filename'] log.debug('Found filename for patches') except KeyError: log.error('Found old version file. Please read ' 'the upgrade section in the docs.') log.debug('Found old verison file') return except Exception as err: log.debug(err, exc_info=True) return else: filename = self._filename log.debug('Generating src file path') self.src = os.path.join(self._files_dir, filename) log.debug('Source path: %s', self.src) if not os.path.exists(self.src): log.warning("Source path does not exist: %s", filename) return try: patch_num = self._config['patches'][_name] log.debug('Found patch number') self._config['patches'][_name] += 1 except KeyError: log.debug('Cannot find patch number') # If no patch number we will start at 1 patch_num = 1 if 'patches' not in self._config.keys(): log.debug('Adding patches to version meta') self._config['patches'] = {} if _name not in self._config['patches'].keys(): log.debug('Adding %s to patches version meta', _name) self._config['patches'][_name] = patch_num + 1 self.patch_num = patch_num + 1 log.debug('Patch Number: %s', self.patch_num) self.ok = True
def _check_make_patch(self, json_data, name, platform): # Check to see if previous version is available to # make patch updates. Also calculates patch number log.debug(json.dumps(json_data['latest'], indent=2)) log.info('Checking if patch creation is possible') if bsdiff4 is None: log.warning('Bsdiff is missing. Cannot create patches') return None src_file_path = None if os.path.exists(self.files_dir): with ChDir(self.files_dir): files = os.listdir(os.getcwd()) log.debug('Found %s files in files dir', len(files)) files = remove_dot_files(files) # No src files to patch from. Exit quickly if len(files) == 0: log.debug('No src file to patch from') return None # If latest not available in version file. Exit try: log.debug('Looking for %s on %s', name, platform) latest = json_data['latest'][name]['stable'][platform] log.debug('Found latest version for patches') except KeyError: log.debug('Cannot find latest version in version meta') return None try: latest_platform = json_data[settings.UPDATES_KEY][name][latest] log.debug('Found latest platform for patches') try: filename = latest_platform[platform]['filename'] log.debug('Found filename for patches') except KeyError: log.error('Found old version file. Please read ' 'the upgrade section in the docs.') log.debug('Found old verison file') return None except Exception as err: log.debug(err, exc_info=True) return None log.debug('Generating src file path') src_file_path = os.path.join(self.files_dir, filename) try: patch_num = self.config['patches'][name] log.debug('Found patch number') self.config['patches'][name] += 1 except KeyError: log.debug('Cannot find patch number') # If no patch number we will start at 1 patch_num = 1 if 'patches' not in self.config.keys(): log.debug('Adding patches to version meta') self.config['patches'] = {} if name not in self.config['patches'].keys(): log.debug('Adding %s to patches version meta', name) self.config['patches'][name] = patch_num + 1 num = patch_num + 1 log.debug('Patch Number: %s', num) return src_file_path, num return None
def test_remove_dot_files(self): bad_list = ['.DS_Store', 'test', 'stuff', '.trash'] good_list = ['test', 'stuff'] for n in remove_dot_files(bad_list): assert n in good_list
def _check_make_patch(self, json_data, name, platform): # Check to see if previous version is available to # make patch updates. Also calculates patch number log.debug(json.dumps(json_data['latest'], indent=2)) log.debug('Checking if patch creation is possible') if bsdiff4 is None: log.warning('Bsdiff is missing. Cannot create patches') return None if os.path.exists(self.files_dir): with ChDir(self.files_dir): files = os.listdir(os.getcwd()) log.debug('Found %s files in files dir', len(files)) files = remove_dot_files(files) # No src files to patch from. Exit quickly if len(files) == 0: log.debug('No src file to patch from') return None # If latest not available in version file. Exit try: log.debug('Looking for %s on %s', name, platform) latest = json_data['latest'][name]['stable'][platform] log.debug('Found latest version for patches') except KeyError: log.debug('Cannot find latest version in version meta') return None try: latest_platform = json_data[settings.UPDATES_KEY][name][latest] log.debug('Found latest platform for patches') try: filename = latest_platform[platform]['filename'] log.debug('Found filename for patches') except KeyError: log.error('Found old version file. Please read ' 'the upgrade section in the docs.') log.debug('Found old verison file') return None except Exception as err: log.debug(err, exc_info=True) return None log.debug('Generating src file path') src_file_path = os.path.join(self.files_dir, filename) try: patch_num = self.config['patches'][name] log.debug('Found patch number') self.config['patches'][name] += 1 except KeyError: log.debug('Cannot find patch number') # If no patch number we will start at 1 patch_num = 1 if 'patches' not in self.config.keys(): log.debug('Adding patches to version meta') self.config['patches'] = {} if name not in self.config['patches'].keys(): log.debug('Adding %s to patches version meta', name) self.config['patches'][name] = patch_num + 1 num = patch_num + 1 log.debug('Patch Number: %s', num) return src_file_path, num return None
def test_remove_dot_files(self): bad_list = [".DS_Store", "test", "stuff", ".trash"] good_list = ["test", "stuff"] for n in remove_dot_files(bad_list): assert n in good_list