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