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 #19

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Empty file added linux/dumper/cache.txt
Empty file.
33 changes: 33 additions & 0 deletions linux/dumper/dump_battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import subprocess
import sys

class dump_battery:
def battery_remaining(self):
self.rem = subprocess.check_output("upower -i | grep -i 'percentage'", shell=True)

#TESTING CODE - REMOVE WHEN DONE
#self.file = open('/home/pi/dump-dev/dump/linux/dumper/battery_test.txt', 'r')

for i in self.rem:
if 'percentage' in i:
self.percentage = i.split()
else:
pass

return (int(self.percentage[1].strip('%')))


def battery_state(self):
self.state = subprocess.check_output(["upower -i | grep -i 'state'", shell=True)

#TESTING CODE - REMOVE WHEN DONE
#self.file = open('/home/pi/dump-dev/dump/linux/dumper/battery_test.txt', 'r')

for i in self.state:
if 'state' in i:
self.status = i.split()
else:
pass

return (str(self.status[1]))

123 changes: 123 additions & 0 deletions linux/dumper/dump_it.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#copy files from source to destination

class backup:

def locateSource(self, source):
self.source = source

return self.source

def locateBackup(self, backup):
self.backup = backup

return self.backup

def sourceDict(self): pass

def destinationDict(self): pass

def performChecksum(self):
#performs a checksum of each image object
#hashing algo: MD5

import hashlib

#need source location

def compareChecksum(self): pass
#returns dictionary object of backup objects

def backup(self):
#recursively add file names to dic object from the source.

#recursively add files name to dic object from the destination.

#perform checksum on source objects

#perform checksum on destination objects

#add checksum source objects to local cache database if they don't exist to create rainbow table

#create a new dict object of new objects that need to be copied


pass

class hashing:
import hashlib

def __init__(self):
from glob import glob
from multiprocessing import Process

#need to get image file path for source device
#source_dir (list)
self.source_dir = glob("location")

#spawn process
for i in self.source_dir:
p = Process(target=md5, args=(self.source_dir,))
p.start()
p.join()

def md5(self, source_dir):
#returns MD5 hash values of source directory
#return value: key = pathname + filename : value = checksum

#items = path+filename:checksum
self.checksum_library = {}

#for each file in source, get checksum
for key in self.source_dir:
with open(key, 'rb') as self.getMD5:
self.data = self.getMD5.read()
self.getHash = hashlib.md5(data).hexdigest()

if key not in self.checksum_library:
self.checksum_library[key] = {'value': self.getHash}

return self.checksum_library


class cacheTable:
#source material: https://www.blog.pythonlibrary.org/2016/02/25/python-an-intro-to-caching/

def __init__(self):
#open/read cache file, write objects to cache{}
try:
with open('cache.txt', 'r') as cacheFile:
self.cache = cacheFile.read()
except Exception as e:
print(e)

#close file
cacheFile.close()

def __contains__(self, key):
#returns true if key is in cache

return key in self.cache

def updateCache(self, key, value):

#update cache with new key:value if it doesn't exist
if key not in self.cache:
try:
self.cache[key] = {'value': value}
except Exception as e:
print (e)

return self.cache

def writeCache(self):
import json

#reconstruct json from obj str -> dict
self.js = json.loads(self.cache)

#open file and append cache data
with open('cache.txt', 'a+') as cacheFile:
self.cache = cacheFile.read()

#close file
cacheFile.close()
25 changes: 25 additions & 0 deletions linux/dumper/dump_wifi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import subprocess

class dump_wifi():
def __init__(self, state):
'''
Params: state - state of WiFi (on/off)
'''

self.state = str(state)

if self.state.lower() == 'on':
wifi_enable()
elif self.state.lower() == 'off':
wifi_disable()
else:
print('Invalid Wifi State. Valid states: on, off')

def wifi_enable(self):
#Enable Wifi Connection using rfkill. More information 'man rfkill'
subprocess.check_output(["rfkill", "unblock", "wifi"], shell=True)

def wifi_disable(self):
#Disable Wifi Connection using rfkill. More information 'man rfkill'
subprocess.check_output(["rfkill", "block", "wifi"], shell=True)

34 changes: 32 additions & 2 deletions linux/dumper/dumper_lcd.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin python3

import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
from gpiozero import Button, Led
import configparser
import subprocess
import dump_wifi
import logger
import pyudev
import time
import board
import busio
import time
import usb
import sys
import os
Expand All @@ -30,6 +32,17 @@ def init_lcd():

return lcd

def init_gpio():
'''
Params: button - initializes GPIO pin

Returns: button
'''

#Button is located at GPIO pin 26
button = Button(26)

return button

def get_configparser():
'''
Expand Down Expand Up @@ -249,7 +262,6 @@ def shutdown():
shutdown_command = ('''sudo shutdown -h now''')
os.system(shutdown_command)


def restart():
lcd.message = "Restarting in:"
time.sleep(0.5)
Expand All @@ -264,16 +276,34 @@ def restart():

os.system('''sudo reboot -f''')

def wifi_on():
enable_wifi = subprocess.call(["rfkill","unblock", "wifi"])

def wifi_off():
disable_wifi = subprocess.call(["rfkill","block", "wifi"])


if __name__ == "__main__":
#init lcid screen
lcd = init_lcd()

#init gpio button
button = init_gpio()

#get configparser
backup_device, input_device, dev_backup_loc, dev_input_loc, mnt_backup_loc, mnt_input_loc, dumper_loc = get_configparser()

#message user to plug in devices
# TODO: get message to scroll to the left without newline continuously
while True:
#enabled/disable wifi
if button.is_pressed:
#turns wifi on - switch is in toggle on state (1)
dump_wifi('on')
else:
#turns wifi off - switch is in toggle off state (0)
dump_wifi('off')

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

Expand Down
Empty file added linux/dumper/formatDrive.py
Empty file.