Conditions | 5 |
Total Lines | 52 |
Code Lines | 26 |
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 | #!/usr/bin/env python3 |
||
51 | def handle(self, *args, **options): |
||
52 | # call commands and fill tables. |
||
53 | logger.info("Called patch_orphan_samples") |
||
54 | |||
55 | # get a new auth object |
||
56 | auth = get_manager_auth() |
||
57 | |||
58 | # get a new root object |
||
59 | root = Root(auth) |
||
60 | |||
61 | # some variables |
||
62 | count = 1 |
||
63 | old_team = None |
||
64 | usi_submission = None |
||
65 | submission = None |
||
66 | |||
67 | # iterate among orphan sample, create a BioSample submission |
||
68 | # and then add biosample for patch |
||
69 | for orphan_sample in get_orphan_samples(): |
||
70 | data, team = orphan_sample['data'], orphan_sample['team'] |
||
71 | |||
72 | if count % 100 == 0 or old_team != team: |
||
73 | update_submission_status(submission) |
||
74 | |||
75 | # create a new Biosample submission |
||
76 | usi_submission, submission = create_biosample_submission( |
||
77 | root, team) |
||
78 | |||
79 | # reset count and old_team |
||
80 | count = 1 |
||
81 | old_team = team |
||
82 | |||
83 | # add sample to submission |
||
84 | try: |
||
85 | usi_submission.create_sample(data) |
||
86 | |||
87 | except USIDataError: |
||
88 | logger.error("Can't remove %s" % data) |
||
89 | continue |
||
90 | |||
91 | # update submission count |
||
92 | submission.samples_count = count |
||
93 | submission.save() |
||
94 | |||
95 | # new element |
||
96 | count += 1 |
||
97 | |||
98 | # update the last submission status |
||
99 | update_submission_status(submission) |
||
100 | |||
101 | # end the script |
||
102 | logger.info("patch_orphan_samples ended") |
||
103 |