mirror of
https://github.com/netinvent/npbackup.git
synced 2025-09-12 16:04:48 +08:00
Reformat files with black
This commit is contained in:
parent
13df17542c
commit
5f816db5c0
2 changed files with 18 additions and 11 deletions
|
@ -216,9 +216,13 @@ This is free software, and you are welcome to redistribute it under certain cond
|
||||||
|
|
||||||
parser.add_argument("--license", action="store_true", help="Show license")
|
parser.add_argument("--license", action="store_true", help="Show license")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--auto-upgrade", action="store_true", help="Auto upgrade NPBackup")
|
"--auto-upgrade", action="store_true", help="Auto upgrade NPBackup"
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--upgrade-conf", action="store_true", help="Add new configuration elements after upgrade")
|
"--upgrade-conf",
|
||||||
|
action="store_true",
|
||||||
|
help="Add new configuration elements after upgrade",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.version:
|
if args.version:
|
||||||
|
@ -338,7 +342,9 @@ This is free software, and you are welcome to redistribute it under certain cond
|
||||||
"auto_upgrade_server_password"
|
"auto_upgrade_server_password"
|
||||||
]
|
]
|
||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc)
|
logger.error(
|
||||||
|
"Missing auto upgrade info: %s, cannot launch auto upgrade", exc
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if args.auto_upgrade:
|
if args.auto_upgrade:
|
||||||
logger.info("Running user initiated auto upgrade")
|
logger.info("Running user initiated auto upgrade")
|
||||||
|
|
|
@ -40,7 +40,7 @@ def sha256sum_data(data):
|
||||||
def need_upgrade(upgrade_interval: int) -> bool:
|
def need_upgrade(upgrade_interval: int) -> bool:
|
||||||
"""
|
"""
|
||||||
Basic counter which allows an upgrade only every X times this is called so failed operations won't end in an endless upgrade loop
|
Basic counter which allows an upgrade only every X times this is called so failed operations won't end in an endless upgrade loop
|
||||||
|
|
||||||
We need to make to select a write counter file that is writable
|
We need to make to select a write counter file that is writable
|
||||||
So we actually test a local file and a temp file (less secure for obvious reasons)
|
So we actually test a local file and a temp file (less secure for obvious reasons)
|
||||||
We just have to make sure that once we can write to one file, we stick to it unless proven otherwise
|
We just have to make sure that once we can write to one file, we stick to it unless proven otherwise
|
||||||
|
@ -48,11 +48,11 @@ def need_upgrade(upgrade_interval: int) -> bool:
|
||||||
The for loop logic isn't straight simple, but allows file fallback
|
The for loop logic isn't straight simple, but allows file fallback
|
||||||
"""
|
"""
|
||||||
# file counter, local, home, or temp if not available
|
# file counter, local, home, or temp if not available
|
||||||
counter_file = 'npbackup.autoupgrade.log'
|
counter_file = "npbackup.autoupgrade.log"
|
||||||
|
|
||||||
def _write_count(file: str, counter: int) -> bool:
|
def _write_count(file: str, counter: int) -> bool:
|
||||||
try:
|
try:
|
||||||
with open(file, 'w') as fpw:
|
with open(file, "w") as fpw:
|
||||||
fpw.write(str(counter))
|
fpw.write(str(counter))
|
||||||
return True
|
return True
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -61,7 +61,7 @@ def need_upgrade(upgrade_interval: int) -> bool:
|
||||||
|
|
||||||
def _get_count(file: str) -> Optional[int]:
|
def _get_count(file: str) -> Optional[int]:
|
||||||
try:
|
try:
|
||||||
with open(file, 'r') as fpr:
|
with open(file, "r") as fpr:
|
||||||
count = int(fpr.read())
|
count = int(fpr.read())
|
||||||
return count
|
return count
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -71,12 +71,13 @@ def need_upgrade(upgrade_interval: int) -> bool:
|
||||||
logger.error("Bogus upgrade counter in %s", file)
|
logger.error("Bogus upgrade counter in %s", file)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
for file in [
|
||||||
|
os.path.join(CURRENT_DIR, counter_file),
|
||||||
for file in [os.path.join(CURRENT_DIR, counter_file), os.path.join(tempfile.gettempdir(), counter_file)]:
|
os.path.join(tempfile.gettempdir(), counter_file),
|
||||||
|
]:
|
||||||
if not os.path.isfile(file):
|
if not os.path.isfile(file):
|
||||||
if _write_count(file, 1):
|
if _write_count(file, 1):
|
||||||
logger.debug('Initial upgrade counter written to %s', file)
|
logger.debug("Initial upgrade counter written to %s", file)
|
||||||
else:
|
else:
|
||||||
logger.debug("Cannot write to upgrade counter file %s", file)
|
logger.debug("Cannot write to upgrade counter file %s", file)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Reference in a new issue