def read_data_from_csv_file(): logger.info(script_filename + "Reading data from csv file to list") data = [] if path.exists(data_file_path): try: reader = pd.read_csv(data_file_path, header=None, ) reader = reader.dropna() data = reader.values.tolist() except Exception as e: logger.info(script_filename + "File is empty") logger.report(e) print(e) return data
def validate(self): try: self.validateVolume() self.validateKey() self.create() self.accept() except ValidationError as e: QMessageBox.critical(self, "Validation Failed", str(e)) except Exception as e: QMessageBox.critical(self, "FATAL ERROR", "Volume Creation FAILED!!!\n"+str(e)) logger.report()
def create(self): try: self.createKey() self.createMP() self.createVolume() QMessageBox.information(self, "Warning", "It is recomended that you keep your key and volume seperate. \nIf your volume is on your hard-drive then keep your key on a flashdrive...") QMessageBox.information(self, "Finished!", "Volume creation complete!\nYou may now store files in your volume. :D") except CreationError as e: QMessageBox.critical(self, "Volume creation could not countinue.", str(e)) except Exception as e: QMessageBox.critical(self, "Unspecified Error", str(e)) logger.report()
def createKey(self): logger.out("Creating key...") try: if not os.path.isfile(self.ui.keyFileLineEdit.text()): #logger.out("dd if=/dev/urandom of={0} bs=1024 count=1".format(self.ui.keyFileLineEdit.text())) key = subprocess.check_output("dd if=/dev/urandom of=\"{0}\" bs=1024 count=1".format(self.ui.keyFileLineEdit.text()), shell=True) if self.ui.md5CheckBox.isChecked(): md5 = subprocess.check_output("md5sum \"{0}\"".format(self.ui.keyFileLineEdit.text()), shell=True) print(md5.decode("utf-8").split(" ")[0]) with open(self.ui.keyFileLineEdit.text()+".md5", "w") as file: file.write(md5.decode("utf-8").split(" ")[0]) except Exception as e: logger.report() raise CreationError(str(e))
def createVolume(self): try: logger.out("Creating Volume") volume = self.ui.newVolLineEdit.text() keyfile = self.ui.keyFileLineEdit.text() sizeNumb = self.ui.sizeNumberSpinBox.value() if os.path.isfile(self.ui.newVolLineEdit.text()): reply = QMessageBox.question(self, "File Conflict", "Encryption will COMPLETELY overwrite this file!\nContinue?", QMessageBox.No, QMessageBox.Yes) if reply == QMessageBox.No: raise CreationError("User disallowed volume overwrite...") #print("dd if=/dev/zero of=\"{0}\" bs=1 count=0 seek={1}{2}".format(self.ui.newVolLineEdit.text(), self.ui.sizeNumberDoubleSpinBox.value(), self.parseVolumeSize())) vol = subprocess.check_output("dd if=/dev/zero of=\"{0}\" bs=1 count=0 seek={1}{2}".format(volume, sizeNumb, self.parseVolumeSize()),stderr=subprocess.STDOUT , shell=True) vol = subprocess.check_output("cryptsetup luksFormat {0} {1} --batch-mode".format(volume, keyfile),stderr=subprocess.STDOUT , shell=True) try: vol = subprocess.check_output("cryptsetup luksOpen {0} luksLocker1 --key-file {1} --batch-mode".format(volume, keyfile),stderr=subprocess.STDOUT , shell=True) except: vol = subprocess.check_output("cryptsetup luksClose luksLocker1",stderr=subprocess.STDOUT , shell=True) vol = subprocess.check_output("cryptsetup luksOpen {0} luksLocker1 --key-file {1} --batch-mode".format(volume, keyfile),stderr=subprocess.STDOUT , shell=True) vol = subprocess.check_output("mkfs.ext4 /dev/mapper/luksLocker1",stderr=subprocess.STDOUT , shell=True) vol = subprocess.check_output("mount /dev/mapper/luksLocker1 {0}".format(self.parent.conf.data[0]["mpoint"]),stderr=subprocess.STDOUT , shell=True) #print("chown -R {0} {1}".format(self.parent.args.username, self.parent.conf.data[0]["mpoint"])) vol = subprocess.check_output("chown -R {0} {1}".format(self.parent.args.username, self.parent.conf.data[0]["mpoint"]),stderr=subprocess.STDOUT , shell=True) vol = subprocess.check_output("umount {0}".format(self.parent.conf.data[0]["mpoint"]),stderr=subprocess.STDOUT , shell=True) vol = subprocess.check_output("cryptsetup luksClose luksLocker1",stderr=subprocess.STDOUT , shell=True) self.parent.ui.volumeLineEdit.setText(volume) except subprocess.CalledProcessError as e: logger.out("ERROR: "+str(e)) logger.out(e.output.decode("utf-8")) logger.report() #print("THIS: ", e.output) QMessageBox.warning(self, "Oops!", e.output.decode("utf-8")) if self.parent.conf.data[0]['debug']: QMessageBox.critical(self, "Warning", str(e)) raise CreationError(str(e.output.decode("utf-8"))) except Exception as e: logger.report() raise CreationError(str(e))
def __init__(self): try: # Try first time setup setup = Setup() self.getVersionInfo() # determine the mode and run proper function if args.subparser_name == "status": Status(args, setup) elif args.subparser_name == "manifest": Manifest(args, setup) elif args.subparser_name == "pack": Pack(args, setup) elif args.subparser_name == "unpack": Unpack(args, setup) elif args.subparser_name == "config": Config(args, setup) elif args.version: pass else: print("\nPlease pick a mode. Use --help for assistance\n") except: logger.report()
if helper.validate_article_url_read(article): count += 1 index = aljazeera_scrap.articles.index(article) aljazeera_scrap.articles[index][1] = 1 aljazeera_scrap.change_url(article[0]) time.sleep(sitescrapper.request_interval) aljazeera_scrap.retrieve_webpage() if not aljazeera_scrap.http_exception: aljazeera_scrap.write_webpage_as_html() aljazeera_scrap.read_webpage_from_html() aljazeera_scrap.convert_data_to_bs4() try: aljazeera_scrap.parse_soup_to_extract_data() except Exception as e: print(e) logger.report(e) logger.report("Url", article) if count > limit_articles: break aljazeera_scrap.write_menu_list_to_file() helper.write_data_to_file(aljazeera_scrap.articles, "output/articles.csv", "scrapped article urls") helper.write_data_to_file(aljazeera_scrap.articles_data, "output/articles_data.csv", "scrapped articles data") logger.info(script_filename + "#### Execution Ended, Scrapping Done ####") logger.info(