Skip to content

Commit

Permalink
Updated strings (#51)
Browse files Browse the repository at this point in the history
* Updated strings

* Changed single quotes to double quotes
  • Loading branch information
svenkat19 authored Jul 25, 2021
1 parent b6b7660 commit 26cf13f
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 111 deletions.
23 changes: 11 additions & 12 deletions src/flashbake/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def commit(control_config, hot_files, quiet_mins):
if not (hot_files.contains(pending_file)):
continue

logging.debug('Parsing status line %s to determine commit action' % line)
logging.debug(f'Parsing status line {line} to determine commit action')

# remove files that will be considered for commit
hot_files.remove(pending_file)
Expand All @@ -76,9 +76,9 @@ def commit(control_config, hot_files, quiet_mins):
# add the file to the list to include in the commit
if pending_mod < now:
to_commit.append(pending_file)
logging.debug('Flagging file, %s, for commit.' % pending_file)
logging.debug(f'Flagging file, {pending_file}, for commit.' )
else:
logging.debug('Change for file, %s, is too recent.' % pending_file)
logging.debug(f'Change for file, {pending_file}, is too recent.')
_capture_deleted(hot_files, line)

logging.debug('Examining unknown or unchanged files.')
Expand All @@ -90,7 +90,7 @@ def commit(control_config, hot_files, quiet_mins):
# this shouldn't happen since HotFiles.addfile uses glob.iglob to expand
# the original file lines which does so based on what is in project_dir
if not os.path.exists(control_file):
logging.debug('%s does not exist yet.' % control_file)
logging.debug(f'{control_file} does not exist yet.' )
hot_files.putabsent(control_file)
continue

Expand All @@ -105,7 +105,7 @@ def commit(control_config, hot_files, quiet_mins):
# needed for git < 1.7.0.4
if status_output.find('did not match') > 0:
hot_files.putneedsadd(control_file)
logging.debug('%s exists but is unknown by git.' % control_file)
logging.debug(f'{control_file} exists but is unknown by git.')
else:
logging.error('Unknown error occurred!')
logging.error(status_output)
Expand All @@ -115,19 +115,19 @@ def commit(control_config, hot_files, quiet_mins):
# error
control_re = re.compile('\<' + re.escape(control_file) + '\>')
if control_re.search(status_output) == None:
logging.debug('%s has no uncommitted changes.' % control_file)
logging.debug(f'{control_file} has no uncommitted changes.')
# if anything hits this block, we need to figure out why
else:
logging.error('%s is in the status message but failed other tests.' % control_file)
logging.error('Try \'git status "%s"\' for more info.' % control_file)
logging.error(f'{control_file} is in the status message but failed other tests.' )
logging.error(f'Try \'git status "{control_file}"\' for more info.')

hot_files.addorphans(git_obj, control_config)

for plugin in control_config.file_plugins:
plugin.post_process(to_commit, hot_files, control_config)

if len(to_commit) > 0:
logging.info('Committing changes to known files, %s.' % to_commit)
logging.info(f'Committing changes to known files, {to_commit}.' )
message_file = context.buildmessagefile(control_config)
if not control_config.dry_run:
# consolidate the commit to be friendly to how git normally works
Expand Down Expand Up @@ -161,7 +161,7 @@ def purge(control_config, hot_files):
_capture_deleted(hot_files, line)

if len(hot_files.deleted) > 0:
logging.info('Committing removal of known files, %s.' % hot_files.deleted)
logging.info(f'Committing removal of known files, {hot_files.deleted}.' )
message_file = context.buildmessagefile(control_config)
if not control_config.dry_run:
# consolidate the commit to be friendly to how git normally works
Expand All @@ -185,8 +185,7 @@ def _handle_fatal(hot_files, git_status):
if git_status.startswith('fatal'):
logging.error('Fatal error from git.')
if git_status.startswith('fatal:'):
logging.error('Make sure "git init" was run in %s'
% os.path.realpath(hot_files.project_dir))
logging.error('Make sure "git init" was run in {}'.format(os.path.realpath(hot_files.project_dir)))
else:
logging.error(git_status)
sys.exit(1)
Expand Down
12 changes: 6 additions & 6 deletions src/flashbake/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def __fallback_next(*args):

args_len = len(args)
if (args_len < 1):
raise TypeError("expected at least 1 argument, got %d" %
args_len)
raise TypeError(f"expected at least 1 argument, got {args_len}"
)
if (args_len > 2):
raise TypeError("expected at most 2 arguments, got %d" %
args_len)
raise TypeError(f"expected at most 2 arguments, got {args_len}"
)
iterator = args[0]

try:
Expand All @@ -78,8 +78,8 @@ def __fallback_next(*args):
elif hasattr(iterator, 'next'):
return iterator.next()
else:
raise TypeError('%s object is not an iterator'
% type(iterator).__name__)
raise TypeError(f'{type(iterator).__name__} object is not an iterator'
)
except StopIteration:
if args_len == 2:
return args[1]
Expand Down
40 changes: 20 additions & 20 deletions src/flashbake/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def main():
try:
quiet_period = int(args[1])
except:
parser.error('Quiet minutes, "%s", must be a valid number.' % args[1])
parser.error(f'Quiet minutes, "{args[1]}", must be a valid number.' )
sys.exit(1)
try:
(hot_files, control_config) = control.parse_control(project_dir, control_file, control_config, hot_files)
Expand All @@ -105,7 +105,7 @@ def main():
logging.info('!!! No changes will be committed. !!!')
logging.info('========================================')
except (flashbake.git.VCError, flashbake.ConfigError) as error:
logging.error('Error: %s' % str(error))
logging.error(f'Error: {str(error)}' )
sys.exit(1)
except PluginError as error:
_handle_bad_plugin(error)
Expand Down Expand Up @@ -136,15 +136,15 @@ def multiple_projects():
parser.exit(err.code, msg)
exit_code = 0
for project in _locate_projects(args[0]):
print ("project: %s" % project)
print (f"project: {project}")
sys.argv = sys.argv[0:1] + flashbake_opts + [project] + args[1:]
try:
main()
except SystemExit as err:
if err.code != 0:
exit_code = err.code
logging.error("Error: 'flashbake' had an error for '%s'"
% project)
logging.error(f"Error: 'flashbake' had an error for '{project}'"
)
sys.exit(exit_code)


Expand Down Expand Up @@ -192,7 +192,7 @@ def _build_main_parser():
usage = "usage: %prog [options] <project_dir> [quiet_min]"

parser = FlashbakeOptionParser(
usage=usage, version='%s %s' % ('%prog', VERSION))
usage=usage, version='{0} {1}'.format('%prog', VERSION))
parser.add_option('-c', '--context', dest='context_only',
action='store_true', default=False,
help='just generate and show the commit message, don\'t check for changes')
Expand All @@ -217,7 +217,7 @@ def _build_main_parser():
def _build_multi_parser():
usage = "usage: %prog [options] <search_root> [quiet_min]"
parser = FlashbakeOptionParser(
usage=usage, version='%s %s' % ('%prog', VERSION))
usage=usage, version='{0} {1}'.format ('%prog', VERSION))
parser.add_option('-o', '--options', dest='flashbake_options', default='',
action='store', type='string', metavar='FLASHBAKE_OPTS',
help=("options to pass through to the 'flashbake' "
Expand All @@ -229,18 +229,18 @@ def _load_plugin_dirs(options, home_dir):
plugin_dir = join(home_dir, '.flashbake', 'plugins')
if os.path.exists(plugin_dir):
real_plugin_dir = realpath(plugin_dir)
logging.debug('3rd party plugin directory exists, adding: %s' % real_plugin_dir)
logging.debug(f'3rd party plugin directory exists, adding: {real_plugin_dir}' )
sys.path.insert(0, real_plugin_dir)
else:
logging.debug('3rd party plugin directory doesn\'t exist, skipping.')
logging.debug('Only stock plugins will be available.')

if options.plugin_dir != None:
if os.path.exists(options.plugin_dir):
logging.debug('Adding plugin directory, %s.' % options.plugin_dir)
logging.debug(f'Adding plugin directory, {options.plugin_dir}.' )
sys.path.insert(0, realpath(options.plugin_dir))
else:
logging.warn('Plugin directory, %s, doesn\'t exist.' % options.plugin_dir)
logging.warn(f'Plugin directory, {options.plugin_dir}, doesn\'t exist.')



Expand All @@ -263,7 +263,7 @@ def _find_control(parser, project_dir):
control_file = join(project_dir, '.control')

if not os.path.exists(control_file):
parser.error('Could not find .flashbake or .control file in directory, "%s".' % project_dir)
parser.error(f'Could not find .flashbake or .control file in directory, "{project_dir}".' )
return None
else:
return control_file
Expand All @@ -286,30 +286,30 @@ def _context_only(options, project_dir, control_file, control_config, hot_files)
os.remove(msg_filename)
return 0
except (flashbake.git.VCError, flashbake.ConfigError) as error:
logging.error('Error: %s' % str(error))
logging.error('Error: {}'.format(str(error)))
return 1
except PluginError as error:
_handle_bad_plugin(error)
return 1


def _handle_bad_plugin(plugin_error):
logging.debug('Plugin error, %s.' % plugin_error)
logging.debug(f'Plugin error, {plugin_error}.' )
if plugin_error.reason == PLUGIN_ERRORS.unknown_plugin or plugin_error.reason == PLUGIN_ERRORS.invalid_plugin: #@UndefinedVariable
logging.error('Cannot load plugin, %s.' % plugin_error.plugin_spec)
logging.error(f'Cannot load plugin, {plugin_error.plugin_spec}.' )
return

if plugin_error.reason == PLUGIN_ERRORS.missing_attribute: #@UndefinedVariable
logging.error('Plugin, %s, doesn\'t have the needed plugin attribute, %s.' \
% (plugin_error.plugin_spec, plugin_error.name))
logging.error(f'Plugin, {plugin_error.plugin_spec}, doesn\'t have the needed plugin attribute, {plugin_error.name}.' \
)
return

if plugin_error.reason == PLUGIN_ERRORS.invalid_attribute: #@UndefinedVariable
logging.error('Plugin, %s, has an invalid plugin attribute, %s.' \
% (plugin_error.plugin_spec, plugin_error.name))
logging.error(f'Plugin, {plugin_error.plugin_spec}, has an invalid plugin attribute, {plugin_error.name}.' \
)
return

if plugin_error.reason == PLUGIN_ERRORS.missing_property:
logging.error('Plugin, %s, requires the config option, %s, but it was missing.' \
% (plugin_error.plugin_spec, plugin_error.name))
logging.error(f'Plugin, {plugin_error.plugin_spec}, requires the config option, {plugin_error.name}, but it was missing.' \
)
return
4 changes: 2 additions & 2 deletions src/flashbake/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
def parse_control(project_dir, control_file, config=None, results=None):
""" Parse the dot-control file to get config options and hot files. """

logging.debug('Checking %s' % control_file)
logging.debug(f'Checking {control_file}' )

if None == results:
hot_files = flashbake.HotFiles(project_dir)
Expand Down Expand Up @@ -58,7 +58,7 @@ def prepare_control(hot_files, control_config):
control_config.init()
logging.debug("loading file plugins")
for plugin in control_config.file_plugins:
logging.debug("running plugin %s" % plugin)
logging.debug(f"running plugin {plugin}" )
plugin.pre_process(hot_files, control_config)
return (hot_files, control_config)

2 changes: 1 addition & 1 deletion src/flashbake/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init_env(self, git_path):
self.env.update(os.environ)
if git_path != None:
new_path = self.env['PATH']
new_path = '%s%s%s' % (git_path, os.pathsep, new_path)
new_path = '{0}{1}{2}'.format(git_path, os.pathsep, new_path)
self.env['PATH'] = new_path

if __name__ == "__main__":
Expand Down
17 changes: 9 additions & 8 deletions src/flashbake/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def __init__(self, reason, plugin_spec, name=None):
self.name = name
def __str__(self):
if self.name == None:
return '%s: %s' % (self.reason, self.plugin_spec)
return f'{self.reason}: {self.plugin_spec}'
else:
return '%s, %s: %s' % (self.plugin_spec, self.reason, self.name)
return f'{self.plugin_spec}, {self.reason}: {self.name}'


def service_and_prefix(plugin_spec):
Expand Down Expand Up @@ -72,7 +72,7 @@ def share_property(self, name, type=None, plugin_spec=None):
if plugin_spec:
parsed = service_and_prefix(plugin_spec)
property_prefix = parsed[1]
self.__shared_prop_defs.append(('%s_%s' % (property_prefix, name), type))
self.__shared_prop_defs.append((f'{property_prefix}_{name}', type))
else:
self.__shared_prop_defs.append((name, type))
except AttributeError:
Expand All @@ -85,7 +85,7 @@ def share_properties(self, config):
def capture_properties(self, config):
try:
for prop in self.__property_defs:
assert len(prop) == 4, "Property definition, %s, is invalid" % (prop,)
assert len(prop) == 4, f"Property definition, {prop}, is invalid"
self.__capture_property(config, *prop)
except AttributeError:
raise Exception('Call AbstractPlugin.__init__ in your plugin\'s __init__.')
Expand All @@ -101,7 +101,7 @@ def dependencies(self):
def __capture_property(self, config, name, type=None, required=False, default=None):
""" Move a property, if present, from the ControlConfig to the daughter
plugin. """
config_name = '%s_%s' % (self.property_prefix, name)
config_name = f'{self.property_prefix}_{name}'
if required and not config_name in config.extra_props:
raise PluginError(PLUGIN_ERRORS.missing_property, self.plugin_spec, config_name)

Expand All @@ -116,16 +116,17 @@ def __capture_property(self, config, name, type=None, required=False, default=No
value = type(value)
except:
raise flashbake.ConfigError(
'The value, %s, for option, %s, could not be parsed as %s.'
% (value, name, type))
f"The value, {value}, for option, {name}, could not be parsed as {type}."
)

self.__dict__[name] = value

def abstract(self):
""" borrowed this from Norvig
http://norvig.com/python-iaq.html """
import inspect
caller = inspect.getouterframes(inspect.currentframe())[1][3]
raise NotImplementedError('%s must be implemented in subclass' % caller)
raise NotImplementedError(f'{caller} must be implemented in subclass' )


class AbstractMessagePlugin(AbstractPlugin):
Expand Down
2 changes: 1 addition & 1 deletion src/flashbake/plugins/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def addcontext(self, message_file, config):
""" Add a static message to the commit context. """

if self.message is not None:
message_file.write('%s\n' % self.message)
message_file.write(f'{self.message}\n' )

return True
10 changes: 5 additions & 5 deletions src/flashbake/plugins/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def addcontext(self, message_file, config):
% {'item_count' : len(last_items), 'feed_title' : title, 'author' or 'dc:creator' : self.author})
for item in last_items:
# edit the '%s' if you want to add a label, like 'Title %s' to the output
message_file.write('%s\n' % item['title'])
message_file.write('%s\n' % item['link'])
message_file.write(f'{item["title"]}\n')
message_file.write(f'{item["link"]}\n')
else:
message_file.write('Couldn\'t fetch entries from feed, %s.\n' % self.url)

Expand Down Expand Up @@ -83,9 +83,9 @@ def __fetchfeed(self):

return (feed_title, by_creator)
except urllib.error.HTTPError as e:
logging.error('Failed with HTTP status code %d' % e.code)
logging.error(f'Failed with HTTP status code {e.code}')
return (None, {})
except urllib.error.URLError as e:
logging.error('Plugin, %s, failed to connect with network.' % self.__class__)
logging.debug('Network failure reason, %s.' % e.reason)
logging.error(f'Plugin, {self.__class__}, failed to connect with network.')
logging.debug('Network failure reason, {e.reason}.')
return (None, {})
2 changes: 1 addition & 1 deletion src/flashbake/plugins/itunes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def addcontext(self, message_file, config):
if info is None:
message_file.write('Couldn\'t get current track.\n')
else:
message_file.write('Currently playing in iTunes:\n%s' % info)
message_file.write(f'Currently playing in iTunes:\n{info}' )

return True

Expand Down
Loading

0 comments on commit 26cf13f

Please sign in to comment.