BITWISE operators =/= LOGICAL operators

* Also fixed is_writable_dir()
This commit is contained in:
2Shirt 2019-05-17 16:05:01 -06:00
parent d06f505a84
commit 385f4a1d15
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
6 changed files with 31 additions and 25 deletions

View file

@ -32,8 +32,8 @@ def archive_all_users():
user_path = os.path.join(users_root, user_name) user_path = os.path.join(users_root, user_name)
appdata_local = os.path.join(user_path, r'AppData\Local') appdata_local = os.path.join(user_path, r'AppData\Local')
appdata_roaming = os.path.join(user_path, r'AppData\Roaming') appdata_roaming = os.path.join(user_path, r'AppData\Roaming')
valid_user &= os.path.exists(appdata_local) valid_user = valid_user and os.path.exists(appdata_local)
valid_user &= os.path.exists(appdata_roaming) valid_user = valid_user and os.path.exists(appdata_roaming)
if valid_user: if valid_user:
user_envs.append({ user_envs.append({
'USERNAME': user_name, 'USERNAME': user_name,

View file

@ -355,7 +355,7 @@ class RecoveryState():
"""Checks if pass is done for all block-pairs, returns bool.""" """Checks if pass is done for all block-pairs, returns bool."""
done = True done = True
for b_pair in self.block_pairs: for b_pair in self.block_pairs:
done &= b_pair.pass_done[self.current_pass] done = done and b_pair.pass_done[self.current_pass]
return done return done
def current_pass_min(self): def current_pass_min(self):
@ -543,7 +543,8 @@ class RecoveryState():
self.total_size = 0 self.total_size = 0
for b_pair in self.block_pairs: for b_pair in self.block_pairs:
b_pair.self_check() b_pair.self_check()
self.resumed |= b_pair.resumed if b_pair.resumed:
self.resumed = True
self.total_size += b_pair.size self.total_size += b_pair.size
def set_pass_num(self): def set_pass_num(self):
@ -553,7 +554,7 @@ class RecoveryState():
# Iterate backwards through passes # Iterate backwards through passes
pass_done = True pass_done = True
for b_pair in self.block_pairs: for b_pair in self.block_pairs:
pass_done &= b_pair.pass_done[pass_num] pass_done = pass_done and b_pair.pass_done[pass_num]
if pass_done: if pass_done:
# All block-pairs reported being done # All block-pairs reported being done
# Set to next pass, unless we're on the last pass (2) # Set to next pass, unless we're on the last pass (2)
@ -849,9 +850,9 @@ def is_writable_dir(dir_obj):
"""Check if we have read-write-execute permissions, returns bool.""" """Check if we have read-write-execute permissions, returns bool."""
is_ok = True is_ok = True
path_st_mode = os.stat(dir_obj.path).st_mode path_st_mode = os.stat(dir_obj.path).st_mode
is_ok &= path_st_mode & stat.S_IRUSR is_ok = is_ok and path_st_mode & stat.S_IRUSR
is_ok &= path_st_mode & stat.S_IWUSR is_ok = is_ok and path_st_mode & stat.S_IWUSR
is_ok &= path_st_mode & stat.S_IXUSR is_ok = is_ok and path_st_mode & stat.S_IXUSR
return is_ok return is_ok

View file

@ -196,8 +196,8 @@ class DiskObj():
disk_ok = False disk_ok = False
# Disable override if necessary # Disable override if necessary
self.override_disabled |= ATTRIBUTES[attr_type][k].get( if ATTRIBUTES[attr_type][k].get('Critical', False):
'Critical', False) self.override_disabled = True
# SMART overall assessment # SMART overall assessment
## NOTE: Only fail drives if the overall value exists and reports failed ## NOTE: Only fail drives if the overall value exists and reports failed
@ -441,7 +441,7 @@ class DiskObj():
# Check partitions # Check partitions
for part in json_data.get('partitiontable', {}).get('partitions', []): for part in json_data.get('partitiontable', {}).get('partitions', []):
aligned &= part.get('start', -1) % 4096 == 0 aligned = aligned and part.get('start', -1) % 4096 == 0
# Done # Done
return aligned return aligned
@ -875,7 +875,7 @@ def menu_diags(state, args):
# If so, verify no other tests are enabled and set quick_mode # If so, verify no other tests are enabled and set quick_mode
state.quick_mode = True state.quick_mode = True
for opt in main_options[4:5] + main_options[6:]: for opt in main_options[4:5] + main_options[6:]:
state.quick_mode &= not opt['Enabled'] state.quick_mode = state.quick_mode and not opt['Enabled']
else: else:
state.quick_mode = False state.quick_mode = False
@ -1057,7 +1057,8 @@ def run_hw_tests(state):
tests_enabled = False tests_enabled = False
# Disable osTicket Integration if necessary # Disable osTicket Integration if necessary
state.ost.disabled |= '--quick' in state.args if '--quick' in state.args:
state.ost.disabled = True
# Build Panes # Build Panes
update_progress_pane(state) update_progress_pane(state)
@ -1104,7 +1105,8 @@ def run_hw_tests(state):
# Run disk safety checks (if necessary) # Run disk safety checks (if necessary)
_disk_tests_enabled = False _disk_tests_enabled = False
for k in TESTS_DISK: for k in TESTS_DISK:
_disk_tests_enabled |= state.tests[k]['Enabled'] if state.tests[k]['Enabled']:
_disk_tests_enabled = True
if _disk_tests_enabled: if _disk_tests_enabled:
for disk in state.disks: for disk in state.disks:
try: try:
@ -1176,8 +1178,8 @@ def run_hw_tests(state):
# Aborted/Unknown/etc # Aborted/Unknown/etc
all_disks_passed = False all_disks_passed = False
else: else:
all_disks_passed &= disk.checkbox all_disks_passed = all_disks_passed and disk.checkbox
disk_failures |= not disk.checkbox disk_failures = disk_failures or not disk.checkbox
# Update checkbox if necessary # Update checkbox if necessary
if disk_failures: if disk_failures:
@ -1755,7 +1757,8 @@ def show_results(state):
# CPU tests # CPU tests
_enabled = False _enabled = False
for k in TESTS_CPU: for k in TESTS_CPU:
_enabled |= state.tests[k]['Enabled'] if state.tests[k]['Enabled']:
_enabled = True
if _enabled: if _enabled:
print_success('CPU:'.format(k)) print_success('CPU:'.format(k))
show_report(state.cpu.generate_cpu_report(), log_report=True) show_report(state.cpu.generate_cpu_report(), log_report=True)
@ -1764,7 +1767,8 @@ def show_results(state):
# Disk tests # Disk tests
_enabled = False _enabled = False
for k in TESTS_DISK: for k in TESTS_DISK:
_enabled |= state.tests[k]['Enabled'] if state.tests[k]['Enabled']:
_enabled = True
if _enabled: if _enabled:
print_success('Disk{}:'.format( print_success('Disk{}:'.format(
'' if len(state.disks) == 1 else 's')) '' if len(state.disks) == 1 else 's'))

View file

@ -24,7 +24,7 @@ def check_4k_alignment(show_alert=False):
continue continue
try: try:
aligned &= int(off) % 4096 == 0 aligned = aligned and int(off) % 4096 == 0
except ValueError: except ValueError:
# Ignore, this check is low priority # Ignore, this check is low priority
pass pass

View file

@ -123,15 +123,15 @@ if __name__ == '__main__':
result = try_and_print( result = try_and_print(
message='CHKDSK ({SYSTEMDRIVE})...'.format(**global_vars['Env']), message='CHKDSK ({SYSTEMDRIVE})...'.format(**global_vars['Env']),
function=run_chkdsk, other_results=other_results) function=run_chkdsk, other_results=other_results)
system_ok &= check_result(result, other_results) system_ok = system_ok and check_result(result, other_results)
result = try_and_print(message='SFC scan...', result = try_and_print(message='SFC scan...',
function=run_sfc_scan, other_results=other_results) function=run_sfc_scan, other_results=other_results)
system_ok &= check_result(result, other_results) system_ok = system_ok and check_result(result, other_results)
if D7_MODE: if D7_MODE:
result = try_and_print(message='DISM RestoreHealth...', result = try_and_print(message='DISM RestoreHealth...',
function=run_dism, other_results=other_results, repair=True) function=run_dism, other_results=other_results, repair=True)
if global_vars['OS']['Version'] in ('8', '8.1', '10'): if global_vars['OS']['Version'] in ('8', '8.1', '10'):
system_ok &= check_result(result, other_results) system_ok = system_ok and check_result(result, other_results)
else: else:
try_and_print(message='DISM CheckHealth...', try_and_print(message='DISM CheckHealth...',
function=run_dism, other_results=other_results, repair=False) function=run_dism, other_results=other_results, repair=False)

View file

@ -177,11 +177,12 @@ def get_actions(setup_mode, answers):
_win10_only = _val.get('Win10 only', False) _win10_only = _val.get('Win10 only', False)
# Set enabled status # Set enabled status
_action['Enabled'] = _val.get(setup_mode, False) _enabled = _val.get(setup_mode, False)
if _if_answer: if _if_answer:
_action['Enabled'] &= answers[_if_answer] _enabled = _enabled and answers[_if_answer]
if _win10_only: if _win10_only:
_action['Enabled'] &= global_vars['OS']['Version'] == '10' _enabled = _enabled and global_vars['OS']['Version'] == '10'
_action['Enabled'] = _enabled
# Set other keys # Set other keys
for _sub_key in SETUP_ACTION_KEYS: for _sub_key in SETUP_ACTION_KEYS: