-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery Starbot ⭐ refactored mfhbam/pyload #1
base: stable
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
if os.name == "nt": | ||
enc = "cp850" | ||
else: | ||
enc = "utf8" | ||
|
||
enc = "cp850" if os.name == "nt" else "utf8" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 37-41
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
elif not self.threadManager.pause: | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Core.__init__.toggle_pause
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
f = open(self.pidfile, "wb") | ||
f.write(str(pid)) | ||
f.close() | ||
with open(self.pidfile, "wb") as f: | ||
f.write(str(pid)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Core.__init__.writePidFile
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
f = open(self.pidfile, "rb") | ||
pid = f.read().strip() | ||
f.close() | ||
with open(self.pidfile, "rb") as f: | ||
pid = f.read().strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Core.__init__.checkPidFile
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
data = {} | ||
data["type"] = conn.attribute("type", "remote") | ||
data = {"type": conn.attribute("type", "remote")} | ||
data["default"] = conn.attribute("default", "False") | ||
data["id"] = conn.attribute("id", uuid().hex) | ||
if data["default"] == "True": | ||
data["default"] = True | ||
else: | ||
data["default"] = False | ||
data["default"] = data["default"] == "True" | ||
subs = self.parser.parseNode(conn, "dict") | ||
if not subs.has_key("name"): | ||
data["name"] = _("Unnamed") | ||
else: | ||
data["name"] = subs["name"].text() | ||
data["name"] = subs["name"].text() if subs.has_key("name") else _("Unnamed") | ||
if data["type"] == "remote": | ||
if not subs.has_key("server"): | ||
continue | ||
else: | ||
data["host"] = subs["server"].text() | ||
data["user"] = subs["server"].attribute("user", "admin") | ||
data["port"] = int(subs["server"].attribute("port", "7227")) | ||
data["password"] = subs["server"].attribute("password", "") | ||
data["host"] = subs["server"].text() | ||
data["user"] = subs["server"].attribute("user", "admin") | ||
data["port"] = int(subs["server"].attribute("port", "7227")) | ||
data["password"] = subs["server"].attribute("password", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function main.getConnections
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Replace if statement with if expression (
assign-if-exp
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Merge dictionary assignment with declaration (
merge-dict-assign
) - Swap if/else branches (
swap-if-else-branches
)
pdata = PackageData(data["id"], data["name"], data["folder"], data["site"], data["password"], | ||
data["queue"], data["order"], | ||
links=[self._convertPyFile(x) for x in data["links"].itervalues()]) | ||
|
||
return pdata | ||
return PackageData( | ||
data["id"], | ||
data["name"], | ||
data["folder"], | ||
data["site"], | ||
data["password"], | ||
data["queue"], | ||
data["order"], | ||
links=[self._convertPyFile(x) for x in data["links"].itervalues()], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Api.statusDownloads.getPackageData
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
|
||
if not data: | ||
raise PackageDoesNotExists(pid) | ||
|
||
pdata = PackageData(data["id"], data["name"], data["folder"], data["site"], data["password"], | ||
data["queue"], data["order"], | ||
fids=[int(x) for x in data["links"]]) | ||
|
||
return pdata | ||
return PackageData( | ||
data["id"], | ||
data["name"], | ||
data["folder"], | ||
data["site"], | ||
data["password"], | ||
data["queue"], | ||
data["order"], | ||
fids=[int(x) for x in data["links"]], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Api.statusDownloads.getPackageInfo
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
fdata = self._convertPyFile(info.values()[0]) | ||
return fdata | ||
return self._convertPyFile(info.values()[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Api.statusDownloads.getFileData
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
th = open(join(self.core.config["general"]["download_folder"], "tmp_" + filename), "wb") | ||
th.write(str(data)) | ||
th.close() | ||
|
||
with open(join(self.core.config["general"]["download_folder"], "tmp_" + filename), "wb") as th: | ||
th.write(str(data)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Api.statusDownloads.uploadContainer
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
while pack["order"] in order.keys(): #just in case | ||
while pack["order"] in order: #just in case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Api.statusDownloads.getPackageOrder
refactored with the following changes:
- Remove unnecessary call to keys() (
remove-dict-keys
)
while pyfile["order"] in order.keys(): #just in case | ||
while pyfile["order"] in order: #just in case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Api.statusDownloads.getFileOrder
refactored with the following changes:
- Remove unnecessary call to keys() (
remove-dict-keys
)
return not task is None | ||
return task is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Api.statusDownloads.isCaptchaWaiting
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
t = CaptchaTask(int(task.id), standard_b64encode(data), type, result) | ||
return t | ||
return CaptchaTask(int(task.id), standard_b64encode(data), type, result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Api.statusDownloads.getCaptchaTask
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
return True if self.checkAuth(username, password, remoteip) else False | ||
return bool(self.checkAuth(username, password, remoteip)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Api.statusDownloads.login
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
)
res = {} | ||
for user, data in self.core.db.getAllUserData().iteritems(): | ||
res[user] = UserData(user, data["email"], data["role"], data["permission"], data["template"]) | ||
|
||
return res | ||
return { | ||
user: UserData( | ||
user, | ||
data["email"], | ||
data["role"], | ||
data["permission"], | ||
data["template"], | ||
) | ||
for user, data in self.core.db.getAllUserData().iteritems() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Api.statusDownloads.getAllUserData
refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if not value == self.progress: | ||
if value != self.progress: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PyFile.__init__.notifyChange.setProgress
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
el = heappop(self.queue) | ||
return el | ||
return heappop(self.queue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function PriorityQueue.get
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for i in range(0, self.core.config.get("download", "max_downloads")): | ||
for _ in range(self.core.config.get("download", "max_downloads")): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ThreadManager.__init__
refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range
) - Replace unused for index with underscore (
for-index-underscore
)
for i in range(10): | ||
for _ in range(10): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ThreadManager.getIP
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
@@ -80,7 +80,6 @@ def compare_time(start, end): | |||
now = list(time.localtime()[3:5]) | |||
if start < now < end: return True | |||
elif start > end and (now > start or now < end): return True | |||
elif start < now > end < start: return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function compare_time
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
if m: | ||
traffic = float(m.group(1).replace(",", ".")) | ||
unit = m.group(2) | ||
else: | ||
if not m: | ||
return 0 | ||
traffic = float(m.group(1).replace(",", ".")) | ||
unit = m.group(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function parseFileSize
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if "-" in inp: | ||
l, n, h = inp.partition("-") | ||
l = int(l) | ||
h = int(h) | ||
r = range(l, h + 1) | ||
|
||
ret = [] | ||
if package: | ||
for p in self.cache: | ||
if p.pid in r: | ||
ret.append(p.pid) | ||
else: | ||
for l in self.links.links: | ||
if l.lid in r: | ||
ret.append(l.lid) | ||
|
||
return ret | ||
if "-" not in inp: | ||
return [int(x) for x in inp.split(",")] | ||
|
||
l, n, h = inp.partition("-") | ||
l = int(l) | ||
h = int(h) | ||
r = range(l, h + 1) | ||
|
||
ret = [] | ||
if package: | ||
for p in self.cache: | ||
if p.pid in r: | ||
ret.append(p.pid) | ||
else: | ||
return [int(x) for x in inp.split(",")] | ||
for l in self.links.links: | ||
if l.lid in r: | ||
ret.append(l.lid) | ||
|
||
return ret |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ManageFiles.init.onBackSpace.onEnter.renderBody.getLinks.parseInput
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
for x in range(0, randint(20, 100)): | ||
for _ in range(randint(20, 100)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function createURLs
refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range
) - Replace unused for index with underscore (
for-index-underscore
)
for i in range(n): | ||
for _ in range(n): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function startApiExerciser
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
if thrift: | ||
self.api = ThriftClient(user=user, password=pw) | ||
else: | ||
self.api = core.api | ||
|
||
|
||
self.api = ThriftClient(user=user, password=pw) if thrift else core.api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function APIExerciser.__init__
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if not ids or (pyfile.id in ids and len(ids) == 1): | ||
if not pyfile.package().setFinished: | ||
self.core.log.info(_("Package finished: %s") % pyfile.package().name) | ||
self.core.hookManager.packageFinished(pyfile.package()) | ||
pyfile.package().setFinished = True | ||
if ( | ||
not ids or (pyfile.id in ids and len(ids) == 1) | ||
) and not pyfile.package().setFinished: | ||
self.core.log.info(_("Package finished: %s") % pyfile.package().name) | ||
self.core.hookManager.packageFinished(pyfile.package()) | ||
pyfile.package().setFinished = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function FileHandler.addLinks.deleteLink.updateLink.restartFile.checkPackageFinished
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
urls = [] | ||
urls = [ | ||
(pyfile["url"], pyfile["plugin"]) | ||
for pyfile in data.itervalues() | ||
if pyfile["status"] not in (0, 12, 13) | ||
] | ||
|
||
for pyfile in data.itervalues(): | ||
if pyfile["status"] not in (0, 12, 13): | ||
urls.append((pyfile["url"], pyfile["plugin"])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function FileHandler.addLinks.deleteLink.updateLink.restartFile.checkPackageFinished.reCheckPackage
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
data = {} | ||
for r in self.c: | ||
data[r[0]] = { | ||
return {r[0]: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function FileHandler.addLinks.deleteLink.updateLink.restartFile.checkPackageFinished.FileMethods._nextFileOrder.addLink.addLinks.getAllLinks
refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
data = {} | ||
for r in self.c: | ||
data[r[0]] = { | ||
return {r[0]: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function FileHandler.addLinks.deleteLink.updateLink.restartFile.checkPackageFinished.FileMethods._nextFileOrder.addLink.addLinks.getPackageData
refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
@style.queue | ||
@style.queue | ||
def updateLinkInfo(self, data): | ||
""" data is list of tupels (name, size, status, url) """ | ||
self.c.executemany('UPDATE links SET name=?, size=?, status=? WHERE url=? AND status IN (1,2,3,14)', data) | ||
ids = [] | ||
self.c.execute('SELECT id FROM links WHERE url IN (\'%s\')' % "','".join([x[3] for x in data])) | ||
for r in self.c: | ||
ids.append(int(r[0])) | ||
return ids | ||
return [int(r[0]) for r in self.c] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function FileHandler.addLinks.deleteLink.updateLink.restartFile.checkPackageFinished.FileMethods._nextFileOrder.addLink.addLinks.updateLinkInfo
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
stable
branch, then run: