def __init__(self, dbDir, masterPassword): self.dbDir = dbDir dbPath = os.path.join(dbDir, DBFILE) if not os.path.isdir(dbDir): raise Exception("Data folder not found: " + dbDir) self.pull() self.fs = FileStorage(dbPath, masterPassword)
def monitorFilter(self): while True: # get current messages messages = self.web3.geth.shh.get_filter_messages(self.filter_id) print('polling...') # go through all messages active right now for message in messages: content = message['payload'] contentS = bytes.fromhex(content.hex()[2:]).decode('utf-8') Header, fileHash, prof = contentS.split('\r\n') print(Header, fileHash, prof, '\n\n\n') # If help is needed and device has enough resources - sendHelp if Header == 'HELP': if not self.busy(): self.sendHelp(fileHash) fs = FileStorage() # fs.retrieve_from_hash(fileHash) # If our help request has been pushed by someone then release job elif Header == 'FIN': if self.newFileHash == fileHash: self.newFileHash = '' self.helpAsked = False time.sleep(1)
class VersionedStorage: def __init__(self, dbDir, masterPassword): self.dbDir = dbDir dbPath = os.path.join(dbDir, DBFILE) if not os.path.isdir(dbDir): raise Exception("Data folder not found: " + dbDir) self.pull() self.fs = FileStorage(dbPath, masterPassword) def getNames(self): return self.fs.getNames() def setPassword(self, name, password): self.fs.setPassword(name, password) self.commit("Added or updated entry %s"%name) def getPassword(self, idx): return self.fs.getPassword(idx) def verifyMasterPassword(self): self.fs.verifyMasterPassword() def delete(self, idx): name = self.fs.delete(idx) self.commit("Deleted entry %s"%name) def pull(self): call([ "git", "fetch", "-q", "origin", "master" ], cwd=self.dbDir) call([ "git", "merge", "-q", "--strategy=recursive", "--strategy-option=ours", "origin/master" ], cwd=self.dbDir) def push(self): self.commit("Pushing offline changes.") def commit(self, what): check_call([ "git", "add", DBFILE ], cwd=self.dbDir) check_call([ "git", "commit", "-m", what ], cwd=self.dbDir) call([ "git", "push", "-q", "origin", "master" ], cwd=self.dbDir)
from fileStorage import FileStorage fileStorage = FileStorage() while True: print('\n') fileName = input("Uploading File's Name: ") info = fileStorage.upload(fileName) print(info)
from fileStorage import FileStorage fileStorage = FileStorage() while True: print('') fileName = input("Retrieving File's Name: ") info = fileStorage.retrieve_from_name(fileName) print(str(info, 'utf-8'))
from fileStorage import FileStorage from datetime import datetime import os import time import xlsxwriter fileStorage = FileStorage() testingFiles = '../testingFiles/' fileNames = sorted(os.listdir(testingFiles)) workbook = xlsxwriter.Workbook('./data/upload.xlsx') worksheet = workbook.add_worksheet() worksheet.write('A1', 'fileName') worksheet.write('B1', 'Size') worksheet.write('C1', 'time') worksheet.write('D1', 'start') worksheet.set_column('A:C', 25) row = 2 for file in fileNames: filePath = testingFiles + file start = datetime.now() info = fileStorage.upload(filePath) diff = datetime.now() - start diffTime = diff.seconds + diff.microseconds / 1000000 print(diffTime) worksheet.write(row, 0, file) worksheet.write(row, 1, info['Size']) worksheet.write(row, 2, diffTime)