Skip to content

Commit 7d93ba9

Browse files
committed
bin: Move class and login handling out of main()
This is a no-op
1 parent 2e72bb7 commit 7d93ba9

2 files changed

Lines changed: 63 additions & 48 deletions

File tree

bin/bugzilla

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,42 +1153,13 @@ def _do_set_attach(bz, opt, parser, args):
11531153

11541154

11551155
#################
1156-
# Main function #
1156+
# Main handling #
11571157
#################
11581158

1159-
def main(bzinstance=None):
1160-
parser = setup_parser()
1161-
(global_opt, args) = parser.parse_args()
1162-
1163-
if global_opt.generate_man:
1164-
generate_man_page()
1165-
return 0
1166-
1167-
if global_opt.debug:
1168-
log.setLevel(DEBUG)
1169-
elif global_opt.verbose:
1170-
log.setLevel(INFO)
1171-
else:
1172-
log.setLevel(WARN)
1173-
1174-
log.debug("Launched with command line: %s", " ".join(sys.argv))
1175-
1176-
# Get our action
1177-
if len(args) == 0:
1178-
parser.error("No command specified, command must be one of: %s" %
1179-
', '.join(cmdlist))
1180-
action = args.pop(0)
1181-
if action not in cmdlist:
1182-
parser.error("Unknown command '%s', command must be one of: %s" %
1183-
(action, ', '.join(cmdlist)))
1184-
1185-
# Parse action-specific args
1186-
action_parser = setup_action_parser(action)
1187-
(opt, args) = action_parser.parse_args(args)
1188-
1189-
# Connect to bugzilla
1190-
log.info('Connecting to %s', global_opt.bugzilla)
1191-
1159+
def _make_bz_instance(global_opt, parser):
1160+
"""
1161+
Build the Bugzilla instance we will use
1162+
"""
11921163
if global_opt.bztype == 'auto':
11931164
log.info('Autodetecting Bugzilla type')
11941165
bzclass = bugzilla.Bugzilla
@@ -1198,22 +1169,24 @@ def main(bzinstance=None):
11981169
else:
11991170
parser.error("bztype must be one of: %s" % str(bugzilla.classlist))
12001171

1201-
if bzinstance:
1202-
bz = bzinstance
1172+
if global_opt.cache_credentials:
1173+
cookiefile = global_opt.cookiefile or -1
1174+
tokenfile = global_opt.tokenfile or -1
12031175
else:
1204-
if global_opt.cache_credentials:
1205-
cookiefile = global_opt.cookiefile or -1
1206-
tokenfile = global_opt.tokenfile or -1
1207-
else:
1208-
cookiefile = None
1209-
tokenfile = None
1210-
bz = bzclass(url=global_opt.bugzilla,
1211-
cookiefile=cookiefile,
1212-
tokenfile=tokenfile,
1213-
sslverify=global_opt.sslverify)
1176+
cookiefile = None
1177+
tokenfile = None
12141178

1179+
bz = bzclass(url=global_opt.bugzilla,
1180+
cookiefile=cookiefile,
1181+
tokenfile=tokenfile,
1182+
sslverify=global_opt.sslverify)
1183+
return bz
12151184

1216-
# Handle 'login' action
1185+
1186+
def _handle_login(global_opt, parser, args, action, bz):
1187+
"""
1188+
Handle all login related bits
1189+
"""
12171190
is_login_command = (action == 'login')
12181191
force_login = is_login_command or global_opt.login
12191192

@@ -1243,6 +1216,48 @@ def main(bzinstance=None):
12431216
sys.exit(1)
12441217

12451218

1219+
def main(unittest_bz_instance=None):
1220+
parser = setup_parser()
1221+
(global_opt, args) = parser.parse_args()
1222+
1223+
if global_opt.generate_man:
1224+
generate_man_page()
1225+
return 0
1226+
1227+
if global_opt.debug:
1228+
log.setLevel(DEBUG)
1229+
elif global_opt.verbose:
1230+
log.setLevel(INFO)
1231+
else:
1232+
log.setLevel(WARN)
1233+
1234+
log.debug("Launched with command line: %s", " ".join(sys.argv))
1235+
1236+
# Get our action
1237+
if len(args) == 0:
1238+
parser.error("No command specified, command must be one of: %s" %
1239+
', '.join(cmdlist))
1240+
action = args.pop(0)
1241+
if action not in cmdlist:
1242+
parser.error("Unknown command '%s', command must be one of: %s" %
1243+
(action, ', '.join(cmdlist)))
1244+
1245+
# Parse action-specific args
1246+
action_parser = setup_action_parser(action)
1247+
(opt, args) = action_parser.parse_args(args)
1248+
1249+
# Connect to bugzilla
1250+
log.info('Connecting to %s', global_opt.bugzilla)
1251+
1252+
if unittest_bz_instance:
1253+
bz = unittest_bz_instance
1254+
else:
1255+
bz = _make_bz_instance(global_opt)
1256+
1257+
# Handle login options
1258+
_handle_login(global_opt, parser, args, action, bz)
1259+
1260+
12461261
###########################
12471262
# Run the actual commands #
12481263
###########################

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def clicomm(argv, bzinstance, returnmain=False, printcliout=False,
8383
print(" ".join(argv))
8484
print()
8585

86-
mainout = bugzillascript.main(bzinstance)
86+
mainout = bugzillascript.main(unittest_bz_instance=bzinstance)
8787
except SystemExit:
8888
sys_e = sys.exc_info()[1]
8989
ret = sys_e.code

0 commit comments

Comments
 (0)