-
Notifications
You must be signed in to change notification settings - Fork 3
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
Urbackup wva (Sourcery refactored) #579
Conversation
|
||
enable_client_database(clientid) | ||
|
||
command = "(echo [parameters] & echo backup_enabled = 1 & echo client_id = "+str(clientid)+" & echo authkey = "+str(authkey)+" & echo backup_server = urbackup://"+str(urbackup_server)+" & echo backup_port = "+str(urbackup_port)+") > C:\progra~1\pulse\etc\updatebackupclient.ini" | ||
command = ( | ||
f"(echo [parameters] & echo backup_enabled = 1 & echo client_id = {str(clientid)} & echo authkey = {str(authkey)} & echo backup_server = urbackup://{str(urbackup_server)} & echo backup_port = {str(urbackup_port)}" | ||
+ ") > C:\progra~1\pulse\etc\updatebackupclient.ini" | ||
) |
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 enable_client
refactored with the following changes:
- Use f-string instead of string concatenation [×7] (
use-fstring-for-concatenation
)
if session == "": | ||
return "No DATA in session" | ||
|
||
return session | ||
return "No DATA in session" if session == "" else session |
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 get_ses
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if "content" in logs: | ||
return logs["content"] | ||
|
||
return "No DATA in logs" | ||
return logs["content"] if "content" in logs else "No DATA in logs" |
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 get_logs
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if "content" in stats: | ||
return stats["content"] | ||
|
||
return "No DATA in stats" | ||
return stats["content"] if "content" in stats else "No DATA in stats" |
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 get_stats
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
if "content" in newgroup: | ||
return newgroup["content"] | ||
|
||
return "No DATA in newclient" | ||
return newgroup["content"] if "content" in newgroup else "No DATA in newclient" |
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 add_group
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
for i in range(NB_DB_CONN_TRY): | ||
for _ in range(NB_DB_CONN_TRY): |
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 UrbackupDatabase.getDbConnection
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
sql="""SELECT * FROM urbackup.client_state WHERE client_id = '%s';"""%(client_id) | ||
sql = f"""SELECT * FROM urbackup.client_state WHERE client_id = '{client_id}';""" | ||
|
||
resultquery = session.execute(sql) | ||
session.commit() | ||
session.flush() | ||
|
||
result = [{column: value for column, | ||
value in rowproxy.items()} | ||
for rowproxy in resultquery] | ||
|
||
|
||
result = [dict(rowproxy.items()) for rowproxy in resultquery] | ||
|
||
except Exception as e: | ||
logging.getLogger().error(str(e)) | ||
|
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 UrbackupDatabase.getClientStatus
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Replace identity comprehension with call to collection constructor (
identity-comprehension
)
sql="""UPDATE client_state SET state = '%s' WHERE client_id = '%s';"""%(state, client_id) | ||
sql = f"""UPDATE client_state SET state = '{state}' WHERE client_id = '{client_id}';""" | ||
|
||
session.execute(sql) | ||
session.commit() | ||
session.flush() | ||
|
||
return True | ||
|
||
except Exception as e: | ||
logging.getLogger().error(str(e)) | ||
|
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 UrbackupDatabase.editClientState
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
sql="""INSERT INTO client_state VALUES ('%s', '1', '%s');"""%(client_id, authkey) | ||
sql = f"""INSERT INTO client_state VALUES ('{client_id}', '1', '{authkey}');""" | ||
|
||
session.execute(sql) | ||
session.commit() | ||
session.flush() | ||
|
||
return True | ||
|
||
except Exception as e: | ||
logging.getLogger().error(str(e)) | ||
|
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 UrbackupDatabase.insertNewClient
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
sql="""SELECT id, jid, enabled FROM xmppmaster.machines WHERE jid = '%s';"""%(jid) | ||
sql = f"""SELECT id, jid, enabled FROM xmppmaster.machines WHERE jid = '{jid}';""" | ||
|
||
resultquery = session.execute(sql) | ||
session.commit() | ||
session.flush() | ||
|
||
result = [{column: value for column, | ||
value in rowproxy.items()} | ||
for rowproxy in resultquery] | ||
|
||
|
||
result = [dict(rowproxy.items()) for rowproxy in resultquery] | ||
|
||
except Exception as e: | ||
logging.getLogger().error(str(e)) | ||
|
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 UrbackupDatabase.getComputersEnableValue
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Replace identity comprehension with call to collection constructor (
identity-comprehension
)
Pull Request #548 refactored by Sourcery.
If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.
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
urbackup-wva
branch, then run:Help us improve this pull request!