예제 #1
0
	def getArguments(self, init_args):

		try:

			args = {'file': ['-f', '--file'],
					'duration': ['-d', '--duration'],
					'loops': ['-l', '--loops'],
					'args': ['-a', '--args']}

			presets = ['--off', '--color', '--rainbow']

			print_args = []

			if init_args[1] in presets:
				init_args = self.presets(init_args)

			for i in range(1, len(init_args)):
				for key in args:
					if init_args[i] in args[key]:
						if (i + 1) < len(init_args):
							if key != 'args':
								setattr(self, key, init_args[i + 1])
								print_args.append(str(colorful.bold_orange(key.capitalize())) + ': ' + init_args[i + 1])
								break
							elif key == 'args':
								args_temp = []
								for x in range(i + 1, len(init_args)):
									if '-' not in init_args[x]:
										args_temp.append(init_args[x])
									else:
										break
								if len(args_temp) > 0:
									setattr(self, key, args_temp)
									print_args.append(str(colorful.bold_orange(key.capitalize())) + ': ' + str(args_temp))

			req_exit = False

			if 'file' not in self.__dict__:
				req_exit = printError('Missing file argument.')
			if 'file' in self.__dict__ and not os.path.isfile(str(self.__dict__['file'])):
				req_exit = printError('File not valid.')
			if 'duration' in self.__dict__ and not intCheck(self.__dict__['duration']):
				req_exit = printError('Invalid duration.')
			if 'loops' in self.__dict__ and not intCheck(self.__dict__['loops']):
				req_exit = printError('Invalid number of loops.')

			if req_exit == True:
				printExit('Invalid arguments.')
			else:
				printLog(colorful.bold_seaGreen('ARGUMENTS: ') + ', '.join(print_args))

		except Exception as e:
			if str(e)[-1] != '.':
				e_str = str(e) + '.'
			else:
				e_str = str(e)
			printExit('Invalid arguments: ' + e_str)
예제 #2
0
def update_json_and_bokeh(project_code, bokeh_html_path=""):
    pd.set_option('display.width', 1400)
    paths = command_get_paths()

    if not bokeh_html_path:
        bokeh_html_path = paths["current_dir"]

    warning_html = project_code + ".html"
    html_exists = op.exists(op.join(paths["warnings_dir"], warning_html))

    warning_json = op.join(paths["warnings_dir"], warning_html.split(".")[0] + ".json")

    if html_exists:
        warn_df = read_warning_html(op.join(paths["warnings_dir"], warning_html))
        warning_html_date = str(warn_df.columns[0])

        print(colorful.bold_orange("\n-read warnings in html: \n"))
        print(warn_df.head())
        warnings_merged = warn_df

        json_update = True
        json_exists = op.exists(warning_json)

        if json_exists:
            existing_warnings = read_warning_json(warning_json)
            warnings_merged = existing_warnings
            print(existing_warnings.columns)

            existing_readout_timestamps = existing_warnings.columns

            print(colorful.bold_orange("\n-existing warnings in json: \n"))
            print(existing_warnings.head())

            if warning_html_date not in existing_readout_timestamps:
                print(colorful.bold_orange("\n-new warnings found - adding it to json."))
                warnings_merged = pd.concat([warn_df, existing_warnings], axis=1, join="inner")
                print(colorful.bold_orange("-merged warnings to json: \n"))
                print(warnings_merged.head())
                write_warning_json(warnings_merged,
                                   op.join(paths["warnings_dir"], warning_html.split(".")[0] + ".json"))
            else:
                print(colorful.bold_orange("\n-html warnings already in json."))
                # warnings_merged = existing_warnings
                json_update = False

        if json_update:
            write_warning_json(warnings_merged, warning_json)

        bokeh_html = op.join(bokeh_html_path, warning_html + "warnings_graph.html")
        bokeh_df = write_bokeh_graph(warnings_merged, bokeh_html, project_code)
        return bokeh_df
예제 #3
0
	def getConfig(self):

		try:

			text = getFileJSON(self.file)
			self.config = json.loads(text)
			printLog(colorful.bold_orange('CONFIG: ') + str(self.config))
			printSuccess('Unloaded JSON config file.')

		except Exception as e:
			if str(e)[-1] != '.':
				e_str = str(e) + '.'
			else:
				e_str = str(e)
			printExit('Could not parse JSON: ' + e_str)			
예제 #4
0
def overview():
    """
    display program banner with corpus and coverage information
    """
    global LAST_COVERAGE
    global LAST_CORPUS_SIZE

    print(cf.bold_orange(''' _____                                     '''))
    print(cf.bold_orange('''|  ___|   _ ___________ _____   _____ _ __ '''))
    print(cf.bold_orange('''| |_ | | | |_  /_  / __/ _ \ \ / / _ \ '__|'''))
    print(cf.bold_orange('''|  _|| |_| |/ / / / (_| (_) \ V /  __/ |   '''))
    print(cf.bold_orange('''|_|   \__,_/___/___\___\___/ \_/ \___|_|   '''))
    print(cf.bold_orange('''                                           '''))

    print('Fuzzcover binary:', os.path.relpath(FUZZCOVER_BINARY))

    current_corpus_size = corpus_size()
    if LAST_CORPUS_SIZE:
        diff_files = current_corpus_size.files - LAST_CORPUS_SIZE.files
        diff_bytes = current_corpus_size.bytes - LAST_CORPUS_SIZE.bytes

        print(
            'Corpus: {name}, {files} files ({diff_files}), {bytes} bytes ({diff_bytes})'
            .format(name=CORPUS_DIRECTORY,
                    files=current_corpus_size.files,
                    diff_files=format_integer(diff_files),
                    bytes=current_corpus_size.bytes,
                    diff_bytes=format_integer(diff_bytes)))
    else:
        print('Corpus: {name}, {files} files, {bytes} bytes'.format(
            name=CORPUS_DIRECTORY,
            files=current_corpus_size.files,
            bytes=current_corpus_size.bytes))

    current_coverage = check_coverage(CORPUS_DIRECTORY)
    if LAST_COVERAGE:
        diff_lines = current_coverage.lines - LAST_COVERAGE.lines
        diff_branches = current_coverage.branches - LAST_COVERAGE.branches

        print(
            'Coverage: {line} lines ({diff_lines}), {branch} branches ({diff_branches})'
            .format(line=current_coverage.lines,
                    branch=current_coverage.branches,
                    diff_lines=format_integer(diff_lines),
                    diff_branches=format_integer(diff_branches)))
    else:
        print('Coverage: {line} lines, {branch} branches'.format(
            line=current_coverage.lines, branch=current_coverage.branches))
    print()

    LAST_COVERAGE = current_coverage
    LAST_CORPUS_SIZE = current_corpus_size
def purge(journal_dir, threshold_age_days=60):
    """
    deletes all files starting with 'journal' older than the threshold_age_days
    :param journal_dir:
    :param threshold_age_days:
    :return:
    """
    found = 0
    now = time.time()
    for jrn in os.scandir(journal_dir):
        file_modified = os.stat(jrn).st_mtime
        if (now - file_modified) // (24 * 3600) >= threshold_age_days:
            os.remove(jrn)
            found += 1
    if found > 0:
        print(
            colorful.bold_orange(
                f" deleted {found} journals older than: {threshold_age_days} in {journal_dir}"
            ))
예제 #6
0
command = args["<command>"]
project_code = args["<project_code>"]
full_model_path = args["<full_model_path>"]
model_path = op.dirname(full_model_path)
model_file_name = op.basename(full_model_path)
timeout = args["--timeout"]
html_path = args["--html_path"]
rvt_override_path = args["--rvt_path"]
rvt_override_version = args["--rvt_ver"]
notify = args["--notify"]
disablefilecheck = args["--nofilecheck"]

print(
    colorful.bold_blue(
        f"+process model job control started with command: {command}"))
print(colorful.bold_orange('-detected following path structure:'))
paths = get_paths_dict()

comma_concat_args = ",".join([f"{k}={v}" for k, v in args.items()])

journal_file_path = op.join(paths["journals_dir"], project_code + ".txt")
model_exists = op.exists(full_model_path)

if timeout:
    timeout = int(timeout)
else:
    timeout = 60

if not html_path:
    if command == "qc":
        html_path = paths["com_qc_dir"]
args = docopt(__doc__)
slog_path = args["<slog_path>"]

print(colorful.bold_cyan("+parsing: {}".format(op.basename(slog_path))))
print(" at path: {}".format(op.abspath(slog_path)))

if not op.exists(slog_path):
    print(colorful.bold_red("+slog not found at specified path!"))
else:
    with open(slog_path, 'r', encoding="utf-16le") as slog:
        slog_txt = slog.read()

    slog_users = get_user_sessions(slog_txt)

    print(colorful.bold_orange("-found {} users:".format(len(slog_users))))
    for user in slog_users:
        print(colorful.bold_green("-{}:".format(user)))
        for session in slog_users[user].ses_cls:
            ses_id = colorful.bold_orange(session)
            start = slog_users[user].ses_cls[session].start
            host = slog_users[user].ses_cls[session].hosts
            build = slog_users[user].ses_cls[session].build
            duration = slog_users[user].ses_cls[session].duration
            print("     session {}\n"
                  "     on {} {} / session_start {} / session_duration: {}".
                  format(ses_id, host, build, start, duration))

            for link in slog_users[user].ses_cls[session].links:
                print("          link open start {}".format(
                    link.link_open_start))
예제 #8
0
파일: gherkin.py 프로젝트: nokia/radish
def write_summary(features):
    """Write the end report after all Feature Files are ran"""
    feature_states = [f.state for f in features]
    features_line = "{} Feature{} ({})".format(
        len(feature_states),
        "s" if len(feature_states) != 1 else "",
        ", ".join("{} {}".format(v, k.name.lower())
                  for k, v in Counter(feature_states).items()),
    )

    scenarios = []
    rules_scenarios = (rule.scenarios for feature in features
                       for rule in feature.rules)
    for scenario in itertools.chain(*rules_scenarios):
        if hasattr(scenario, "examples"):
            scenarios.extend(scenario.examples)
        else:
            scenarios.append(scenario)

    scenarios_line = "{} Scenario{} ({})".format(
        len(scenarios),
        "s" if len(scenarios) != 1 else "",
        ", ".join("{} {}".format(v, k.name.lower())
                  for k, v in Counter(s.state for s in scenarios).items()),
    )

    steps = [s for s in scenarios for s in s.steps]
    steps_line = "{} Step{} ({})".format(
        len(steps),
        "s" if len(steps) != 1 else "",
        ", ".join("{} {}".format(v, k.name.lower())
                  for k, v in Counter(s.state for s in steps).items()),
    )

    print(features_line, flush=True)
    print(scenarios_line, flush=True)
    print(steps_line, flush=True)

    # remind about pending Steps
    pending_steps = [s for s in steps if s.state is State.PENDING]
    if pending_steps:
        pending_step_implementations = {s.step_impl for s in pending_steps}
        print(
            cf.orange(
                "You have {} pending Step Implementation{} affecting {} Step{}:"
                .format(
                    cf.bold_orange(len(pending_step_implementations)),
                    "s" if len(pending_step_implementations) != 1 else "",
                    cf.bold_orange(len(pending_steps)),
                    "s" if len(pending_steps) != 1 else "",
                )))
        for pending_step_implementation in pending_step_implementations:
            print(
                cf.orange("*  '{} {}' @ {}:{}".format(
                    cf.bold_orange(pending_step_implementation.keyword),
                    cf.bold_orange(pending_step_implementation.pattern),
                    cf.bold_orange(
                        pending_step_implementation.func.__code__.co_filename),
                    cf.bold_orange(pending_step_implementation.func.__code__.
                                   co_firstlineno),
                )))
        print(
            cf.orange(
                "Note: This may be the reason for potentially failed Steps!"))

    total_duration = sum((f.duration() for f in features), timedelta())
    timing_information = cf.deepSkyBlue3(
        "Run {marker} finished within {duration} seconds".format(
            marker=cf.bold_deepSkyBlue3(world.config.marker),
            duration=cf.bold_deepSkyBlue3(total_duration.total_seconds()),
        ))

    print(timing_information, flush=True)
예제 #9
0
html_path = args["--html_path"]
write_warn_ids = args["--write_warn_ids"]
rvt_override_path = args["--rvt_path"]
rvt_override_version = args["--rvt_ver"]
notify = args["--notify"]
disable_filecheck = args["--nofilecheck"]
disable_detach = args["--nodetach"]
disable_ws = args["--noworkshared"]
audit = args["--audit"]

comma_concat_args = ",".join([f"{k}={v}" for k, v in args.items()])

print(
    colorful.bold_blue(
        f"+process model job control started with command: {command}"))
print(colorful.bold_orange(f"-detected following root path path:"))
print(f" {paths['root_dir']}")

journal_file_path = op.join(paths["journals_dir"], project_code + ".txt")
model_exists = op.exists(full_model_path)

if timeout:
    timeout = int(timeout)
else:
    timeout = 60

if not html_path:
    if command == "qc":
        html_path = paths["com_qc_dir"]
    elif command == "warnings":
        html_path = paths["com_warnings_dir"]
예제 #10
0
	def doActions(self):

		try:

			for i in range(0, len(self.config)):

				inf_check = False

				if len(self.config) == 1 and 'duration' in self.__dict__:
					self.config[i]['duration'] = int(self.duration)

				if len(self.config) == 1 and 'loops' in self.__dict__:
					self.config[i]['loops'] = int(self.loops)

				if self.config[i]['action'] == 'off':
					printLog(colorful.bold_purple("Turning Pi LED's off..."))
					loop_itt = -1
					rem, loop_bool = self.loopLogic(loop_itt, self.config[i]['loops'])
					while loop_bool == True:
						proc = Process(proc_name='python{0}.{1}'.format(str(sys.version_info.major), str(sys.version_info.minor)), 
							proc_args=['--color', '--rainbow'])
						proc.killProcesses()
						led.all_off()
						if self.config[i]['duration'] != 0:
							printLog('Sleeping for ' + colorful.bold_blue(str(self.config[i]['duration'])) + ' seconds.')
							time.sleep(self.config[i]['duration'])
						if loop_itt == -1:
							loop_itt += 2
						elif self.config[i]['loops'] > -1:
							loop_itt += 1
						rem, loop_bool = self.loopLogic(loop_itt, self.config[i]['loops'])
						if inf_check == False:
							printLog(colorful.bold_orange(rem) + ' loops remaining.')
							inf_check = True

				elif self.config[i]['action'] == 'color':
					loop_itt = -1
					rem, loop_bool = self.loopLogic(loop_itt, self.config[i]['loops'])
					while loop_bool == True:
						if 'args' in self.__dict__:
							self.config[i]['args']['color'] = self.args[i]
						led.fill(color_hex(self.config[i]['args']['color']))
						led.update()
						if self.config[i]['duration'] != 0:
							printLog('Sleeping for ' + colorful.bold_blue(str(self.config[i]['duration'])) + ' seconds.')
							time.sleep(self.config[i]['duration'])
						if loop_itt == -1:
							loop_itt += 2
						elif self.config[i]['loops'] > -1:
							loop_itt += 1
						rem, loop_bool = self.loopLogic(loop_itt, self.config[i]['loops'])
						if inf_check == False:
							printLog(colorful.bold_orange(rem) + ' loops remaining.')
							inf_check = True

				elif self.config[i]['action'] == 'rainbow':
					loop_itt = -1
					anim = Rainbow(led)
					rem, loop_bool = self.loopLogic(loop_itt, self.config[i]['loops'])
					while loop_bool == True:
						anim.step()
						led.update()
						if self.config[i]['duration'] != 0:
							printLog('Sleeping for ' + colorful.bold_blue(str(self.config[i]['duration'])) + ' seconds.')
							time.sleep(self.config[i]['duration'])
						if loop_itt == -1:
							loop_itt += 2
						elif self.config[i]['loops'] > -1:
							loop_itt += 1
						rem, loop_bool = self.loopLogic(loop_itt, self.config[i]['loops'])
						if inf_check == False:
							printLog(colorful.bold_orange(rem) + ' loops remaining.')
							inf_check = True

			if self.config[-1]['action'] != 'off':
				led.all_off() 

			printSuccess('Actions completed.')

		except KeyboardInterrupt:
			led.all_off()
			print(colorful.bold(' ------------->>> ') + colorful.magenta('Interrupt entered.'))
			printExit('Actions interrupted.')

		except Exception as e:
			if str(e)[-1] != '.':
				e_str = str(e) + '.'
			else:
				e_str = str(e)
			printExit('Invalid config: ' + e_str)	
예제 #11
0
import glob
import colorful
import time
from time import gmtime, strftime
import sys

total1 = len(glob.glob('/home/pi/Brian/gallery/*'))
print colorful.bold_orange('NEW TOTAL:'), colorful.bold_orange(total1)

total2 = len(glob.glob('/home/pi/Brian/removed/*'))
print colorful.bold_red('AWW TOTAL:'), colorful.bold_red(total2)

time1 = strftime("%d-%m-%y", gmtime())
time2 = strftime("%H:%M:%S", gmtime())
print colorful.bold_yellow(time1), colorful.bold_yellow(time2)