def copy(location): """copy file or directory at a given location; can be pasted later""" copyData = settings.getDataFile() copyFileLocation = os.path.abspath(location) copy = {"copyLocation": copyFileLocation} dataFile = open(copyData, "wb") pickle.dump(copy, dataFile) speech.speak(location + " copied successfully!") speech.speak("Tip: use 'hallie paste' to paste this file.")
def saveDirectory(alias): """save a directory to a certain alias/nickname""" if not settings.platformCompatible(): return False dataFile = open(settings.getDataFile(), "wb") currentDirectory = os.path.abspath(".") directory = {alias : currentDirectory} pickle.dump(directory, dataFile) speech.success(alias + " will now link to " + currentDirectory + ".") speech.success("Tip: use 'hallie go to " + alias + "' to change to this directory.")
def saveDirectory(alias): """save a directory to a certain alias/nickname""" if not settings.platformCompatible(): return False dataFile = open(settings.getDataFile(), "wb") currentDirectory = os.path.abspath(".") directory = {alias: currentDirectory} pickle.dump(directory, dataFile) speech.success(alias + " will now link to " + currentDirectory + ".") speech.success("Tip: use 'hallie go to " + alias + "' to change to this directory.")
def paste(location): """paste a file or directory that has been previously copied""" copyData = settings.getDataFile() if not location: location = "." try: data = pickle.load(open(copyData, "rb")) speech.speak("Pasting " + data["copyLocation"] + " to current directory.") except: speech.fail("It doesn't look like you've copied anything yet.") speech.fail("Type 'hallie copy <file>' to copy a file or folder.") return process, error = subprocess.Popen(["cp", "-r", data["copyLocation"], location], stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate() if "denied" in process: speech.fail("Unable to paste your file successfully. This is most likely due to a permission issue. You can try to run me as sudo!")
def goToDirectory(alias): """go to a saved directory""" if not settings.platformCompatible(): return False data = pickle.load(open(settings.getDataFile(), "rb")) try: data[alias] except KeyError: speech.fail("Sorry, it doesn't look like you have saved " + alias + " yet.") speech.fail("Go to the directory you'd like to save and type 'hallie save as " + alias + "\'") return try: (output, error) = subprocess.Popen(["osascript", "-e", CHANGE_DIR % (data[alias])], stdout=subprocess.PIPE).communicate() except: speech.fail("Something seems to have gone wrong. Please report this error to [email protected].") return speech.success("Successfully navigating to " + data[alias])
def paste(location): """paste a file or directory that has been previously copied""" copyData = settings.getDataFile() if not location: location = "." try: data = pickle.load(open(copyData, "rb")) speech.speak("Pasting " + data["copyLocation"] + " to current directory.") except: speech.fail("It doesn't look like you've copied anything yet.") speech.fail("Type 'hallie copy <file>' to copy a file or folder.") return process, error = subprocess.Popen( ["cp", "-r", data["copyLocation"], location], stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate() if "denied" in process: speech.fail( "Unable to paste your file successfully. This is most likely due to a permission issue. You can try to run me as sudo!" )
def goToDirectory(alias): """go to a saved directory""" if not settings.platformCompatible(): return False data = pickle.load(open(settings.getDataFile(), "rb")) try: data[alias] except KeyError: speech.fail("Sorry, it doesn't look like you have saved " + alias + " yet.") speech.fail( "Go to the directory you'd like to save and type 'hallie save as " + alias + "\'") return try: (output, error) = subprocess.Popen( ["osascript", "-e", CHANGE_DIR % (data[alias])], stdout=subprocess.PIPE).communicate() except: speech.fail( "Something seems to have gone wrong. Please report this error to [email protected]." ) return speech.success("Successfully navigating to " + data[alias])