Conditions | 5 |
Total Lines | 164 |
Code Lines | 52 |
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 | # -*- coding: utf-8 -*- |
||
43 | def __init__(self, settings): |
||
44 | """Parse configuration file.""" |
||
45 | |||
46 | ### |
||
47 | # General |
||
48 | ### |
||
49 | |||
50 | mandatory_msg = \ |
||
51 | 'ERROR: {} configuration is mandatory. Set it before continuing.' |
||
52 | self.DEPOT_STORAGE_DIR = settings.get( |
||
53 | 'depot_storage_dir', |
||
54 | ) |
||
55 | if not self.DEPOT_STORAGE_DIR: |
||
56 | raise Exception( |
||
57 | mandatory_msg.format('depot_storage_dir') |
||
58 | ) |
||
59 | self.DEPOT_STORAGE_NAME = settings.get( |
||
60 | 'depot_storage_name', |
||
61 | ) |
||
62 | if not self.DEPOT_STORAGE_NAME: |
||
63 | raise Exception( |
||
64 | mandatory_msg.format('depot_storage_name') |
||
65 | ) |
||
66 | self.PREVIEW_CACHE_DIR = settings.get( |
||
67 | 'preview_cache_dir', |
||
68 | ) |
||
69 | if not self.PREVIEW_CACHE_DIR: |
||
70 | raise Exception( |
||
71 | 'ERROR: preview_cache_dir configuration is mandatory. ' |
||
72 | 'Set it before continuing.' |
||
73 | ) |
||
74 | |||
75 | self.DATA_UPDATE_ALLOWED_DURATION = int(settings.get( |
||
76 | 'content.update.allowed.duration', |
||
77 | 0, |
||
78 | )) |
||
79 | |||
80 | self.WEBSITE_TITLE = settings.get( |
||
81 | 'website.title', |
||
82 | 'TRACIM', |
||
83 | ) |
||
84 | |||
85 | self.WEBSITE_BASE_URL = settings.get( |
||
86 | 'website.base_url', |
||
87 | '', |
||
88 | ) |
||
89 | |||
90 | # TODO - G.M - 26-03-2018 - [Cleanup] These params seems deprecated for tracimv2, # nopep8 |
||
91 | # Verify this |
||
92 | # |
||
93 | # self.WEBSITE_HOME_TITLE_COLOR = settings.get( |
||
94 | # 'website.title.color', |
||
95 | # '#555', |
||
96 | # ) |
||
97 | # self.WEBSITE_HOME_IMAGE_PATH = settings.get( |
||
98 | # '/assets/img/home_illustration.jpg', |
||
99 | # ) |
||
100 | # self.WEBSITE_HOME_BACKGROUND_IMAGE_PATH = settings.get( |
||
101 | # '/assets/img/bg.jpg', |
||
102 | # ) |
||
103 | # |
||
104 | |||
105 | self.WEBSITE_SERVER_NAME = settings.get( |
||
106 | 'website.server_name', |
||
107 | None, |
||
108 | ) |
||
109 | |||
110 | if not self.WEBSITE_SERVER_NAME: |
||
111 | self.WEBSITE_SERVER_NAME = urlparse(self.WEBSITE_BASE_URL).hostname |
||
112 | logger.warning( |
||
113 | self, |
||
114 | 'NOTE: Generated website.server_name parameter from ' |
||
115 | 'website.base_url parameter -> {0}' |
||
116 | .format(self.WEBSITE_SERVER_NAME) |
||
117 | ) |
||
118 | |||
119 | self.WEBSITE_HOME_TAG_LINE = settings.get( |
||
120 | 'website.home.tag_line', |
||
121 | '', |
||
122 | ) |
||
123 | self.WEBSITE_SUBTITLE = settings.get( |
||
124 | 'website.home.subtitle', |
||
125 | '', |
||
126 | ) |
||
127 | self.WEBSITE_HOME_BELOW_LOGIN_FORM = settings.get( |
||
128 | 'website.home.below_login_form', |
||
129 | '', |
||
130 | ) |
||
131 | |||
132 | self.WEBSITE_TREEVIEW_CONTENT = settings.get( |
||
133 | 'website.treeview.content', |
||
134 | ) |
||
135 | |||
136 | self.USER_AUTH_TOKEN_VALIDITY = int(settings.get( |
||
137 | 'user.auth_token.validity', |
||
138 | '604800', |
||
139 | )) |
||
140 | |||
141 | # TODO - G.M - 27-03-2018 - [Email] Restore email config |
||
142 | ### |
||
143 | # EMAIL related stuff (notification, reply) |
||
144 | ### |
||
145 | # |
||
146 | # self.EMAIL_NOTIFICATION_NOTIFIED_EVENTS = [ |
||
147 | # # ActionDescription.COMMENT, |
||
148 | # # ActionDescription.CREATION, |
||
149 | # # ActionDescription.EDITION, |
||
150 | # # ActionDescription.REVISION, |
||
151 | # # ActionDescription.STATUS_UPDATE |
||
152 | # ] |
||
153 | # |
||
154 | # self.EMAIL_NOTIFICATION_NOTIFIED_CONTENTS = [ |
||
155 | # # ContentType.Page, |
||
156 | # # ContentType.Thread, |
||
157 | # # ContentType.File, |
||
158 | # # ContentType.Comment, |
||
159 | # # ContentType.Folder -- Folder is skipped |
||
160 | # ] |
||
161 | # if settings.get('email.notification.from'): |
||
162 | # raise Exception( |
||
163 | # 'email.notification.from configuration is deprecated. ' |
||
164 | # 'Use instead email.notification.from.email and ' |
||
165 | # 'email.notification.from.default_label.' |
||
166 | # ) |
||
167 | # |
||
168 | # self.EMAIL_NOTIFICATION_FROM_EMAIL = settings.get( |
||
169 | # 'email.notification.from.email', |
||
170 | # ) |
||
171 | # self.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = settings.get( |
||
172 | # 'email.notification.from.default_label' |
||
173 | # ) |
||
174 | # self.EMAIL_NOTIFICATION_REPLY_TO_EMAIL = settings.get( |
||
175 | # 'email.notification.reply_to.email', |
||
176 | # ) |
||
177 | # self.EMAIL_NOTIFICATION_REFERENCES_EMAIL = settings.get( |
||
178 | # 'email.notification.references.email' |
||
179 | # ) |
||
180 | # self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_HTML = settings.get( |
||
181 | # 'email.notification.content_update.template.html', |
||
182 | # ) |
||
183 | # self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_TEXT = settings.get( |
||
184 | # 'email.notification.content_update.template.text', |
||
185 | # ) |
||
186 | # self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML = settings.get( |
||
187 | # 'email.notification.created_account.template.html', |
||
188 | # './tracim/templates/mail/created_account_body_html.mak', |
||
189 | # ) |
||
190 | # self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_TEXT = settings.get( |
||
191 | # 'email.notification.created_account.template.text', |
||
192 | # './tracim/templates/mail/created_account_body_text.mak', |
||
193 | # ) |
||
194 | # self.EMAIL_NOTIFICATION_CONTENT_UPDATE_SUBJECT = settings.get( |
||
195 | # 'email.notification.content_update.subject', |
||
196 | # ) |
||
197 | # self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_SUBJECT = settings.get( |
||
198 | # 'email.notification.created_account.subject', |
||
199 | # '[{website_title}] Created account', |
||
200 | # ) |
||
201 | # self.EMAIL_NOTIFICATION_PROCESSING_MODE = settings.get( |
||
202 | # 'email.notification.processing_mode', |
||
203 | # ) |
||
204 | # |
||
205 | self.EMAIL_NOTIFICATION_ACTIVATED = asbool(settings.get( |
||
206 | 'email.notification.activated', |
||
207 | )) |
||
437 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.