Conversation
| temp = [] | ||
| for key in self.cmdList: | ||
| temp.append((self.cmdList[key]['order'], key)) | ||
| temp = [(self.cmdList[key]['order'], key) for key in self.cmdList] |
There was a problem hiding this comment.
Function device.sortCommands refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| d = {} | ||
| d['UDID'] = self.UDID | ||
| if self.customName: | ||
| d['name'] = self.customName | ||
| else: | ||
| d['name'] = self.name | ||
| d['ip'] = self.IP | ||
| d['owner'] = self.owner | ||
| d['location'] = self.location | ||
| d['geo'] = self.GEO | ||
| d['status'] = ['success', 'warning', 'danger'][self.status] | ||
| d = { | ||
| 'UDID': self.UDID, | ||
| 'name': self.customName or self.name, | ||
| 'ip': self.IP, | ||
| 'owner': self.owner, | ||
| 'location': self.location, | ||
| 'geo': self.GEO, | ||
| 'status': ['success', 'warning', 'danger'][self.status], | ||
| } | ||
|
|
There was a problem hiding this comment.
Function device.populate refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity) - Merge dictionary assignment with declaration (
merge-dict-assign) - Replace if statement with if expression (
assign-if-exp) - Ensure constant in comparison is on the right (
flip-comparison)
| if self.status != 1: | ||
| return | ||
|
|
There was a problem hiding this comment.
Function device.checkTimeout refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign)
|
|
||
| # NOTE: Will need to overwrite this if behind a firewall | ||
| MY_ADDR = s.getsockname()[0] + ":8080" | ||
| MY_ADDR = f"{s.getsockname()[0]}:8080" |
There was a problem hiding this comment.
Lines 53-89 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace dict() with {} (
dict-literal)
| drop_list = [] | ||
| for key in sorted(mdm_commands.iterkeys()): | ||
| drop_list.append([key, key]) | ||
| drop_list = [[key, key] for key in sorted(mdm_commands.iterkeys())] |
There was a problem hiding this comment.
Function get_commands.POST refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| problem_detect += ') Jailbreak detected for ' | ||
| problem_detect += ') Jailbreak detected for ' | ||
| problem_detect += web.ctx.ip | ||
|
|
||
| problems.insert(0, problem_detect) | ||
| out = "\nproblems = %s" % problems | ||
| fd = open('problems.py', 'w') | ||
| fd.write(out) | ||
| fd.close() | ||
| with open('problems.py', 'w') as fd: | ||
| fd.write(out) |
There was a problem hiding this comment.
Function do_problem.GET refactored with the following changes:
- Simplify conditional into switch-like form (
switch) - Use
withwhen opening file to ensure closure (ensure-file-closed)
| if 'CA.crt' in os.listdir('.'): | ||
| web.header('Content-Type', 'application/octet-stream;charset=utf-8') | ||
| web.header('Content-Disposition', 'attachment;filename="CA.crt"') | ||
| return open('CA.crt', "rb").read() | ||
| else: | ||
| if 'CA.crt' not in os.listdir('.'): | ||
| raise web.notfound() | ||
| web.header('Content-Type', 'application/octet-stream;charset=utf-8') | ||
| web.header('Content-Disposition', 'attachment;filename="CA.crt"') | ||
| return open('CA.crt', "rb").read() |
There was a problem hiding this comment.
Function mdm_ca.GET refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if 'Manifest.plist' in os.listdir('.'): | ||
| web.header('Content-Type', 'text/xml;charset=utf-8') | ||
| return open('Manifest.plist', "rb").read() | ||
| else: | ||
| if 'Manifest.plist' not in os.listdir('.'): | ||
| raise web.notfound() | ||
| web.header('Content-Type', 'text/xml;charset=utf-8') | ||
| return open('Manifest.plist', "rb").read() |
There was a problem hiding this comment.
Function app_manifest.GET refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if 'MyApp.ipa' in os.listdir('.'): | ||
| web.header('Content-Type', 'application/octet-stream;charset=utf-8') | ||
| web.header('Content-Disposition', 'attachment;filename="MyApp.ipa"') | ||
| return open('MyApp.ipa', "rb").read() | ||
| else: | ||
| if 'MyApp.ipa' not in os.listdir('.'): | ||
| return web.ok | ||
| web.header('Content-Type', 'application/octet-stream;charset=utf-8') | ||
| web.header('Content-Disposition', 'attachment;filename="MyApp.ipa"') | ||
| return open('MyApp.ipa', "rb").read() |
There was a problem hiding this comment.
Function app_ipa.GET refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| fd = open(LOGFILE, "a") | ||
| fd.write(datetime.now().ctime()) | ||
| fd.write(" %s\n" % repr(out)) | ||
| fd.close() | ||
| with open(LOGFILE, "a") as fd: | ||
| fd.write(datetime.now().ctime()) | ||
| fd.write(" %s\n" % repr(out)) |
There was a problem hiding this comment.
Function log_data refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!