Skip to content
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

Development: Issue#18 (Sourcery refactored) #20

Open
wants to merge 1 commit into
base: development---signed
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions linux/dumper/dumper_lcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def init_lcd():
lcd_columns = 16
lcd_rows = 2
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)

return lcd
return character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function init_lcd refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)


def init_gpio():
'''
Expand Down Expand Up @@ -90,7 +88,7 @@ def check_usb():
connected_usb = usb.core.find(find_all=True)

#Check if no devices are connected
if connected_usb == None:
if connected_usb is None:
Comment on lines -93 to +91
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check_usb refactored with the following changes:

  • Use x is None rather than x == None (none-compare)

lcd.clear()
lcd.message = "No devices found"
raise ValueError('No Devices Found.')
Expand All @@ -104,7 +102,7 @@ def check_usb():
usb_device_vendorID = hex(device.idVendor)
usb_device_productID = hex(device.idProduct)
device_list[usb_device] = usb_device_vendorID, usb_device_productID

lcd.clear()
lcd.message = "Devices found"
time.sleep(0.5)
Expand Down Expand Up @@ -160,14 +158,12 @@ def mount_usb(dbl, dil, mbl, mil, backup_name, input_name):

check_path_backup = (mbl + 'backup')
check_path_input = (mil + 'source')

lcd.clear()
lcd.message = "Mounting Devices"
time.sleep(0.5)

if os.path.exists(check_path_backup):
pass
else:
if not os.path.exists(check_path_backup):
Comment on lines -163 to +166
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function mount_usb refactored with the following changes:

  • Swap if/else to remove empty if body (remove-pass-body)

#make dir for mount point
makedir_backup = ('mkdir ' + mbl + 'backup')
os.system(makedir_backup)
Expand All @@ -181,9 +177,7 @@ def mount_usb(dbl, dil, mbl, mil, backup_name, input_name):
lcd.message = "Backup Mounted"
time.sleep(0.5)

if os.path.exists(check_path_input):
pass
else:
if not os.path.exists(check_path_input):
#make dir for mount point
makedir_input = ('mkdir ' + mil + 'source')
os.system(makedir_input)
Expand All @@ -192,7 +186,7 @@ def mount_usb(dbl, dil, mbl, mil, backup_name, input_name):
#make mount point for input usb
input_command = ('sudo mount -t auto ' + dil + ' ' + mil + 'source')
os.system(input_command)

lcd.clear()
lcd.message = "Source Mounted"
time.sleep(0.5)
Expand Down Expand Up @@ -306,38 +300,38 @@ def wifi_off():

lcd.clear()
lcd.message = "Insert USB's\nPress Select"

device_add = True
while device_add == True:
while device_add:
#shutdown RPI
if lcd.down_button:
lcd.clear()
shutdown()

#reboot RPI
if lcd.up_button:
lcd.clear()
restart()

Comment on lines -309 to +315
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 309-340 refactored with the following changes:

  • Simplify comparison to boolean (simplify-boolean-comparison)

#perform USB check
if lcd.select_button:
#get connected usb devices
usb_device = check_usb()

#validate if backup and input devices are connected
backup_usb_device_vendor, input_usb_device_vendor, backup_usb_device_product, input_usb_device_product = verify_usb(usb_device, backup_device, input_device)

#mount USB
mount_usb(dev_backup_loc, dev_input_loc, mnt_backup_loc, mnt_input_loc, backup_device, input_device)

lcd.clear()
lcd.message = "Press RB to\nbegin backup"

if lcd.right_button:
#check if /mnt/backup and /mnt/source exist
verify_backup_loc = mnt_backup_loc + 'backup'
verify_source_loc = mnt_input_loc + 'source'

if os.path.exists(verify_backup_loc) and os.path.exists(verify_source_loc):
#rsync backup -> right_button
run_autobackup(dev_backup_loc, dev_input_loc, mnt_backup_loc, mnt_input_loc, backup_device, input_device)
Expand Down