示例#1
0
def init(program: ArgumentParser) -> None:
    global ARGS

    if not ARGS:
        ip = None

        if not helper.has_argument('--philips-hue-ip'):
            ip = helper.get_first(discover_ips())
        if ip:
            program.add_argument('--philips-hue-ip', default=ip)
        else:
            program.add_argument('--philips-hue-ip', required=True)
        program.add_argument('--philips-hue-light', action='append')
        program.add_argument('--philips-hue-group', action='append')
    ARGS = helper.get_first(program.parse_known_args())
示例#2
0
def init(program: ArgumentParser) -> None:
    global ARGS

    if not ARGS:
        program.add_argument('--agile-innovative-blinkstick-device',
                             action='append')
    ARGS = helper.get_first(program.parse_known_args())
示例#3
0
def fetch(host: str, slug: str, token: str) -> List[ProducerModel]:
    result = []
    response = None

    if host and slug and token:
        token = ':' + token
        response = request.get(
            host + '/' + slug + '/_apis/build/builds?api-version=6.0',
            headers={
                'Accept':
                'application/json',
                'Authorization':
                'Basic ' +
                base64.b64encode(token.encode('utf-8')).decode('ascii')
            })

    # process response

    if response and response.status_code == 200:
        data = request.parse_json(response)

        if 'value' in data:
            build = helper.get_first(data['value'])

            if 'project' in build and 'name' in build[
                    'project'] and 'status' in build:
                if 'result' in build:
                    result.append(
                        normalize_data(build['project']['name'],
                                       build['status'], build['result']))
                else:
                    result.append(
                        normalize_data(build['project']['name'],
                                       build['status'], None))
    return result
示例#4
0
def fetch(host: str, slug: str, username: str,
          password: str) -> List[Dict[str, Any]]:
    result = []
    response = None

    if host and slug and username and password:
        username_password = username + ':' + password
        response = requests.get(
            host + '/rest/api/latest/result/' + slug,
            headers={
                'Accept':
                'application/json',
                'Authorization':
                'Basic ' + base64.b64encode(
                    username_password.encode('utf-8')).decode('ascii')
            })

    # process response

    if response and response.status_code == 200:
        data = helper.parse_json(response)

        if 'results' in data and 'result' in data['results']:
            result.append(
                normalize_data(helper.get_first(data['results']['result'])))
    return result
示例#5
0
def test_get_first() -> None:
	assert helper.get_first(
	[
		1,
		2,
		3
	]) == 1
示例#6
0
def init(program: ArgumentParser) -> None:
    global ARGS

    if not ARGS:
        program.add_argument('--custom-host')
        program.add_argument('--custom-slug', action='append', required=True)
    ARGS = helper.get_first(program.parse_known_args())
示例#7
0
def fetch(host : str, organization : str, slug : str, __filter__ : str, token : str) -> List[ProducerModel]:
	result = []
	response = None

	if host and slug and __filter__ == 'mine' and token:
		response = request.get(host + '/api/v2/project/' + slug + '/pipeline/mine', headers =
		{
			'Accept': 'application/json',
			'Circle-Token': token
		})
	elif host and slug and token:
		response = request.get(host + '/api/v2/project/' + slug + '/pipeline', headers =
		{
			'Accept': 'application/json',
			'Circle-Token': token
		})
	elif host and organization and token:
		response = request.get(host + '/api/v2/pipeline?org-slug=' + organization, headers =
		{
			'Accept': 'application/json',
			'Circle-Token': token
		})

	# process response

	if response and response.status_code == 200:
		data = request.parse_json(response)

		if 'items' in data:
			pipeline = helper.get_first(data['items'])

			if pipeline and 'id' in pipeline:
				result.extend(fetch_workflows(host, pipeline['id'], token))
	return result
示例#8
0
def fetch(host: str, slug: str, username: str,
          password: str) -> List[ProducerModel]:
    result = []
    response = None

    if host and slug and username and password:
        username_password = username + ':' + password
        response = request.get(
            host + '/2.0/repositories/' + slug + '/pipelines/',
            headers={
                'Accept':
                'application/json',
                'Authorization':
                'Basic ' + base64.b64encode(
                    username_password.encode('utf-8')).decode('ascii')
            })

    # process response

    if response and response.status_code == 200:
        data = request.parse_json(response)

        if 'values' in data:
            build = helper.get_first(data['values'])

            if build and 'repository' in build and 'full_name' in build[
                    'repository'] and 'state' in build and 'result' in build[
                        'state'] and 'name' in build['state']['result']:
                result.append(
                    normalize_data(build['repository']['full_name'],
                                   build['state']['result']['name']))
    return result
示例#9
0
def init(program: ArgumentParser) -> None:
    args = helper.get_first(program.parse_known_args())

    if sys.version_info < (3, 8):
        sys.exit(
            wording.get('version_no').format(sys.version_info.major,
                                             sys.version_info.minor) +
            wording.get('exclamation_mark'))

    # report header

    reporter.print_header()
    print()

    # handle background run

    if args.background_run is True:
        application = loop.get_application()
        timer = loop.get_timer()
        timer.setInterval(500)
        timer.timeout.connect(lambda: background_run(program))
        timer.singleShot(0, lambda: run(program))  # type: ignore
        timer.start()
        sys.exit(application.exec_())
    else:
        run(program)
示例#10
0
def fetch(host: str, slug: str, token: str) -> List[Dict[str, Any]]:
    result = []
    response = None

    if host and token:
        headers =\
        {
         'Accept': 'application/json',
         'Authorization': 'Bearer ' + token
        }
        if slug:
            response = requests.get(
                host +
                '/app/rest/buildTypes/?fields=buildType(builds($locator(running:any),build(running,status,buildType(projectName))))&locator=affectedProject:(id:'
                + slug + ')',
                headers=headers)
        else:
            response = requests.get(
                host +
                '/app/rest/buildTypes/?fields=buildType(builds($locator(running:any),build(running,status,buildType(projectName))))',
                headers=headers)

    # process response

    if response and response.status_code == 200:
        data = helper.parse_json(response)

        if 'buildType' in data:
            for project in data['buildType']:
                if 'build' in project['builds']:
                    build = helper.get_first(project['builds']['build'])
                    result.append(normalize_data(build))
    return result
示例#11
0
def init(program : ArgumentParser) -> None:
	global ARGS

	if not ARGS:
		program.add_argument('--wercker-host', default = 'https://app.wercker.com')
		program.add_argument('--wercker-slug', action = 'append', required = True)
		program.add_argument('--wercker-token', required = True)
	ARGS = helper.get_first(program.parse_known_args())
示例#12
0
def init(program: ArgumentParser) -> None:
    global ARGS

    if not ARGS:
        program.add_argument('--travis-host',
                             default='https://api.travis-ci.org')
        program.add_argument('--travis-slug', action='append', required=True)
    ARGS = helper.get_first(program.parse_known_args())
示例#13
0
def init(program : ArgumentParser) -> None:
	global ARGS

	if not ARGS:
		program.add_argument('--circle-host', default = 'https://circleci.com')
		program.add_argument('--circle-slug', action = 'append')
		program.add_argument('--circle-token')
	ARGS = helper.get_first(program.parse_known_args())
示例#14
0
def run(program: ArgumentParser) -> None:
    status = None

    if sys.version_info < (3, 4):
        exit(
            wording.get('version_no').format(sys.version_info.major,
                                             sys.version_info.minor) +
            wording.get('exclamation_mark'))

    # report header

    if threading.active_count() == 1:
        reporter.print_header()
        print()

    # process producer

    producer_result = producer.process(program)

    # handle exit

    if not producer_result:
        exit(wording.get('result_no') + wording.get('exclamation_mark'))

    # report producer

    producer_report = reporter.create_producer_report(producer_result)
    if producer_report:
        reporter.print_report(producer_report)
        print()

    # handle dry run

    args = helper.get_first(program.parse_known_args())
    if args.dry_run is False:

        # process consumer

        status = helper.get_producer_status(producer_result)
        consumer_result = consumer.process(program, status)

        # report consumer

        consumer_report = reporter.create_consumer_report(consumer_result)
        if consumer_report:
            reporter.print_report(consumer_report)
            print()

    # handle thread

    if args.background_run is True:
        threading.Timer(args.background_interval, run, args=[program]).start()
        if helper.is_linux():
            systray_report = reporter.create_systray_report(producer_result)
            if systray.is_active():
                systray.update(status, systray_report)
            else:
                systray.create(status, systray_report)
示例#15
0
def process(program: ArgumentParser) -> List[Dict[str, Any]]:
    args = helper.get_first(program.parse_known_args())
    result = []

    for producer_name in args.producer:
        producer = load_producer(producer_name)
        producer.init(program)
        result.extend(producer.run())
    return result
示例#16
0
def init(program : ArgumentParser) -> None:
	global ARGS

	if not ARGS:
		program.add_argument('--jenkins-host', required = True)
		program.add_argument('--jenkins-slug', action = 'append', required = True)
		program.add_argument('--jenkins-username', required = True)
		program.add_argument('--jenkins-token', required = True)
	ARGS = helper.get_first(program.parse_known_args())
示例#17
0
def process(program: ArgumentParser, status: str) -> List[Dict[str, Any]]:
    args = helper.get_first(program.parse_known_args())
    result = []

    for consumer_name in args.consumer:
        consumer = load_consumer(consumer_name)
        consumer.init(program)
        result.extend(consumer.run(status))
    return result
示例#18
0
def init(program: ArgumentParser) -> None:
    global ARGS

    if not ARGS:
        program.add_argument('--teamcity-host',
                             default='https://teamcity.jetbrains.com')
        program.add_argument('--teamcity-slug', action='append')
        program.add_argument('--teamcity-token', required=True)
    ARGS = helper.get_first(program.parse_known_args())
示例#19
0
def init(program: ArgumentParser) -> None:
    global ARGS

    if not ARGS:
        program.add_argument('--bitbucket-host',
                             default='https://api.bitbucket.org')
        program.add_argument('--bitbucket-slug', action='append')
        program.add_argument('--bitbucket-username', required=True)
        program.add_argument('--bitbucket-password', required=True)
    ARGS = helper.get_first(program.parse_known_args())
示例#20
0
def process(program : ArgumentParser, status : StatusType) -> List[ConsumerModel]:
	args = helper.get_first(program.parse_known_args())
	result = []

	for consumer_name in args.consumer:
		consumer = load_consumer(consumer_name)
		consumer.init(program)
		try:
			result.extend(consumer.run(status))
		except IOError:
			sys.exit(wording.get('consumer_crash').format(consumer_name) + wording.get('exclamation_mark'))
	return result
示例#21
0
def process(program : ArgumentParser) -> List[ProducerModel]:
	args = helper.get_first(program.parse_known_args())
	result = []

	for producer_name in args.producer:
		producer = load_producer(producer_name)
		producer.init(program)
		try:
			result.extend(producer.run())
		except IOError:
			sys.exit(wording.get('producer_crash').format(producer_name) + wording.get('exclamation_mark'))
	return result
示例#22
0
def background_run(program: ArgumentParser) -> None:
    global INTERVAL

    args = helper.get_first(program.parse_known_args())
    timer = loop.get_timer()

    # handle interval

    if INTERVAL == args.background_interval * 1000:
        run(program)
        INTERVAL = 0
    else:
        INTERVAL += timer.interval()
示例#23
0
def init(program : ArgumentParser) -> None:
	global ARGS

	if not ARGS:
		ip = None

		if not helper.has_argument('--xiaomi-yeelight-ip'):
			ip = discover_ips()
		if ip:
			program.add_argument('--xiaomi-yeelight-ip', default = ip)
		else:
			program.add_argument('--xiaomi-yeelight-ip', action = 'append', required = True)
	ARGS = helper.get_first(program.parse_known_args())
示例#24
0
def fetch(host: str, slug: str, token: str) -> List[Dict[str, Any]]:
    result = []
    response = None

    if host and slug and token:
        response = request.get(host + '/api/projects/' + slug,
                               headers={
                                   'Accept': 'application/json',
                                   'Authorization': 'Bearer ' + token
                               })
    elif host and token:
        response = request.get(host + '/api/projects',
                               headers={
                                   'Accept': 'application/json',
                                   'Authorization': 'Bearer ' + token
                               })

    # process response

    if response and response.status_code == 200:
        data = request.parse_json(response)

        if 'project' in data and 'accountName' in data[
                'project'] and 'build' in data and 'status' in data['build']:
            result.append(
                normalize_data(
                    data['project']['accountName'] + '/' +
                    data['project']['slug'], data['build']['status']))
        if 'builds' in helper.get_first(data):
            for project in data:
                build = helper.get_first(project['builds'])

                if project and 'accountName' in project and 'slug' in project and build and 'status' in build:
                    result.append(
                        normalize_data(
                            project['accountName'] + '/' + project['slug'],
                            build['status']))
    return result
示例#25
0
def discover_ips() -> List[str]:
	ips = []
	message =\
	[
		'HF-A11ASSISTHREAD'
	]
	discovery = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	discovery.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
	discovery.settimeout(2)
	discovery.sendto('\r\n'.join(message).encode(), ('255.255.255.255', 48899))

	try:
		ips.append(helper.get_first(discovery.recvfrom(65507)[1]))
	except OSError:
		print(wording.get('ip_no').format('MAGIC HUE') + wording.get('exclamation_mark'))
	return ips
示例#26
0
def discover_ips() -> List[str]:
	ips = []
	message =\
	[
		'M-SEARCH * HTTP/1.1',
		'MAN: "ssdp:discover"'
	]
	discovery = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	discovery.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
	discovery.settimeout(2)
	discovery.sendto('\r\n'.join(message).encode(), ('255.255.255.255', 38899))

	try:
		ips.append(helper.get_first(discovery.recvfrom(65507)[1]))
	except OSError:
		print(wording.get('ip_no').format('WIZ LIGHT') + wording.get('exclamation_mark'))
	return ips
示例#27
0
def discover_ips() -> List[str]:
	ips = []
	message =\
	[
		'M-SEARCH * HTTP/1.1',
		'MAN: "ssdp:discover"'
	]
	discovery = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
	discovery.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 32)
	discovery.settimeout(2)
	discovery.sendto('\r\n'.join(message).encode(), ('239.255.255.250', 1900))

	try:
		ips.append(helper.get_first(discovery.recvfrom(65507)[1]))
	except socket.timeout:
		sys.exit(wording.get('ip_no').format('PHILIPS HUE BRIDGE') + wording.get('exclamation_mark'))
	return ips
示例#28
0
def run(program: ArgumentParser) -> None:
    args = helper.get_first(program.parse_known_args())
    status = None

    # process producer

    producer_result = producer.process(program)

    # handle exit

    if not producer_result:
        sys.exit(wording.get('result_no') + wording.get('exclamation_mark'))

    # report producer

    producer_report = reporter.create_producer_report(producer_result)

    if producer_report:
        reporter.print_report(producer_report)
        print()

    # handle dry run

    if args.dry_run is False:

        # process consumer

        status = helper.get_producer_status(producer_result)
        consumer_result = consumer.process(program, status)

        # report consumer

        consumer_report = reporter.create_consumer_report(consumer_result)

        if consumer_report:
            reporter.print_report(consumer_report)
            print()

    # handle systray

    if loop.is_created() is True:
        if systray.is_created() is True:
            systray.update(status, producer_report)
        else:
            systray.create(status, producer_report)
示例#29
0
def discover_ips() -> List[str]:
	ips = []
	message =\
	[
		'M-SEARCH * HTTP/1.1',
		'HOST: 239.255.255.250:1982',
		'MAN: "ssdp:discover"',
		'ST: wifi_bulb'
	]
	discovery = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
	discovery.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 32)
	discovery.settimeout(2)
	discovery.sendto('\r\n'.join(message).encode(), ('239.255.255.250', 1982))

	try:
		ips.append(helper.get_first(discovery.recvfrom(65507)[1]))
	except socket.timeout:
		print(wording.get('ip_no').format('XIAOMI YEELIGHT') + wording.get('exclamation_mark'))
	return ips
示例#30
0
def fetch(host: str, slug: str, token: str) -> List[Dict[str, Any]]:
    result = []
    response = None

    if host and slug and token:
        response = requests.get(host + '/api/v4/projects/' + slug +
                                '/pipelines',
                                headers={'Private-Token': token})

    # process response

    if response and response.status_code == 200:
        data = helper.parse_json(response)
        pipeline = helper.get_first(data)

        if pipeline:
            pipeline_id = str(pipeline['id'])
            result.extend(fetch_jobs(host, slug, pipeline_id, token))
    return result