Conditions | 5 |
Total Lines | 63 |
Code Lines | 35 |
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 record in get_orphan_samples(): |
||
70 | (data, team, sample) = ( |
||
71 | record['data'], record['team'], record['sample']) |
||
72 | |||
73 | if count % 100 == 0 or old_team != team: |
||
74 | update_submission_status(submission) |
||
75 | |||
76 | # create a new Biosample submission |
||
77 | usi_submission, submission = create_biosample_submission( |
||
78 | root, team) |
||
79 | |||
80 | # reset count and old_team |
||
81 | count = 1 |
||
82 | old_team = team |
||
83 | |||
84 | # add sample to submission |
||
85 | try: |
||
86 | logger.info("Submitting '%s'" % data['accession']) |
||
87 | usi_submission.create_sample(data) |
||
88 | |||
89 | except USIDataError as error: |
||
90 | logger.error( |
||
91 | "Can't remove '%s': Error was '%s'" % ( |
||
92 | data['accession'], str(error))) |
||
93 | sample.status = ERROR |
||
94 | sample.save() |
||
95 | continue |
||
96 | |||
97 | # update sample status and track submission |
||
98 | sample.status = SUBMITTED |
||
99 | sample.submission = submission |
||
100 | sample.save() |
||
101 | |||
102 | # update submission count |
||
103 | submission.samples_count = count |
||
104 | submission.save() |
||
105 | |||
106 | # new element |
||
107 | count += 1 |
||
108 | |||
109 | # update the last submission status |
||
110 | update_submission_status(submission) |
||
111 | |||
112 | # end the script |
||
113 | logger.info("patch_orphan_samples ended") |
||
114 |