コード例 #1
0
def downloadFilesList():
    terminalColor.printGreenString("\nDownloading list of files")
    url = "https://hardware-donations-database-gamma.s3-us-west-1.amazonaws.com/Misc_Items/DownloadList"
    urllib.request.urlretrieve(
        url,
        os.path.expanduser('~') + "/HardwareDonations/Settings/DownloadList")
    terminalColor.printGreenString("Download Finished")
コード例 #2
0
def askToSaveLoginInfo():
    saveChoice = 0
    listOfChoices = [". Yes", ". No"]
    while ((saveChoice < 1) or (saveChoice > len(listOfChoices))):
        try:
            print("Do want to save your login credentials?")
            for i in range(len(listOfChoices)):
                terminalColor.printBlueString(str(i + 1) + listOfChoices[i])
            saveChoice = int(input())
            if ((saveChoice < 1) or (saveChoice > len(listOfChoices))):
                terminalColor.printRedString("Invalid Input")
            elif (listOfChoices[saveChoice - 1] == ". No"):
                break
            elif (listOfChoices[saveChoice - 1] == ". Yes"):
                fileFunctions.checkForDirectory(
                    os.path.expanduser('~') + "/HardwareDonations/Settings")
                jsonToSave = dict(key1=settingsJson.key1,
                                  key2=settingsJson.key2,
                                  key3=settingsJson.key3)
                with open(
                        os.path.expanduser('~') +
                        "/HardwareDonations/Settings/LoginInfo",
                        'w') as outfile:
                    json.dump(jsonToSave, outfile)
                terminalColor.printGreenString("Login credentials saved")
        except:
            saveChoice = 0
            terminalColor.printRedString("Invalid Input")
コード例 #3
0
def changeColor():
    intDecision = 0
    listOfOptions = [". Yes(Default)", ". No", ". Cancel"]
    while (((intDecision < 1) or (intDecision > len(listOfOptions)))):
        try:
            print(
                "\nDo you want Color Mode to be ON? If turned off it is harder to use the terminal interface."
            )
            if settingsJson.colorMode == True:
                print("Currently Color Mode is ON")
            else:
                print("Currently Color Mode is OFF")

            for i in range(len(listOfOptions)):
                terminalColor.printBlueString(str(i + 1) + listOfOptions[i])
            intDecision = int(input())
            if ((intDecision < 1) or (intDecision > len(listOfOptions))):
                terminalColor.printRedString("Invalid Input")
            elif (listOfOptions[intDecision - 1] == ". Cancel"):
                break
            elif (listOfOptions[intDecision - 1] == ". Yes(Default)"):
                settingsJson.colorMode = True
                writeJSONSettings()
            elif (listOfOptions[intDecision - 1] == ". No"):
                settingsJson.colorMode = False
                writeJSONSettings()
            else:
                intDecision = 0
        except:
            intDecision = 0
            terminalColor.printRedString("Invalid Input")
    terminalColor.printGreenString("SETTINGS UPDATED")
コード例 #4
0
def changeEditingMode():
    intDecision = 0
    listOfOptions = [". In Program", ". Externally", ". Cancel"]
    while (((intDecision < 1) or (intDecision > len(listOfOptions)))):
        try:
            print(
                "\nHow do you want strings to be edited? Note, on Windows it is neccesary to edit strings exterrnally."
            )
            if settingsJson.externalEditor:
                print(
                    "Currently strings are being edited through an external program."
                )
            else:
                print("Currently strings are being edited internally.")

            for i in range(len(listOfOptions)):
                terminalColor.printBlueString(str(i + 1) + listOfOptions[i])
            intDecision = int(input())
            if ((intDecision < 1) or (intDecision > len(listOfOptions))):
                terminalColor.printRedString("Invalid Input")
            elif (listOfOptions[intDecision - 1] == ". Cancel"):
                break
            elif (listOfOptions[intDecision - 1] == ". Externally"):
                settingsJson.externalEditor = True
                writeJSONSettings()
            elif (listOfOptions[intDecision - 1] == ". In Program"):
                settingsJson.externalEditor = False
                writeJSONSettings()
            else:
                intDecision = 0
        except:
            intDecision = 0
            terminalColor.printRedString("Invalid Input")
    terminalColor.printGreenString("SETTINGS UPDATED")
コード例 #5
0
def downloadLambdaKeys():
    terminalColor.printGreenString("Downloading access keys")
    url = "https://hardware-donations-database-gamma.s3-us-west-1.amazonaws.com/Misc_Items/LambdaAccessKeys"
    urllib.request.urlretrieve(
        url,
        os.path.expanduser('~') +
        "/HardwareDonations/Settings/LambdaAccessKeys")
    terminalColor.printGreenString("Download Finished")
コード例 #6
0
def unitEditOptions(responseJson, unitID): #unit options user is given
    intDecision = 0
    listOfOptions =[". Edit Entry", ". Upload New Photo", ". Download Unit Photos", ". Download Unit Label", ". Download Unit PDF", ". Delete Unit", ". Exit"]
    while ( (intDecision < 1 ) or (intDecision > len(listOfOptions)) ):
        try:
            printUnitInfo(responseJson, unitID)
            print("\nWhat do you want to do with this unit?")
            for i in range( len(listOfOptions) ): terminalColor.printBlueString( str(i+1) + listOfOptions[i] )
            intDecision = int(input())
            if ( (intDecision < 1) or (intDecision > len(listOfOptions)) ): terminalColor.printRedString("Invalid Input")
            elif ( listOfOptions[intDecision-1] == ". Exit"): break
            elif ( listOfOptions[intDecision-1] == ". Edit Entry"):
                intDecision = 0
                responseJson = unitEditEntry(responseJson, "Editing Existing Unit")
            elif ( listOfOptions[intDecision-1] == ". Upload New Photo"):
                intDecision = 0
                uploadNewPhoto(unitID)
            elif ( listOfOptions[intDecision-1] == ". Delete Unit"):
                if deleteUnit(unitID): terminalColor.printGreenString("Unit Deleted")
                else: intDecision = 0
            elif ( listOfOptions[intDecision-1] == ". Download Unit Photos"):
                intDecision = 0
                try:
                    unitInfo = responseJson["unitInfo"]
                    if unitInfo["Photo_URL"] == "https://hardware-donations-database-gamma.s3-us-west-1.amazonaws.com/Misc_Items/noPhotoFound.png":
                        terminalColor.printRedString("No unit photos uploaded")
                    else: downloadUnitPhoto(responseJson)
                except:
                    terminalColor.printRedString("Unable to download unit photos")
            elif ( listOfOptions[intDecision-1] == ". Download Unit Label"):
                intDecision = 0
                try:
                    downloadUnitLabel(unitID)
                except:
                    try:
                        createNewUnitLabel(unitID)
                        downloadUnitLabel(unitID)
                    except:
                        terminalColor.printRedString("Unable to download unit label")
            elif ( listOfOptions[intDecision-1] == ". Download Unit PDF"):
                intDecision = 0
                try:
                    downloadUnitPDF(unitID)
                except:
                    try:
                        createNewUnitPDF(unitID, responseJson)
                        downloadUnitPDF(unitID)
                    except:
                        terminalColor.printRedString("Unable to download unit PDF")
        except:
            intDecision = 0
            terminalColor.printRedString("Invalid Input")
コード例 #7
0
def createUnit():
    print("\nPlease enter the following information")
    searchResults = searchUnits()
    if searchResults["unitExists"]:
        terminalColor.printRedString("This unit already exists")
        return
    elif searchResults["reason"] == "Invalid Access Level":
        terminalColor.printRedString("Invalid Access Level")
        return
    unitID = searchResults["unitID"]
    terminalColor.printGreenString("No unit located with this id")
    jsonTemplate = {}
    listOfCategories = [
        "Location", "Status", "UserID", "Manufacturer", "Model",
        "ARK-OS_Version", "Operating System", "CPU Type", "CPU GHz",
        "CPU Threads", "CPU Architecture", "RAM", "RAM Slots", "RAM Type",
        "HDD", "HDD Port", "HDD Speed", "USB Ports", "Audio Ports",
        "Display Ports", "Disk Drive", "Networking", "Ports", "Comments"
    ]
    for i in listOfCategories:
        jsonTemplate[i] = "NO DATA"
    newUnitJSON = unitEdit.unitEditEntry(dict(unitInfo=jsonTemplate),
                                         "Creating New Unit")
    if newUnitJSON["Unit_ID"] == "OkToUpload":
        newUnitJSON["Unit_ID"] = unitID
        unitType = unitID.split("-", 1)[0]
        if unitType == "HDD":
            newUnitJSON["Category"] = "HDD(Hardware Donations Desktop)"
        elif unitType == "HDL":
            newUnitJSON["Category"] = "HDL(Hardware Donations Laptop)"
        elif unitType == "NX":
            newUnitJSON["Category"] = "NX(Experimental)"
        payload = dict(key1=settingsJson.key1,
                       key2=settingsJson.key2,
                       key3=settingsJson.key3,
                       type="unit_create",
                       unitID=unitID,
                       unitInfo=newUnitJSON)
        response = settings.initiateLambdaClient().invoke(
            FunctionName=
            'arn:aws:lambda:us-west-1:105369739187:function:HDPasswordCheck',
            InvocationType='RequestResponse',
            Payload=json.dumps(payload),
        )
        passTest = json.loads(response['Payload'].read())
        if passTest["result"]:
            terminalColor.printGreenString("Unit Successfully created")
        else:
            terminalColor.printRedString("Unit creation failed")
    else:
        terminalColor.printRedString("Unit creation canceled")
コード例 #8
0
ファイル: BSI_Manager.py プロジェクト: JLO64/BSI-Manager
def installSelectedBSIs(listOfSelectedBSI):
	#This is a placeholder for future internet features
	terminalColor.printRedString("\nunable to connect to BSI-Servers")

	writeInstalledBSIs(listOfSelectedBSI)

	#runs all BSIs in the list listOfSelectedBSI
	if not settingsJson.dummyBSIInstall:
		for i in listOfSelectedBSI:
			terminalColor.printGreenString("\nInitializing " + i +" BSI")
			exec(str(i + "BSI()" ))
	
	#Reminds user to apply all changes
	terminalColor.printRedString("\nPlease restart the computer to apply all changes made")
	os.system('sleep 5s')
コード例 #9
0
def checkCredentials(credentials):  #Connect to AWS Lambda to check login
    response = settings.initiateLambdaClient().invoke(
        FunctionName=
        'arn:aws:lambda:us-west-1:105369739187:function:HDPasswordCheck',
        InvocationType='RequestResponse',
        Payload=json.dumps(credentials),
    )
    passTest = json.loads(response['Payload'].read())
    if (passTest.get('result')):
        terminalColor.printGreenString("Login Successful")
        settingsJson.key1 = passTest.get('key1')
        settingsJson.key2 = passTest.get('key2')
        settingsJson.key3 = passTest.get('key3')
        return True
    else:
        return False
コード例 #10
0
def logoutOfAccount():
    intlogoutDecision = 0
    listOfLogoutOptions = [". Yes", ". No"]
    while intlogoutDecision == 0:
        print("Do you want to logout of your account?")
        for i in range(len(listOfLogoutOptions)):
            terminalColor.printBlueString(str(i + 1) + listOfLogoutOptions[i])
        intlogoutDecision = int(input())
        if ((intlogoutDecision < 1)
                or (intlogoutDecision > len(listOfLogoutOptions))):
            terminalColor.printRedString("Invalid Input")
        elif (listOfLogoutOptions[intlogoutDecision -
                                  1] == ". No"):  #Exit program
            pass
        elif (listOfLogoutOptions[intlogoutDecision - 1] == ". Yes"):
            settingsJson.key1 = "na"
            settingsJson.key2 = "na"
            settingsJson.key3 = "na"
            loginFileLoc = os.path.expanduser(
                '~') + "/HardwareDonations/Settings/LoginInfo"
            if fileFunctions.checkForFile(loginFileLoc):
                fileFunctions.deleteFile(loginFileLoc)
            terminalColor.printGreenString("SETTINGS UPDATED")
コード例 #11
0
def chooseFolderToSaveFile(downloadInfo):
    if (downloadInfo[1] == "none"):
        return
    else:
        fileLoc = ""
        if (settingsJson.guiMode == True):
            root = Tk()
            root.withdraw()
            options = {
            }  #https://www.programcreek.com/python/example/9924/tkFileDialog.asksaveasfilename

            if (downloadInfo[2] == ".txt"):
                options['filetypes'] = [('text files', '.txt')]
            elif (downloadInfo[2] == ".pdf"):
                options['filetypes'] = [('pdf files', '.pdf')]
            elif (downloadInfo[2] == ".zip"):
                options['filetypes'] = [('zip files', '.zip')]
            elif (downloadInfo[2] == ".png"):
                options['filetypes'] = [('png files', '.png')]
            elif (downloadInfo[2] == "unknown"):
                if ".png" in downloadInfo[0].lower():
                    options['filetypes'] = [('png files', '.png')]
                    downloadInfo[2] = ".png"
                elif ".jpg" in downloadInfo[0].lower():
                    options['filetypes'] = [('jpg files', '.jpg')]
                    downloadInfo[2] = ".jpg"
                elif ".jpeg" in downloadInfo[0].lower():
                    options['filetypes'] = [('jpeg files', '.jpeg')]
                    downloadInfo[2] = ".jpeg"

            if (downloadInfo[3] == "PDFs"):
                options['initialdir'] = checkForDirectory(
                    os.path.expanduser('~') + "/HardwareDonations/PDF_Files")
            elif (downloadInfo[3] == "Legal"):
                options['initialdir'] = checkForDirectory(
                    os.path.expanduser('~') + "/HardwareDonations/Legal_Files")
            elif (downloadInfo[3] == "Photos"):
                options['initialdir'] = checkForDirectory(
                    os.path.expanduser('~') + "/HardwareDonations/Photos")
            elif (downloadInfo[3] == "Wallpapers"):
                options['initialdir'] = checkForDirectory(
                    os.path.expanduser('~') + "/HardwareDonations/Wallpapers")
            elif (downloadInfo[3] == "Labels"):
                options['initialdir'] = checkForDirectory(
                    os.path.expanduser('~') + "/HardwareDonations/Labels")
            elif (downloadInfo[3] == "Unit Photos"):
                options['initialdir'] = checkForDirectory(
                    os.path.expanduser('~') + "/HardwareDonations/Unit_Photos")

            options['title'] = "Download As"
            options['initialfile'] = downloadInfo[1] + downloadInfo[2]

            fileLoc = filedialog.asksaveasfilename(**options)
        elif (settingsJson.guiMode == False):
            validDirPath = False
            while validDirPath == False:
                print(
                    "Please type the path of the directory you want to save to.(Or type \"Cancel\")"
                )
                fileLoc = str(input())
                if fileLoc.lower() == "cancel":
                    break
                elif not ("/" == fileLoc[-1] and os.path.exists(fileLoc)):
                    terminalColor.printRedString("Invalid directory")
                else:
                    validDirPath = True
        if (len(fileLoc) > 0) and not (fileLoc.lower() == "cancel"):
            fileLoc = fileLoc

            def _progress(count, block_size, total_size):
                if (float(count * block_size) / float(total_size) < 1.0):
                    sys.stdout.write('\rDownloading %.2f%%' %
                                     (float(count * block_size) /
                                      float(total_size) * 100.0))
                    sys.stdout.flush()

            urllib.request.urlretrieve(downloadInfo[0],
                                       fileLoc,
                                       reporthook=_progress)
            terminalColor.printGreenString("\nDOWNLOAD FINISHED")
            print("File Saved To: " + fileLoc)
        else:
            terminalColor.printRedString("DOWNLOAD CANCELED")
コード例 #12
0
sys.path.append("Python_Functions")
import terminalColor, downloadFiles, fileFunctions, settings, settingsJson, browseDatabase

#os.system("./ARK-OS_Installer")
#print(glob.glob("ARK-OS/*")) #list files


def printARKDino():
    arkDino = "\n     ╓╫╫╫╫╫╫╫╫╓\n     ╫╫╫╫╫╫╫╫╫╫\n     ╙╫╫╫╫╫╫╫╫╫\n          ╫╫╫╫╫\n          ╫╫╫╫╫╥\n          ╫╫╫╫╫╫╦╕\n        ╙╙╫╫╫╫╫╫╫╫╫╦        ╦\n           ║╫╫╫╫╫╫╫╫╫╦╥  ╓╥╫╫\n             ╩╫╫╫╫╫╫╫╫╫╫╫╫╫╫\n              └╫╫╫╫╫╫╫╫╫╫╫╩└\n                ╞╫╫╙╫╫╫╙\n               ╥║╡  ╥║╫\n"
    print(arkDino + "\nHardware Donations Desktop App v" +
          str(settingsJson.versionNum) + "\n\n")


if __name__ == "__main__":
    terminalColor.printGreenString("STARTING PROGRAM...")
    fileFunctions.checkForDirectory(
        os.path.expanduser('~') + "/HardwareDonations")
    fileFunctions.checkForDirectory(
        os.path.expanduser('~') + "/HardwareDonations/Settings")
    settings.initializeSettings()
    terminalColor.printGreenString("SETTINGS LOADED!")
    printARKDino()

    intDecision = 0
    listOfOptions = [
        ". Install ARK-OS", ". Access Database", ". Download Files",
        ". Go To Youtube Channel", ". Settings", ". Exit"
    ]
    while (((intDecision < 1) or (intDecision > len(listOfOptions)))):
        try: