def runCommandWithFlags(self): new_cmd = [self.name] + ADDED_FLAGS.split() + self.parameters try: cmdOutput = subprocess.run(' '.join(new_cmd), shell=True, check=True) except Exception as e: prRed(e) raise CompileException(new_cmd) from e
def executeOriginalCommand(self): try: cmd = [COMPILER_NAME] + self.parameters if verbose(): print('Executing original command:', cmd) subprocess.run(' '.join(cmd), shell=True, check=True) except subprocess.CalledProcessError as e: prRed(e)
def executePreprocessor(self): source = self.getCodeFileNameIfExists() # Copy the command parameters newParams = self.parameters.copy() outputFile = self.getOutputFileIfExists() if outputFile: self.preprocessedFile = outputFile + '.ii' for i in range(len(newParams)): p = self.parameters[i] if p == '-o' or p == '--output-file': newParams[i + 1] = self.preprocessedFile break else: self.preprocessedFile = source + '.ii' newParams.append('-o') newParams.append(self.preprocessedFile) new_cmd = [COMPILER_NAME, '-E'] + newParams try: if verbose(): prGreen(' '.join(new_cmd)) cmdOutput = subprocess.run(' '.join(new_cmd), shell=True, check=True) except Exception as e: message = 'Could not execute pre-processor' if verbose(): prRed(e) logMessage(str(e)) logMessage(message) raise RuntimeError(message) from e return True
def compileInstrumentedFile(self): source = self.getCodeFileNameIfExists() # Copy original command new_cmd = [COMPILER_NAME, '-include', FPCHECKER_RUNTIME ] + self.parameters # Replace file by instrumented file for i in range(len(new_cmd)): p = new_cmd[i] if p == source: new_cmd[i] = self.instrumentedFile break # Change output file if not self.outputFile: fileName, ext = os.path.splitext(source) newOutputFile = fileName + '.o' new_cmd = new_cmd + ['-o', newOutputFile] # Compile try: if verbose(): prGreen('Compiling: ' + ' '.join(new_cmd)) cmdOutput = subprocess.run(' '.join(new_cmd), shell=True, check=True) except Exception as e: if verbose(): prRed(e) logMessage(str(e)) message = 'Could not compile instrumented file' logMessage(message) raise CompileException(message) from e
def get_recent_like(insta_username): media_id = get_post_id(insta_username) request_url = (BASE_URL + 'media/%s/likes') % (media_id) payload = {"access_token": APP_ACCESS_TOKEN} print 'POST request url : %s\n' % (request_url) post_a_like = requests.post(request_url, payload).json() if post_a_like['meta']['code'] == 200: prGreen('Like was successful!') else: prRed('Your like was unsuccessful. Try again!')
def execTraces(fileName): fd = open(fileName, 'r') for cmd in fd: try: print(cmd) cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) print(cmdOutput.decode('utf-8')) except subprocess.CalledProcessError as e: prRed('Error:') print(e.output.decode('utf-8')) exit(-1) fd.close()
def get_comment_list(insta_username): media_id = get_post_id(insta_username) request_url = (BASE_URL + 'media/%s/comments/?access_token=%s') % (media_id, APP_ACCESS_TOKEN) print 'GET request url : %s \n' % (request_url) comment_info = requests.get(request_url).json() if comment_info['meta']['code'] == 200: if len(comment_info['data']): for x in range(0, len(comment_info['data'])): comment_id = comment_info['data'][x]['id'] comment_text = comment_info['data'][x]['text'] print comment_text prGreen('Successfully generated COMMENTS') else: prRed('No comments found')
def send_message(): friend_choice = select_a_friend() original_image = raw_input("What is the name of the image?") output_path = "C:\Users\moham\Desktop\Secret\output.jpg" #Validation for not entering message while True: text = raw_input("What do you want to say? ") words = text.split() length=sum(len(word) for word in words) if text !=("") and length <=100: Steganography.encode(original_image, output_path, text) break prRed("ERROR !!! Either empty or 100 words exceeded") new_chat = ChatMessage(text,True) friends[friend_choice].chats.append(new_chat) print "Your secret message image is ready!"
def tryCommandsSequence(commands): """ Try a command and if it fails, move to the next one """ for cmd in commands: try: print(cmd.strip()) cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) print(cmdOutput.decode('utf-8')) return except subprocess.CalledProcessError as e: prRed('Error:') print(e.output.decode('utf-8')) FAILED_COMMANDS.append(cmd) continue raise SystemExit('FPChecker: compilation commands failed!')
def getRootFile(self): # Find root file files = glob.glob(TRACES_DIR + '/trace.*') root_file = '' for f in files: #print('Checking', f) with open(f) as fd: first_line = fd.readline() if self.isMakeCommand(first_line): root_file = f break #print('Root file', root_file) if root_file == '': prRed('Error: root file not found') exit(-1) return root_file
def add_friend(): new_friend = Spy('','',0,0.0) # Validation for not entering correct Name as input while True: new_friend.name = raw_input("Please add your friend's name: ") if new_friend.name.replace(" ", "").isalpha(): break # Calling Color Red to print error message prRed("ERROR !!! Invalid Friend Name") # Validation for not entering correct Name as input while True: new_friend.salutation = raw_input("Are they Mr. or Ms.?: ") if new_friend.salutation.replace(".", "").isalpha(): break # Calling Color Red to print error message prRed("ERROR !!! Invalid Friend Name") new_friend.name = new_friend.salutation + " " + new_friend.name # Validation for not entering correct Age as input while True: new_friend.age = raw_input("Age? ") if new_friend.age.replace("", "").isdigit(): new_friend.age = int( new_friend.age) break # Calling Color Red to print error message prRed("ERROR !!! Age should be in NUMBERS") # Validation for not entering correct spy rating as input while True: new_friend.rating = raw_input("Spy rating? ") if new_friend.rating.replace(".", "").isdigit(): new_friend.rating = float(new_friend.rating) break # Calling Color Red to print error message prRed("ERROR !!! Rating should be in Numbers and Precise") if len(new_friend.name) > 0 and new_friend.age > 12 and new_friend.rating >= spy.rating: friends.append(new_friend) print 'Friend Added!' else: prRed('Sorry! Invalid entry. We can\'t add spy with the details you provided') return len(friends)
from datetime import datetime import sys from termcolor import colored, cprint #importing colors from colors.py for output/messages. from colors import prCyan, prRed, prYellow, prGreen, prLightPurple, prPurple , R , B , Black #Status Message lists STATUS_MESSAGES = ["'My name is Bond, James Bond'", "'Shaken, not stirred.'", "'Keeping the British end up, Sir'"] question = "Do you want to continue as " + spy.salutation + " " + spy.name + " (Y/N)? " existing = raw_input(question) if existing != 'Y' or existing != 'N': prRed('Wrong Input! Try Again') existing = raw_input(question) #START Function to add status in SpyChat def add_status(): updated_status_message = None if spy.current_status_message != None: print 'Your current status message is %s \n' % (spy.current_status_message) else: print 'You don\'t have any status message currently \n' default = raw_input("Do you want to select from the older status (y/n)? ") if default.upper() == "N": new_status_message = raw_input("What status message do you want to set? ")
def executeOriginalCommand(self): try: cmd = [self.name] + self.parameters subprocess.run(' '.join(cmd), shell=True, check=True) except subprocess.CalledProcessError as e: prRed(e)
self.name = 'clang++' else: self.name = 'clang' self.parameters = cmd[1:] def executeOriginalCommand(self): try: cmd = [self.name] + self.parameters subprocess.run(' '.join(cmd), shell=True, check=True) except subprocess.CalledProcessError as e: prRed(e) def getOriginalCommand(self): return ' '.join([self.name] + self.parameters[1:]) def runCommandWithFlags(self): new_cmd = [self.name] + ADDED_FLAGS.split() + self.parameters try: cmdOutput = subprocess.run(' '.join(new_cmd), shell=True, check=True) except Exception as e: prRed(e) raise CompileException(new_cmd) from e if __name__ == '__main__': cmd = Command(sys.argv) try: cmd.runCommandWithFlags() except Exception as e: # Fall back to original command prRed(e) cmd.executeOriginalCommand()
##********************************************* # Kolejne kroki w Algorytmie Diffiego Hellmanie #********************************************** # Znajdowanie krzywej (p test pierwszości, a, b oraz delta) prCyan("\nZnajdownie krzywej") KrzewaEliptyczna = generuj_krzywa_eliptyczna(250) # Znajdowanie punktu oraz wypisanie E prCyan("\nZnajdowanie punktu na krzywej") q = punkty_krzywej(KrzewaEliptyczna[0], KrzewaEliptyczna[1], KrzewaEliptyczna[2]) # ALICE n = randint(1, KrzewaEliptyczna[2]) prRed("\nALICE") print("{Wylosowana liczba n: " + f"{n}") PunktA = mnozenie_punktow(q, n, KrzewaEliptyczna) print("{Mnożenie punktu: " + f"{PunktA}") # BOB k = randint(1, KrzewaEliptyczna[2]) prRed("\nBOB") print("{Wylosowana liczba k: " + f"{k}") PunktB = mnozenie_punktow(q, k, KrzewaEliptyczna) print("{Mnożenie punktu: " + f"{PunktB}") # Wymiana wiadomości # Mnożenie oraz dodwanie punktów RAlice = mnozenie_punktow(PunktB, n, KrzewaEliptyczna) RBob = mnozenie_punktow(PunktA, k, KrzewaEliptyczna)