| Conditions | 16 |
| Total Lines | 119 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | 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 _post() 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 | """A setuptools based setup module. |
||
| 28 | def _post(): |
||
| 29 | import icon_font_to_png |
||
| 30 | from pkg_resources import get_distribution |
||
| 31 | from appdirs import AppDirs |
||
| 32 | import requests |
||
| 33 | import re |
||
| 34 | from distutils.version import LooseVersion |
||
| 35 | import os |
||
| 36 | |||
| 37 | # fontawesome 4.7 |
||
| 38 | dirs = AppDirs( |
||
| 39 | os.path.join( |
||
| 40 | 'pandoc_latex_tip', |
||
| 41 | get_distribution('pandoc_latex_tip').version, |
||
| 42 | 'fontawesome', |
||
| 43 | '4.7' |
||
| 44 | ) |
||
| 45 | ) |
||
| 46 | directory = dirs.user_data_dir |
||
| 47 | if not path.exists(directory): |
||
| 48 | makedirs(directory) |
||
| 49 | downloader = icon_font_to_png.FontAwesomeDownloader(directory) |
||
| 50 | downloader.css_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/v4.7.0/css/font-awesome.css' |
||
| 51 | downloader.ttf_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/v4.7.0/fonts/fontawesome-webfont.ttf' |
||
| 52 | downloader.download_files() |
||
| 53 | |||
| 54 | # fontawesome 5.0 |
||
| 55 | dirs = AppDirs( |
||
| 56 | os.path.join( |
||
| 57 | 'pandoc_latex_tip', |
||
| 58 | get_distribution('pandoc_latex_tip').version, |
||
| 59 | 'fontawesome', |
||
| 60 | '5.0' |
||
| 61 | ) |
||
| 62 | ) |
||
| 63 | try: |
||
| 64 | versions = requests.get('https://api.github.com/repos/FortAwesome/Font-Awesome/tags').json() |
||
| 65 | except ValueError: |
||
| 66 | import sys |
||
| 67 | sys.stderr.write('Unable to get the last version number of the Font-Awesome package on github\n') |
||
| 68 | sys.exit(1) |
||
| 69 | |||
| 70 | latest = '5.0' |
||
| 71 | for version in versions: |
||
| 72 | if re.match('^5.0', version['name']) and LooseVersion(version['name']) > LooseVersion(latest): |
||
| 73 | latest = version['name'] |
||
| 74 | |||
| 75 | directory = dirs.user_data_dir |
||
| 76 | if not path.exists(directory): |
||
| 77 | makedirs(directory) |
||
| 78 | |||
| 79 | downloader = icon_font_to_png.FontAwesomeDownloader(directory) |
||
| 80 | downloader.css_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/' + latest + '/web-fonts-with-css/css/fontawesome.css' |
||
| 81 | # brands |
||
| 82 | downloader.ttf_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/' + latest + '/web-fonts-with-css/webfonts/fa-brands-400.ttf' |
||
| 83 | downloader.download_files() |
||
| 84 | # regular |
||
| 85 | downloader.ttf_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/' + latest + '/web-fonts-with-css/webfonts/fa-regular-400.ttf' |
||
| 86 | downloader.download_files() |
||
| 87 | # solid |
||
| 88 | downloader.ttf_url = 'https://cdn.rawgit.com/FortAwesome/Font-Awesome/' + latest + '/web-fonts-with-css/webfonts/fa-solid-900.ttf' |
||
| 89 | downloader.download_files() |
||
| 90 | |||
| 91 | # glyphicons 3.3 |
||
| 92 | dirs = AppDirs( |
||
| 93 | os.path.join( |
||
| 94 | 'pandoc_latex_tip', |
||
| 95 | get_distribution('pandoc_latex_tip').version, |
||
| 96 | 'glyphicons', |
||
| 97 | '3.3' |
||
| 98 | ) |
||
| 99 | ) |
||
| 100 | directory = dirs.user_data_dir |
||
| 101 | if not path.exists(directory): |
||
| 102 | makedirs(directory) |
||
| 103 | downloader = icon_font_to_png.FontAwesomeDownloader(directory) |
||
| 104 | downloader.css_url = 'https://cdn.rawgit.com/twbs/bootstrap/v3.3.7/dist/css/bootstrap.css' |
||
| 105 | downloader.ttf_url = 'https://cdn.rawgit.com/twbs/bootstrap/v3.3.7/dist/fonts/glyphicons-halflings-regular.ttf' |
||
| 106 | downloader.download_files() |
||
| 107 | original = open(os.path.join(directory, "bootstrap.css"), "rt") |
||
| 108 | modified = open(os.path.join(directory, "bootstrap-modified.css"), "w") |
||
| 109 | index = 0 |
||
| 110 | for line in original: |
||
| 111 | if index >= 1067: |
||
| 112 | break |
||
| 113 | elif index >= 280: |
||
| 114 | modified.write(line) |
||
| 115 | index = index + 1 |
||
| 116 | original.close() |
||
| 117 | modified.close() |
||
| 118 | |||
| 119 | # material design 2.4 |
||
| 120 | dirs = AppDirs( |
||
| 121 | os.path.join( |
||
| 122 | 'pandoc_latex_tip', |
||
| 123 | get_distribution('pandoc_latex_tip').version, |
||
| 124 | 'materialdesign', |
||
| 125 | '2.4' |
||
| 126 | ) |
||
| 127 | ) |
||
| 128 | try: |
||
| 129 | versions = requests.get('https://api.github.com/repos/Templarian/MaterialDesign-Webfont/tags').json() |
||
| 130 | except ValueError: |
||
| 131 | import sys |
||
| 132 | sys.stderr.write('Unable to get the last version number of the MaterialDesign-Webfont package on github\n') |
||
| 133 | sys.exit(1) |
||
| 134 | |||
| 135 | latest = 'v2.4' |
||
| 136 | for version in versions: |
||
| 137 | if re.match('^v2.4', version['name']) and LooseVersion(version['name']) > LooseVersion(latest): |
||
| 138 | latest = version['name'] |
||
| 139 | |||
| 140 | directory = dirs.user_data_dir |
||
| 141 | if not path.exists(directory): |
||
| 142 | makedirs(directory) |
||
| 143 | downloader = icon_font_to_png.FontAwesomeDownloader(directory) |
||
| 144 | downloader.css_url = 'https://cdn.rawgit.com/Templarian/MaterialDesign-Webfont/' + latest + '/css/materialdesignicons.css' |
||
| 145 | downloader.ttf_url = 'https://cdn.rawgit.com/Templarian/MaterialDesign-Webfont/' + latest + '/fonts/materialdesignicons-webfont.ttf' |
||
| 146 | downloader.download_files() |
||
| 147 | |||
| 262 |