Total Complexity | 3 |
Total Lines | 40 |
Duplicated Lines | 30 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | """ |
||
13 | class LoadHostClient: |
||
14 | """ |
||
15 | A client for requesting the controller to load a host definition. |
||
16 | """ |
||
17 | |||
18 | # ------------------------------------------------------------------------------------------------------------------ |
||
19 | def __init__(self): |
||
20 | """ |
||
21 | View Code Duplication | Object constructor. |
|
22 | """ |
||
23 | credentials = Credentials.get() |
||
24 | |||
25 | DataLayer.config['host'] = credentials.get_host() |
||
26 | DataLayer.config['user'] = credentials.get_user() |
||
27 | DataLayer.config['password'] = credentials.get_password() |
||
28 | DataLayer.config['database'] = credentials.get_database() |
||
29 | DataLayer.config['port'] = credentials.get_port() |
||
30 | DataLayer.config['autocommit'] = False |
||
31 | |||
32 | # ------------------------------------------------------------------------------------------------------------------ |
||
33 | def main(self, filename): |
||
34 | """ |
||
35 | The main function of load_schedule. |
||
36 | |||
37 | :param str filename: The filename with the XML definition of the host. |
||
38 | """ |
||
39 | try: |
||
40 | DataLayer.connect() |
||
41 | |||
42 | reader = XmlReader() |
||
43 | host = reader.parse_host(filename) |
||
44 | host.store() |
||
45 | |||
46 | DataLayer.commit() |
||
47 | DataLayer.disconnect() |
||
48 | except Exception as exception: |
||
49 | DataLayer.rollback() |
||
50 | DataLayer.disconnect() |
||
51 | |||
52 | raise exception |
||
53 | |||
55 |