Conditions | 1 |
Total Lines | 102 |
Code Lines | 84 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | #!/usr/bin/env python |
||
10 | def parse_args(): |
||
11 | parser = argparse.ArgumentParser() |
||
12 | |||
13 | parser.add_argument( |
||
14 | "--libvirt", |
||
15 | dest="libvirt", |
||
16 | default="qemu:///session", |
||
17 | help="What hypervisor should be used when installing VM." |
||
18 | ) |
||
19 | parser.add_argument( |
||
20 | "--kickstart", |
||
21 | dest="kickstart", |
||
22 | default="kickstarts/test_suite.cfg", |
||
23 | help="Path to a kickstart file for installation of a VM." |
||
24 | ) |
||
25 | parser.add_argument( |
||
26 | "--distro", |
||
27 | dest="distro", |
||
28 | required=True, |
||
29 | choices=['fedora', 'rhel7', 'centos7', 'rhel8', 'rhel9'], |
||
30 | help="What distribution to install." |
||
31 | ) |
||
32 | parser.add_argument( |
||
33 | "--domain", |
||
34 | dest="domain", |
||
35 | required=True, |
||
36 | help="What name should the new domain have." |
||
37 | ) |
||
38 | parser.add_argument( |
||
39 | "--disk-dir", |
||
40 | dest="disk_dir", |
||
41 | default=None, |
||
42 | help="Location of the VM qcow2 file." |
||
43 | ) |
||
44 | parser.add_argument( |
||
45 | "--ram", |
||
46 | dest="ram", |
||
47 | default=3072, |
||
48 | type=int, |
||
49 | help="Amount of RAM configured for the VM." |
||
50 | ) |
||
51 | parser.add_argument( |
||
52 | "--cpu", |
||
53 | dest="cpu", |
||
54 | default=2, |
||
55 | type=int, |
||
56 | help="Number of CPU cores configured for the VM." |
||
57 | ) |
||
58 | parser.add_argument( |
||
59 | "--network", |
||
60 | dest="network", |
||
61 | help="Network type/spec, ie. bridge=br0 or network=name." |
||
62 | ) |
||
63 | parser.add_argument( |
||
64 | "--disk", |
||
65 | dest="disk", |
||
66 | help="Disk type/spec, ie. pool=MyPool,bus=sata,cache=unsafe." |
||
67 | ) |
||
68 | parser.add_argument( |
||
69 | "--url", |
||
70 | dest="url", |
||
71 | default=None, |
||
72 | help="URL to an installation tree on a remote server." |
||
73 | ) |
||
74 | parser.add_argument( |
||
75 | "--extra-repo", |
||
76 | dest="extra_repo", |
||
77 | default=None, |
||
78 | help="URL to an extra repository to be used during installation (e.g. AppStream)." |
||
79 | ) |
||
80 | parser.add_argument( |
||
81 | "--dry", |
||
82 | dest="dry", |
||
83 | action="store_true", |
||
84 | help="Print command line instead of triggering command." |
||
85 | ) |
||
86 | parser.add_argument( |
||
87 | "--ssh-pubkey", |
||
88 | dest="ssh_pubkey", |
||
89 | default=None, |
||
90 | help="Path to an SSH public key which will be used to access the VM." |
||
91 | ) |
||
92 | parser.add_argument( |
||
93 | "--uefi", |
||
94 | dest="uefi", |
||
95 | choices=['secureboot', 'normal'], |
||
96 | help="Perform UEFI based installation, optionally with secure boot support." |
||
97 | ) |
||
98 | parser.add_argument( |
||
99 | "--install-gui", |
||
100 | dest="install_gui", |
||
101 | action='store_true', |
||
102 | help="Perform a GUI installation (default is installation without GUI)." |
||
103 | ) |
||
104 | parser.add_argument( |
||
105 | "--console", |
||
106 | dest="console", |
||
107 | action='store_true', |
||
108 | help="Connect to a serial console of the VM (to monitor installation progress)." |
||
109 | ) |
||
110 | |||
111 | return parser.parse_args() |
||
112 | |||
256 |