Exemplo n.º 1
0
    def handle(  # type: ignore
        self,
        verbosity: int,
        start_election: Optional[int],
        start_precinct: int,
        ballot_limit: Optional[int],
        **_kwargs,
    ):
        log.reset()
        log.silence("datafiles")
        log.init(verbosity=verbosity if "-v" in sys.argv[-1] else 2)

        try:
            scrape_ballots(
                starting_election_id=start_election,
                starting_precinct_id=start_precinct,
                ballot_limit=ballot_limit,
            )
        except Exception as e:
            if "HEROKU_APP_NAME" in os.environ:
                log.error("Unable to finish scraping data", exc_info=e)
                bugsnag.notify(e)
                sys.exit(1)
            else:
                raise e from None
Exemplo n.º 2
0
def configure_logging(app):
    if app.config['DEBUG']:
        level = log.DEBUG
        pattern = "%(levelname)s: %(name)s:%(lineno)d: %(message)s"
    else:
        level = log.INFO
        pattern = "%(levelname)s: %(message)s"
    log.init(level=level, format=pattern)

    def log_request(response=None):
        if current_app.debug:
            path = request.path
            if request.args:
                path += "?%s" % unquote(urlencode(request.args))
            if response:
                log.info("%s: %s - %i", request.method, path,
                         response.status_code)
            else:
                log.info("%s: %s", request.method, path)

        return response

    log.silence('werkzeug', allow_warning=True)
    app.before_request(log_request)
    app.after_request(log_request)
Exemplo n.º 3
0
def pytest_configure(config):
    """Disable verbose output when running tests."""
    log.init(debug=True)
    log.silence("selenium", "urllib3")

    terminal = config.pluginmanager.getplugin("terminal")
    terminal.TerminalReporter.showfspath = False
Exemplo n.º 4
0
    def handle(self, verbosity: int, **_kwargs):  # type: ignore
        log.reset()
        log.silence("datafiles")
        log.init(verbosity=verbosity if "-v" in sys.argv[-1] else 2)

        self.get_or_create_superuser()
        self.add_elections()
        self.fetch_districts()
Exemplo n.º 5
0
def pytest_configure(config):
    """Disable verbose output when running tests."""
    log.init(debug=True)
    log.silence('factory')

    terminal = config.pluginmanager.getplugin("terminal")
    terminal.TerminalReporter.showfspath = False

    requests_cache.install_cache(expire_after=timedelta(hours=12))
Exemplo n.º 6
0
    def handle(self, verbosity: int, **_kwargs):  # type: ignore
        log.reset()
        log.silence("datafiles")
        log.init(verbosity=verbosity if "-v" in sys.argv[-1] else 2)

        defaults.initialize_parties()
        defaults.initialize_districts()

        self.update_elections()
        self.update_jurisdictions()
        self.update_candidates()

        self.import_descriptions()
        self.export_descriptions()
Exemplo n.º 7
0
    def handle(self, verbosity: int, election: Optional[int], **_kwargs):  # type: ignore
        log.reset()
        log.silence("datafiles")
        log.init(reset=True, verbosity=verbosity if "-v" in sys.argv[-1] else 2)

        try:
            parse_ballots(election_id=election)
        except Exception as e:
            if "HEROKU_APP_NAME" in os.environ:
                log.error("Unable to finish parsing data", exc_info=e)
                bugsnag.notify(e)
                sys.exit(1)
            else:
                raise e from None
Exemplo n.º 8
0
def configure_logging(count=0):
    """Configure logging using the provided verbosity count."""
    if count == -1:
        level = settings.QUIET_LOGGING_LEVEL
        default_format = settings.DEFAULT_LOGGING_FORMAT
        verbose_format = settings.LEVELED_LOGGING_FORMAT
    elif count == 0:
        level = settings.DEFAULT_LOGGING_LEVEL
        default_format = settings.DEFAULT_LOGGING_FORMAT
        verbose_format = settings.LEVELED_LOGGING_FORMAT
    elif count == 1:
        level = settings.VERBOSE_LOGGING_LEVEL
        default_format = settings.VERBOSE_LOGGING_FORMAT
        verbose_format = settings.VERBOSE_LOGGING_FORMAT
    elif count == 2:
        level = settings.VERBOSE2_LOGGING_LEVEL
        default_format = settings.VERBOSE_LOGGING_FORMAT
        verbose_format = settings.VERBOSE_LOGGING_FORMAT
    elif count == 3:
        level = settings.VERBOSE2_LOGGING_LEVEL
        default_format = settings.VERBOSE2_LOGGING_FORMAT
        verbose_format = settings.VERBOSE2_LOGGING_FORMAT
    else:
        level = settings.VERBOSE2_LOGGING_LEVEL - 1
        default_format = settings.VERBOSE2_LOGGING_FORMAT
        verbose_format = settings.VERBOSE2_LOGGING_FORMAT

    # Set a custom formatter
    log.reset()
    log.init(level=level)
    log.silence('datafiles', allow_warning=True)
    logging.captureWarnings(True)
    formatter = WarningFormatter(
        default_format, verbose_format, datefmt=settings.LOGGING_DATEFMT
    )
    logging.root.handlers[0].setFormatter(formatter)

    # Warn about excessive verbosity
    if count > _Config.MAX_VERBOSITY:
        msg = "Maximum verbosity level is {}".format(_Config.MAX_VERBOSITY)
        log.warning(msg)
        _Config.verbosity = _Config.MAX_VERBOSITY
    else:
        _Config.verbosity = count
Exemplo n.º 9
0
def pytest_configure(config):
    """Disable verbose output when running tests."""
    log.init(debug=True)
    log.silence("elections.defaults", "parse", "pomace", allow_warning=True)
    log.silence("elections.helpers", allow_info=True)
    log.silence("asyncio", "factory", "faker", "selenium", "urllib3", "vcr")

    terminal = config.pluginmanager.getplugin("terminal")
    terminal.TerminalReporter.showfspath = False
Exemplo n.º 10
0
def configure_logging(app):
    log.init(level=app.config['LOG_LEVEL'])
    log.silence('requests', 'werkzeug', 'yorm', allow_warning=True)
    log.silence('PIL', allow_info=True)
Exemplo n.º 11
0
def pytest_configure(config):
    log.init(debug=True)
    log.silence('selenium', allow_warning=True)
Exemplo n.º 12
0
def pytest_configure(config):
    terminal = config.pluginmanager.getplugin('terminal')
    terminal.TerminalReporter.showfspath = False
    log.init()
    log.silence('gitman.shell', allow_info=True)
    log.silence('datafiles', allow_warning=True)
Exemplo n.º 13
0
def pytest_configure(config):
    log.init()
    log.silence("selenium", allow_warning=True)
Exemplo n.º 14
0
def configure_logging(app):
    log.init(level=app.config['LOG_LEVEL'])
    log.silence('requests', 'werkzeug', 'yorm', allow_warning=True)
    log.silence('PIL', allow_info=True)
Exemplo n.º 15
0
def main():
    log.init()
    log.silence("datafiles", "selenium", "urllib3")
Exemplo n.º 16
0
    @property
    def consequences(self):
        return list(DagNavigator(fact) for fact in Fact.objects.all() if self.fact.key in fact.reasons)

    @property
    def reasons(self):
        return list(DagNavigator(fact) for fact in Fact.objects.all() if fact.key in self.fact.reasons)

    def __repr__(self):
        consequences = "\n  - ".join(n.fact.description for n in self.consequences)
        reasons = "\n  - ".join(n.fact.description for n in self.reasons)
        return f"fact: {self.fact.description}\nconsequences:\n  - {consequences}\nreasons:\n  - {reasons}"


@dataclass
class Dag:
    roots: List[DagNavigator]

    def __repr__(self):
        roots = "\n  - ".join(n.fact.description for n in self.roots)
        return f"roots:\n  - {roots}"


def dag():
    return Dag(list(DagNavigator(fact) for fact in Fact.objects.all() if fact.reasons == []))


log.silence('datafiles')
print("Inspect facts:")
print("- dag()")
Exemplo n.º 17
0
    def with_infos(expect, caplog):
        log.silence('3rd-party', allow_info=True)

        other.do_3rd_party_thing()

        expect(len(caplog.records)) == 3
Exemplo n.º 18
0
    def when_off(expect, caplog):
        log.silence('3rd-party')

        other.do_3rd_party_thing()

        expect(caplog.records) == []
Exemplo n.º 19
0
            s.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE)
        except socket.error, e:
            # It is look like one but it is not a socket ...
            if e.args[0] == errno.ENOTSOCK:
                return False
        return True

    # do not detach if we are already supervised or run by init like process
    if is_socket(sys.__stdin__.fileno()) or os.getppid() == 1:
        return

    fork_exit()
    os.setsid()
    fork_exit()
    mute()
    silence()


def savepid(location):
    if not location:
        return

    ownid = os.getpid()

    flags = os.O_CREAT | os.O_EXCL | os.O_WRONLY
    mode = ((os.R_OK | os.W_OK) << 6) | (os.R_OK << 3) | os.R_OK

    try:
        fd = os.open(location, flags, mode)
    except OSError:
        err("PIDfile already exists, not updated %s" % location)
Exemplo n.º 20
0
    return response.html(content)


@app.get("/test")
@doc.exclude(True)
async def test(request):
    if not settings.DEBUG:
        return response.redirect("/")

    urls = await asyncio.to_thread(helpers.get_test_images, request)
    content = utils.html.gallery(urls, columns=False, refresh=True)
    return response.html(content)


@app.get("/favicon.ico")
@doc.exclude(True)
async def favicon(request):
    return await response.file("app/static/favicon.ico")


if __name__ == "__main__":
    log.reset()
    log.silence("datafiles", allow_warning=True)
    app.run(
        host="0.0.0.0",
        port=settings.PORT,
        workers=settings.WORKERS,
        debug=settings.DEBUG,
        access_log=False,
    )
Exemplo n.º 21
0
			s.getsockopt(socket.SOL_SOCKET, socket.SO_TYPE)
		except socket.error, e:
			# It is look like one but it is not a socket ...
			if e.args[0] == errno.ENOTSOCK:
				return False
		return True

	# do not detach if we are already supervised or run by init like process
	if is_socket(sys.__stdin__.fileno()) or os.getppid() == 1:
		return

	fork_exit()
	os.setsid()
	fork_exit()
	mute()
	silence()

def savepid (location):
	if not location:
		return

	ownid = os.getpid()

	flags = os.O_CREAT | os.O_EXCL | os.O_WRONLY
	mode = ((os.R_OK | os.W_OK) << 6) | (os.R_OK << 3) | os.R_OK

	try:
		fd = os.open(location,flags,mode)
	except OSError:
		err("PIDfile already exists, not updated %s" % location)
		return False
Exemplo n.º 22
0
    def with_warnings(expect, caplog):
        log.silence("3rd-party", allow_warning=True)

        other.do_3rd_party_thing()

        expect(len(caplog.records)) == 2