Conditions | 11 |
Total Lines | 71 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 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:
Complex classes like downloader_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 |
||
88 | def downloader_main(osversion, radioversion=None, softwareversion=None, |
||
89 | localdir=None, debricks=True, radios=True, cores=False, altsw=None): |
||
90 | """ |
||
91 | Archivist's download function, abstracted out. |
||
92 | |||
93 | :param osversion: OS version, 10.x.y.zzzz. |
||
94 | :type osversion: str |
||
95 | |||
96 | :param radioversion: Radio version, 10.x.y.zzzz. Can be guessed. |
||
97 | :type radioversion: str |
||
98 | |||
99 | :param softwareversion: Software release, 10.x.y.zzzz. Can be guessed. |
||
100 | :type softwareversion: str |
||
101 | |||
102 | :param localdir: Working directory. Local by default. |
||
103 | :type localdir: str |
||
104 | |||
105 | :param debricks: Whether to download debrick OS files. True by default. |
||
106 | :type debricks: bool |
||
107 | |||
108 | :param radios: Whether to download radio files. True by default. |
||
109 | :type radios: bool |
||
110 | |||
111 | :param cores: Whether to download core OS files. False by default. |
||
112 | :type cores: bool |
||
113 | |||
114 | :param altsw: Radio software release, if not the same as OS. |
||
115 | :type altsw: str |
||
116 | """ |
||
117 | radioversion = scriptutils.return_radio_version(osversion, radioversion) |
||
118 | softwareversion, swchecked = scriptutils.return_sw_checked(softwareversion, osversion) |
||
119 | if altsw: |
||
120 | altsw, altchecked = scriptutils.return_radio_sw_checked(altsw, radioversion) |
||
121 | if localdir is None: |
||
122 | localdir = os.getcwd() |
||
123 | scriptutils.standard_preamble("downloader", osversion, softwareversion, radioversion, altsw) |
||
124 | |||
125 | baseurl, alturl = scriptutils.get_baseurls(softwareversion, altsw) |
||
126 | osurls, corurls, radurls = utilities.bulk_urls(baseurl, osversion, radioversion, cores, alturl) |
||
127 | |||
128 | # Check availability of software releases |
||
129 | scriptutils.check_sw(baseurl, softwareversion, swchecked) |
||
130 | if altsw: |
||
131 | scriptutils.check_radio_sw(alturl, altsw, altchecked) |
||
132 | |||
133 | # Check availability of OS, radio |
||
134 | if debricks: |
||
135 | scriptutils.check_os_bulk(osurls) |
||
136 | if cores: |
||
137 | scriptutils.check_os_bulk(corurls) |
||
138 | if radios: |
||
139 | radurls, radioversion = scriptutils.check_radio_bulk(radurls, radioversion) |
||
140 | |||
141 | # Download files |
||
142 | print("BEGIN DOWNLOADING...") |
||
143 | urllist = [] |
||
144 | if debricks: |
||
145 | urllist += osurls |
||
146 | if radios: |
||
147 | urllist += radurls |
||
148 | if cores: |
||
149 | urllist += corurls |
||
150 | if urllist: |
||
151 | networkutils.download_bootstrap(urllist, localdir, workers=5) |
||
152 | print("ALL FILES DOWNLOADED") |
||
153 | else: |
||
154 | print("NO FILES TO DOWNLOAD!") |
||
155 | raise SystemExit |
||
156 | |||
157 | # Test bar files |
||
158 | scriptutils.test_bar_files(localdir, urllist) |
||
159 | |||
163 |