def _handle_returncode(self, returncode, stderr): if returncode: message = "Return code: {}".format(returncode) if stderr: message += "\nstderr: {}".format(stderr.read().decode("utf-8")) self.logger.error(message) raise CommandException(message)
def _handle_returncode(self, returncode): if returncode: message = 'Return code: {}\nstderr: {}'.format( p.returncode, p.stderr, ) self.logger.error(message) raise CommandException(message)
def run_command(command, env=None, cwd=None): kwargs = {} if env: kwargs["env"] = env if cwd: kwargs["cwd"] = cwd p = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1, shell=True, executable="/bin/bash", **kwargs) for line in iter(p.stdout.readline, ""): yield line p.stdout.close() p.wait() if p.returncode: message = f"Return code: {p.returncode}\nstderr: {p.stderr}" raise CommandException(message)
def _run_command(self, env): p = subprocess.Popen( self.options['command'], stdout=subprocess.PIPE, bufsize=1, shell=True, executable='/bin/bash', env=env, cwd=self.options.get('dir'), ) for line in iter(p.stdout.readline, ''): self._process_output(line) p.stdout.close() p.wait() if p.returncode: message = 'Return code: {}\nstderr: {}'.format( p.returncode, p.stderr, ) self.logger.error(message) raise CommandException(message)
def _run_task(self): if not process_bool_arg(self.options.get('runAllApex', True)): #create CSV file and save list of changed files git_cmd = "touch changedFiles.txt | git status --porcelain | sed s/^...// > changedFiles.txt" p = Popen((git_cmd, os.getcwd()), stdout=PIPE, stderr=PIPE, shell=True) p.wait() with open('changedFiles.txt', 'r') as fr: # filter for specific file types filteredList = [] for line in fr: # if re.match(".+\.(cls|js|cmp)$", line): --> look at adding support for lightning components if re.match(".+\.(cls)$", line): filteredList.append(line) os.remove('changedFiles.txt') if not filteredList: self.logger.warn('No valid file changes in this diff.') return with open('filteredFiles.txt', 'w') as fw: fw.write(','.join(filteredList)) self.pmd_args.extend(['-filelist', 'filteredFiles.txt']) else: self.pmd_args.extend(['-d', self.options['path']]) pmd_out = None if self.options['output'] == 'html': pmd_out = open(self.options['htmlfilename'], 'w+') process = Popen(self.pmd_args, stdout=pmd_out, stderr=PIPE) _, stderr = process.communicate() returncode = process.returncode if os.path.isfile('filteredFiles.txt'): os.remove('filteredFiles.txt') if returncode: message = 'Return code: {}\nstderr: {}'.format(returncode, stderr) self.logger.error(message) raise CommandException(message)
def run_command(command, env=None, cwd=None): kwargs = {} if env: kwargs['env'] = env if cwd: kwargs['cwd'] = cwd p = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1, shell=True, executable='/bin/bash', **kwargs) for line in iter(p.stdout.readline, ''): yield line p.stdout.close() p.wait() if p.returncode: message = 'Return code: {}\nstderr: {}'.format( p.returncode, p.stderr, ) raise CommandException(message)
def _handle_returncode(self, returncode, stderr): if returncode: message = "Return code: {}\nstderr: {}".format(returncode, stderr) self.logger.error(message) raise CommandException(message)