| Conditions | 10 |
| Total Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Complex classes like sqlexport_main() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | #!/usr/bin/env python3 |
||
| 13 | def sqlexport_main(): |
||
| 14 | """ |
||
| 15 | Wrapper around CSV export function. |
||
| 16 | |||
| 17 | Invoke :func:`bbarchivist.sqlutils.export_sql_db`. |
||
| 18 | """ |
||
| 19 | parser = scriptutils.default_parser("bb-sqlexport", "SQL-related tools") |
||
| 20 | parser.add_argument( |
||
| 21 | "-p", |
||
| 22 | "--pop", |
||
| 23 | dest="popsw", |
||
| 24 | help="Pop this OS and SW from the database", |
||
| 25 | nargs=2, |
||
| 26 | metavar=("OS", "SW"), |
||
| 27 | default=False) |
||
| 28 | parser.add_argument( |
||
| 29 | "-l", |
||
| 30 | "--list", |
||
| 31 | dest="list", |
||
| 32 | help="List entries in database", |
||
| 33 | action="store_true", |
||
| 34 | default=False) |
||
| 35 | parser.add_argument( |
||
| 36 | "-a", |
||
| 37 | "--available", |
||
| 38 | dest="avail", |
||
| 39 | help="List only available entries in database (implies -l)", |
||
| 40 | action="store_true", |
||
| 41 | default=False) |
||
| 42 | parser.set_defaults() |
||
| 43 | args = parser.parse_args(sys.argv[1:]) |
||
| 44 | if args.list or args.avail: |
||
| 45 | args.popsw = False |
||
| 46 | if not args.popsw and not args.list and not args.avail: |
||
| 47 | sqlutils.export_sql_db() |
||
| 48 | elif args.popsw: |
||
| 49 | sqlutils.pop_sw_release(*args.popsw) |
||
| 50 | print("POPPED: OS {0} - SW {1}".format(*args.popsw)) |
||
| 51 | else: |
||
| 52 | rellist = sqlutils.list_sw_releases(args.avail) |
||
| 53 | if rellist is not None: |
||
| 54 | for rel in rellist: |
||
| 55 | affix = " " if rel[2] == "available" else "" |
||
| 56 | print("OS {0} - SR {1} - {2} - {3}".format( |
||
| 57 | rel[0], rel[1], (rel[2] + affix), rel[3])) |
||
| 58 | |||
| 62 |