(name, address, logger)
| 141 | |
| 142 | |
| 143 | def get_profile(name, address, logger): |
| 144 | try: |
| 145 | conn = sqlite3.connect(address) |
| 146 | with conn: |
| 147 | conn.row_factory = sqlite3.Row |
| 148 | cursor = conn.cursor() |
| 149 | |
| 150 | profile = select_profile_by_username(cursor, name) |
| 151 | |
| 152 | if profile is None: |
| 153 | add_profile(conn, cursor, name) |
| 154 | # reselect the table after adding data to get the proper `id` |
| 155 | profile = select_profile_by_username(cursor, name) |
| 156 | except Exception as exc: |
| 157 | logger.warning( |
| 158 | "Heeh! Error occurred while getting a DB profile for '{}':\n\t{}".format( |
| 159 | name, str(exc).encode("utf-8") |
| 160 | ) |
| 161 | ) |
| 162 | finally: |
| 163 | if conn: |
| 164 | # close the open connection |
| 165 | conn.close() |
| 166 | |
| 167 | profile = dict(profile) |
| 168 | profile_id = profile["id"] |
| 169 | # assign the id to its child in `Settings` class |
| 170 | Settings.profile["id"] = profile_id |
| 171 | |
| 172 | return profile_id |
| 173 | |
| 174 | |
| 175 | def add_profile(conn, cursor, name): |
no test coverage detected