Mercurial > p > roundup > code
comparison roundup/admin.py @ 7773:ac2c034542e6
chore: reduce nesting if/elif/else blocks; uneeded var assignment
also add lint hint
Leave chained if/elif/else blocks after returns if it doesn't reduce
nesting.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 02 Mar 2024 13:48:40 -0500 |
| parents | 417c8ddc98ac |
| children | d7d68da9878f |
comparison
equal
deleted
inserted
replaced
| 7772:6a1c1cd69582 | 7773:ac2c034542e6 |
|---|---|
| 1496 except ValueError: | 1496 except ValueError: |
| 1497 if args[0] != "list": | 1497 if args[0] != "list": |
| 1498 raise UsageError(_( | 1498 raise UsageError(_( |
| 1499 'Argument must be setting=value, was given: %s.') % | 1499 'Argument must be setting=value, was given: %s.') % |
| 1500 args[0]) | 1500 args[0]) |
| 1501 else: | 1501 |
| 1502 print(_("Current settings and values " | 1502 print(_("Current settings and values " |
| 1503 "(NYI - not yet implemented):")) | 1503 "(NYI - not yet implemented):")) |
| 1504 is_verbose = self.settings['verbose'] | 1504 is_verbose = self.settings['verbose'] |
| 1505 for key in sorted(self.settings.keys()): | 1505 for key in sorted(self.settings.keys()): |
| 1506 if key.startswith('_') and not is_verbose: | 1506 if key.startswith('_') and not is_verbose: |
| 1507 continue | 1507 continue |
| 1508 print(" %s=%s" % (key, self.settings[key])) | 1508 print(" %s=%s" % (key, self.settings[key])) |
| 1509 if is_verbose: | 1509 if is_verbose: |
| 1510 print(" %s" % self.settings_help[key]) | 1510 print(" %s" % self.settings_help[key]) |
| 1511 | 1511 |
| 1512 return | 1512 return |
| 1513 | 1513 |
| 1514 if setting not in self.settings: | 1514 if setting not in self.settings: |
| 1515 raise UsageError(_('Unknown setting %s. Try "pragma list".') | 1515 raise UsageError(_('Unknown setting %s. Try "pragma list".') |
| 1516 % setting) | 1516 % setting) |
| 1517 if isinstance(self.settings[setting], bool): | 1517 if isinstance(self.settings[setting], bool): |
| 1718 cl = self.db.getclass(permission.klass) | 1718 cl = self.db.getclass(permission.klass) |
| 1719 class_props = cl.getprops(protected=True) | 1719 class_props = cl.getprops(protected=True) |
| 1720 for p in permission.properties: | 1720 for p in permission.properties: |
| 1721 if p in class_props: | 1721 if p in class_props: |
| 1722 continue | 1722 continue |
| 1723 else: | 1723 |
| 1724 bad_props.append(p) | 1724 bad_props.append(p) |
| 1725 if bad_props: | 1725 if bad_props: |
| 1726 sys.stdout.write(_( | 1726 sys.stdout.write(_( |
| 1727 '\n **Invalid properties for %(class)s: ' | 1727 '\n **Invalid properties for %(class)s: ' |
| 1728 '%(props)s\n\n') % { | 1728 '%(props)s\n\n') % { |
| 1729 "class": permission.klass, | 1729 "class": permission.klass, |
| 2010 return 1 | 2010 return 1 |
| 2011 command, function = functions[0] | 2011 command, function = functions[0] |
| 2012 | 2012 |
| 2013 if command in ['genconfig', 'templates']: | 2013 if command in ['genconfig', 'templates']: |
| 2014 try: | 2014 try: |
| 2015 ret = function(args[1:]) | 2015 return function(args[1:]) |
| 2016 return ret | |
| 2017 except UsageError as message: | 2016 except UsageError as message: |
| 2018 return self.usageError_feedback(message, function) | 2017 return self.usageError_feedback(message, function) |
| 2019 | 2018 |
| 2020 # make sure we have a tracker_home | 2019 # make sure we have a tracker_home |
| 2021 while not self.tracker_home: | 2020 while not self.tracker_home: |
| 2133 self.password = login_env[1] | 2132 self.password = login_env[1] |
| 2134 self.separator = None | 2133 self.separator = None |
| 2135 self.print_designator = 0 | 2134 self.print_designator = 0 |
| 2136 self.verbose = 0 | 2135 self.verbose = 0 |
| 2137 for opt, arg in opts: | 2136 for opt, arg in opts: |
| 2138 if opt == '-h': | 2137 if opt == '-h': # noqa: RET505 - allow elif after returns |
| 2139 self.usage() | 2138 self.usage() |
| 2140 return 0 | 2139 return 0 |
| 2141 elif opt == '-v': | 2140 elif opt == '-v': |
| 2142 print('%s (python %s)' % (roundup_version, | 2141 print('%s (python %s)' % (roundup_version, |
| 2143 sys.version.split()[0])) | 2142 sys.version.split()[0])) |
