Skip to content

Commit

Permalink
Vendor nylas-production-python (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
squeaky-pl authored Oct 4, 2021
1 parent 83f2119 commit 64e70ec
Show file tree
Hide file tree
Showing 98 changed files with 668 additions and 162 deletions.
2 changes: 1 addition & 1 deletion bin/backfix-duplicate-categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from itertools import chain

import click
from nylas.logging import configure_logging, get_logger
from sqlalchemy import func
from sqlalchemy.sql import and_, exists

from inbox.error_handling import maybe_enable_rollbar
from inbox.ignition import engine_manager
from inbox.logging import configure_logging, get_logger
from inbox.models import Category, MessageCategory
from inbox.models.session import session_scope_by_shard_id

Expand Down
2 changes: 1 addition & 1 deletion bin/backfix-generic-imap-separators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# We previously didn't store IMAP path separators for generic imap accounts.
# This script backfixes the accounts.
import click
from nylas.logging import configure_logging, get_logger

from inbox.crispin import connection_pool
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger
from inbox.models.backends.generic import GenericAccount
from inbox.models.session import (
global_session_scope,
Expand Down
2 changes: 1 addition & 1 deletion bin/balance-fleet
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import time

import click
from munkres import Munkres, make_cost_matrix
from nylas.logging import configure_logging, get_logger

from inbox.config import config
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger
from inbox.models.account import Account
from inbox.models.session import global_session_scope, session_scope
from inbox.scheduling.deferred_migration import (
Expand Down
2 changes: 1 addition & 1 deletion bin/check-attachments
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ from collections import defaultdict
import click
import gevent
from gevent.pool import Pool
from nylas.logging import configure_logging, get_logger
from sqlalchemy import true
from sqlalchemy.sql.expression import func

from inbox.crispin import connection_pool
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger
from inbox.models import Account, Block
from inbox.models.backends.generic import GenericAccount
from inbox.models.session import (
Expand Down
2 changes: 1 addition & 1 deletion bin/clear-heartbeat-status
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from sys import exit

import click
from nylas.logging import configure_logging, get_logger

from inbox.config import config
from inbox.error_handling import maybe_enable_rollbar
from inbox.heartbeat.status import clear_heartbeat_status
from inbox.logging import configure_logging, get_logger

configure_logging(config.get('LOGLEVEL'))
log = get_logger()
Expand Down
2 changes: 1 addition & 1 deletion bin/contact-search-backfill
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import gevent_openssl
gevent_openssl.monkey_patch()

import click
from nylas.logging import configure_logging, get_logger

from inbox.contacts.search import index_namespace
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger

configure_logging()
log = get_logger()
Expand Down
2 changes: 1 addition & 1 deletion bin/contact-search-delete-index
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
import click
from nylas.logging import configure_logging, get_logger

from inbox.contacts.search import delete_namespace_indexes as delete_indexes
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger

configure_logging()
log = get_logger()
Expand Down
6 changes: 1 addition & 5 deletions bin/contact-search-service
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ monkey.patch_all()
import os

import click
from nylas.logging import configure_logging
from setproctitle import setproctitle

from inbox.config import config as inbox_config
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging
from inbox.util.startup import preflight

setproctitle("nylas-contact-search-index-service")
Expand All @@ -39,10 +39,6 @@ def main(prod, config):
config_path = os.path.abspath(config)
load_overrides(config_path)

if 'CONTACTS_SEARCH' in inbox_config and 'SENTRY_DSN' in \
inbox_config['CONTACTS_SEARCH']:
os.environ['SENTRY_DSN'] = inbox_config['CONTACTS_SEARCH']['SENTRY_DSN']

# import here to make sure config overrides are loaded
from inbox.transactions.search import ContactSearchIndexService

Expand Down
2 changes: 1 addition & 1 deletion bin/create-event-contact-associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from __future__ import division

import click
from nylas.logging import configure_logging, get_logger
from sqlalchemy import asc

from inbox.contacts.processing import update_contacts_from_event
from inbox.error_handling import maybe_enable_rollbar
from inbox.ignition import engine_manager
from inbox.logging import configure_logging, get_logger
from inbox.models import Event
from inbox.models.session import session_scope_by_shard_id
from inbox.models.util import limitlion
Expand Down
2 changes: 1 addition & 1 deletion bin/deferred-migration-service
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import gevent.monkey

gevent.monkey.patch_all()

from nylas.logging import configure_logging
from setproctitle import setproctitle

from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging
from inbox.scheduling.deferred_migration import DeferredAccountMigrationExecutor

configure_logging()
Expand Down
4 changes: 3 additions & 1 deletion bin/delete-marked-accounts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Includes:
* Account liveness/status data (in Redis).
"""
from __future__ import absolute_import

from gevent import monkey

monkey.patch_all()
Expand All @@ -16,10 +18,10 @@ import logging

import click
import gevent
from nylas.logging import configure_logging, get_logger

from inbox.config import config
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger
from inbox.models.util import batch_delete_namespaces, get_accounts_to_delete

configure_logging(logging.INFO)
Expand Down
4 changes: 2 additions & 2 deletions bin/inbox-api
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ except ImportError:

import click
from gevent.pywsgi import WSGIServer
from nylas.api.wsgi import NylasWSGIHandler
from nylas.logging import configure_logging, get_logger

from inbox.api.wsgi import NylasWSGIHandler
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger
from inbox.mailsync.frontend import SyncbackHTTPFrontend
from inbox.util.startup import load_overrides, preflight

Expand Down
3 changes: 1 addition & 2 deletions bin/inbox-auth
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ from setproctitle import setproctitle

setproctitle('inbox-auth')

from nylas.logging import configure_logging

from inbox.auth.base import handler_from_provider
from inbox.basicauth import NotSupportedError
from inbox.config import config
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging
from inbox.models import Account
from inbox.models.session import session_scope
from inbox.util.startup import preflight
Expand Down
3 changes: 2 additions & 1 deletion bin/inbox-console
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ from setproctitle import setproctitle
setproctitle('inbox-console')

import click
from nylas.logging import get_logger

from inbox.logging import get_logger

log = get_logger()

Expand Down
5 changes: 1 addition & 4 deletions bin/inbox-start
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ except ImportError:
"Maybe the Vagrant box provisioning didn't succeed?\n"
"Try running sudo ./setup.sh")

from nylas.logging import configure_logging, get_logger

from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger
from inbox.mailsync.frontend import SyncHTTPFrontend
from inbox.mailsync.service import SyncService
from inbox.util.logging_helper import reconfigure_logging
Expand Down Expand Up @@ -85,8 +84,6 @@ def main(prod, enable_tracer, enable_profiler, config, process_num, exit_after):

maybe_enable_rollbar()

os.environ["SENTRY_DSN"] = inbox_config.get("SENTRY_DSN", "")

if config is not None:
from inbox.util.startup import load_overrides
config_path = os.path.abspath(config)
Expand Down
2 changes: 1 addition & 1 deletion bin/populate-sync-queue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import gevent
import gevent.monkey

gevent.monkey.patch_all()
from nylas.logging import configure_logging
from setproctitle import setproctitle

from inbox.config import config
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging
from inbox.scheduling.queue import QueuePopulator

configure_logging()
Expand Down
4 changes: 3 additions & 1 deletion bin/purge-transaction-log
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Deletes entries in the transaction older than `days_ago` days( as measured by
the created_at column)
"""
from __future__ import absolute_import

from gevent import monkey

monkey.patch_all()
Expand All @@ -12,10 +14,10 @@ import logging

import click
import gevent
from nylas.logging import configure_logging, get_logger

from inbox.config import config
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger
from inbox.models.util import purge_transactions

configure_logging(logging.INFO)
Expand Down
3 changes: 1 addition & 2 deletions bin/restart-forgotten-accounts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import gevent.monkey

gevent.monkey.patch_all()

from nylas.logging import configure_logging, get_logger

from inbox.error_handling import maybe_enable_rollbar
from inbox.ignition import engine_manager
from inbox.logging import configure_logging, get_logger
from inbox.mailsync.service import shared_sync_event_queue_for_zone
from inbox.models.account import Account
from inbox.models.session import global_session_scope
Expand Down
4 changes: 1 addition & 3 deletions bin/syncback-service
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ gevent_openssl.monkey_patch()
import os

import click
from nylas.logging import configure_logging
from setproctitle import setproctitle

from inbox.config import config as inbox_config
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging
from inbox.mailsync.frontend import SyncbackHTTPFrontend
from inbox.transactions.actions import SyncbackService
from inbox.util.logging_helper import reconfigure_logging
Expand Down Expand Up @@ -57,8 +57,6 @@ def main(prod, config, process_num, syncback_id, enable_tracer,
configure_logging(log_level=level)
reconfigure_logging()

os.environ["SENTRY_DSN"] = inbox_config.get("SENTRY_DSN", "")

total_processes = int(os.environ.get('SYNCBACK_PROCESSES', 1))

def start():
Expand Down
3 changes: 1 addition & 2 deletions inbox/actions/backends/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from collections import defaultdict
from imaplib import IMAP4

from nylas.logging import get_logger

from inbox.logging import get_logger
from inbox.mailsync.backends.imap.generic import uidvalidity_cb
from inbox.models import Account, Category, Folder, Message
from inbox.models.backends.imap import ImapUid
Expand Down
3 changes: 1 addition & 2 deletions inbox/actions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
at-least-once semantics.
"""
from nylas.logging import get_logger

from inbox.actions.backends.generic import (
remote_create_folder,
remote_delete_draft,
Expand All @@ -44,6 +42,7 @@
remote_delete_label,
remote_update_label,
)
from inbox.logging import get_logger
from inbox.models import Message
from inbox.models.session import session_scope

Expand Down
12 changes: 6 additions & 6 deletions inbox/api/err.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sys
import traceback

import rollbar
from flask import jsonify, make_response, request
from nylas.logging.log import create_error_log_context, get_logger
from nylas.logging.sentry import sentry_alert

from inbox.logging import create_error_log_context, get_logger

log = get_logger()

Expand All @@ -14,15 +15,14 @@ def get_request_uid(headers):
return headers.get("X-Unique-ID")


def log_exception(exc_info, send_to_sentry=True, **kwargs):
def log_exception(exc_info, **kwargs):
""" Add exception info to the log context for the request.
We do not log in a separate log statement in order to make debugging
easier. As a bonus, this reduces log volume somewhat.
"""
if send_to_sentry:
sentry_alert()
rollbar.report_exc_info(exc_info)

if not is_live_env():
print
Expand Down Expand Up @@ -108,7 +108,7 @@ class AccountDoesNotExistError(APIException):


def err(http_code, message, **kwargs):
""" Handle unexpected errors, including sending the traceback to Sentry. """
""" Handle unexpected errors, including sending the traceback to Rollbar. """
log_exception(sys.exc_info(), user_error_message=message, **kwargs)
resp = {"type": "api_error", "message": message}
resp.update(kwargs)
Expand Down
2 changes: 1 addition & 1 deletion inbox/api/kellogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import arrow
from flask import Response
from nylas.logging import get_logger

from inbox.logging import get_logger
from inbox.models import (
Account,
Block,
Expand Down
2 changes: 1 addition & 1 deletion inbox/api/ns_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
pass


from nylas.logging import get_logger
from inbox.logging import get_logger

log = get_logger()

Expand Down
3 changes: 1 addition & 2 deletions inbox/api/sending.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from datetime import datetime

from nylas.logging import get_logger

from inbox.api.err import err
from inbox.api.kellogs import APIEncoder, encode
from inbox.logging import get_logger
from inbox.sendmail.base import SendMailException, get_sendmail_client

log = get_logger()
Expand Down
2 changes: 1 addition & 1 deletion inbox/api/srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from flask.ext.restful import reqparse
from metrics_api import app as metrics_api
from ns_api import DEFAULT_LIMIT, app as ns_api
from nylas.logging import get_logger
from sqlalchemy.orm.exc import NoResultFound
from werkzeug.exceptions import HTTPException, default_exceptions

Expand All @@ -18,6 +17,7 @@
from inbox.auth.generic import GenericAccountData, GenericAuthHandler
from inbox.auth.google import GoogleAccountData, GoogleAuthHandler
from inbox.auth.microsoft import MicrosoftAccountData, MicrosoftAuthHandler
from inbox.logging import get_logger
from inbox.models import Account, Namespace
from inbox.models.backends.generic import GenericAccount
from inbox.models.backends.gmail import GOOGLE_EMAIL_SCOPE, GmailAccount
Expand Down
Loading

0 comments on commit 64e70ec

Please sign in to comment.