def run_cpp(): output_file_path = f'{TEMP_PATH}/run' compile_command = ['c++', FULL_PATH, '-o', output_file_path] execution_command = [output_file_path] execution_command.extend(ARGS) show_log(f'compiled: {compile_command}') show_log(f'executed: {execution_command}') result = run_command(compile_command) if result.returncode == 0: run_command(execution_command)
def evaluate_expressions(expressions: [str], fmt: SyntaxFormat) -> ([str], bool): """ Evaluates the given expressions and returns their value or a parsing error. Returns the following two values: - the output of the evaluation that is the value of the expressions or error message if the expression could not be parsed; - True if the command has returned successfully, otherwise False :param expressions the list of expressions to evaluate :param fmt the syntax format of the expressions, i.e. prefix of infix The same format is applied to each expression. :return the output of the expression evaluations and whether command ran successfully """ syntax_format_arg = '--prefix' if fmt == SyntaxFormat.PREFIX else '--infix' command = f'{KCALC_COMMAND_DIR}/kcalc' input_text = '\n'.join(expressions) + "\n" try: proc = run_command( [command, syntax_format_arg], input=input_text, capture_output=True, text=True, timeout=KCALC_COMMAND_TIMEOUT) output = proc.stdout.split('\n') del output[-1] success = proc.returncode == 0 return output, success except TimeoutExpired: return "Timeout. Expression could not be evaluated.", False
def read_cpu_temp(): """ Reads cpu temp from /sys/class/thermal/thermal_zone0/temp """ cpu_temp = run_command(['cat', '/sys/class/thermal/thermal_zone0/temp'], capture_output=True, text=True).stdout return int(cpu_temp) / 1000
def run_java(): package = FILE_PATH.split('/') if len(package) > 2: package = '/'.join(FILE_PATH.split('/')[-2:]) other_path = FILE_PATH.replace(package, "") compile_command =\ f'(cd {other_path} && javac {package}.{LANG} -d {TEMP_PATH})' execution_command = f'(cd {TEMP_PATH} && java {package})' else: compile_command = f'javac {FULL_PATH} -d {TEMP_PATH}' execution_command = f'(cd {TEMP_PATH} && java {FILE_PATH})' show_log(f'compiled: {compile_command}') show_log(f'executed: {execution_command}') result = run_command(compile_command, shell=True) if result.returncode == 0: run_command(execution_command, shell=True)
def read_cpu_freq(): """ Reads cpu freq in from /sys/devices/system/cpu/cpufreq/policy0/. Freq are in hertz max cpu freq file: /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq min cpu freq file: /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_min_freq current cpu freq file: /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq """ max_freq = run_command( ['cat', '/sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq'], capture_output=True, text=True).stdout min_freq = run_command( ['cat', '/sys/devices/system/cpu/cpufreq/policy0/cpuinfo_min_freq'], capture_output=True, text=True).stdout cur_freq = run_command( ['cat', '/sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq'], capture_output=True, text=True).stdout return int(max_freq) * 1000, int(min_freq) * 1000, int(cur_freq) * 1000
def view(self, diagram_files): displaycmd = ['eog'] displaycmd.extend(diagram_file.name for diagram_file in diagram_files) run_command(displaycmd).wait()
def view(self, diagram_files): displaycmd = ['xdg-open'] displaycmd.extend(diagram_files) run_command(displaycmd).wait()
def view(self, diagram_files): displaycmd = ['open', '-a', 'Preview'] displaycmd.extend(diagram_file.name for diagram_file in diagram_files) run_command(displaycmd).wait()
def call(command): command.insert(0, "avrdude") res = run_command(command, stdout=PIPE, stderr=STDOUT) return (res.returncode, res.stdout.decode("ascii"))
self.presence_activity = kwargs["PRESENCE_ACTIVITY"] super().__init__(command_prefix=kwargs["PREFIX_COMMAND"], activity=kwargs["PRESENCE_ACTIVITY"]) except KeyError: pass async def on_ready(self) -> None: print(ON_READY_MESSAGE, self.user, "\n") print("Ready!") if __name__ == "__main__": run_command("CLS", shell=True).communicate() success_extension_count: int = 0 instance = ProfileMDBot(**{ "PREFIX_COMMAND": PREFIX_COMMAND, "PRESENCE_ACTIVITY": ATTR_ACTIVITY, }) for eachCogs in [ cogsExt.replace(".py", "") for cogsExt in listdir(COGS_DIR_NAME) if isfile(join(COGS_DIR_NAME, cogsExt)) ]: try: instance.load_extension(COGS_DIR_NAME + "." + eachCogs) success_extension_count += 1
def find_links(self, url): command = ['scrapy', 'runspider', f'-s URL={url}', f'-s OUTPUT={RESULT_FILE_PATH}', '--nolog', WEB_CRAWLER_PATH] return run_command(command).returncode
def view(self, diagram_files): displaycmd = ['qlmanage', '-p'] displaycmd.extend(diagram_files) run_command(displaycmd).wait()
def run_python(): execution_command = ['python3', '-B', FULL_PATH] execution_command.extend(ARGS) show_log(f'executed: {execution_command}') run_command(execution_command)
def from_command(cls, args=None): args = [] if args is None else args output = subprocess.run_command(["dmidecode", *args], root=True).stdout return cls(output)