예제 #1
0
 def _generate_message_id(self, date_header, from_addr):
     if sys.version_info[0] < 3:  #3--
         date_str = self._header_value_as_ascii_str(date_header)  #3--
         timestamp = mktime_tz(parsedate_tz(date_str))  #3--
     else:  #3: remove *this* line and *dedent* the next line
         timestamp = date_header.datetime.timestamp()
     msg_id = 'n6.{}.{}'.format(trunc(timestamp), make_hex_id(length=32))
     _, domain = from_addr.split('@')
     return '<{}@{}>'.format(msg_id, domain)
예제 #2
0
 def _generate_sources(self):
     for i, source_id in enumerate(self.source_ids):
         source = self.db_session.query(Source).get(source_id)
         if source is None:
             source = Source(
                 source_id=source_id,
                 anonymized_source_id=self.ANONYMIZED_SOURCE_PREFIX + make_hex_id(16))
         self.msg_sub(source)
         yield source
예제 #3
0
 def _populate_sources(self, sources):
     for i, source_id in enumerate(sources):
         source = db_session.query(Source).get(source_id)
         if source is None:
             source = Source(
                 source_id=source_id,
                 anonymized_source_id=self.ANONYMIZED_SOURCE_PREFIX +
                 make_hex_id(16))
         print source
         yield source
예제 #4
0
 def __init__(self, settings):
     self._auth_tkt_policy = AuthTktAuthenticationPolicy(
         secret=make_hex_id(), hashalg='sha384', secure=False)
예제 #5
0
 def _make_commit_tag(self):
     return '{utc_datetime:%Y-%m-%dT%H:%M:%S.%fZ}#{random_id}'.format(
         utc_datetime=datetime.datetime.utcnow(),
         random_id=make_hex_id(length=12))
예제 #6
0
 def _generate_message_id(self, date_header, from_addr):
     timestamp = date_header.datetime.timestamp()
     msg_id = 'n6.{}.{}'.format(trunc(timestamp), make_hex_id(length=32))
     _, domain = from_addr.split('@')
     return '<{}@{}>'.format(msg_id, domain)
예제 #7
0
def own_db_context():
    # To make this script able to create and run the MariaDB docker
    # container automatically (locally, by itself) -- you need to:
    #
    # 1) have your Linux user able to launch Docker by executing
    #    '/usr/bin/docker' file; typically, that means you need to:
    #
    #    * have Docker installed;
    #    * have your Linux user associated with the appropriate system
    #      group, e.g., 'docker';
    #    * place in your sudoers file (see: the `sudoers` and `visudo`
    #      man pages) the line:
    #      ```
    #      <your Linux user name>  ALL = NOPASSWD: /usr/bin/docker
    #      ```
    #      (where `<your Linux user name>` is your Linux user name --
    #      who would have thought?);
    #
    # 2) run this script with the `--own-db` command-line option.

    DOCKER_EXECUTABLE = '/usr/bin/docker'
    MARIADB_DOCKER_NAME = '{}-{}'.format(MARIADB_STANDARD_HOSTNAME,
                                         make_hex_id(16))
    MARIADB_RUN_COMMAND = [
        DOCKER_EXECUTABLE,
        'run',
        '--name',
        MARIADB_DOCKER_NAME,
        '-e',
        'MYSQL_ROOT_PASSWORD='******'-d',
        'mariadb:10',
    ]
    MARIADB_GET_IP_COMMAND = [
        DOCKER_EXECUTABLE,
        'inspect',
        '--format',
        '{{ .NetworkSettings.IPAddress }}',
        MARIADB_DOCKER_NAME,
    ]
    MARIADB_STOP_COMMAND = [
        DOCKER_EXECUTABLE,
        'stop',
        MARIADB_DOCKER_NAME,
    ]
    MARIADB_REMOVE_COMMAND = [
        DOCKER_EXECUTABLE,
        'rm',
        '-f',
        '-v',
        MARIADB_DOCKER_NAME,
    ]

    @contextlib.contextmanager
    def make_devnull():
        f = os.open(os.devnull, os.O_RDWR)
        try:
            yield f
        finally:
            os.close(f)

    def run_db():
        shutdown_db()
        with make_devnull() as devnull:
            check_call(MARIADB_RUN_COMMAND, stdout=devnull)
            mariadb_host = check_output(MARIADB_GET_IP_COMMAND,
                                        universal_newlines=True).strip()
        return mariadb_host

    def shutdown_db():
        with make_devnull() as devnull:
            call(MARIADB_STOP_COMMAND, stdout=devnull, stderr=devnull)
            call(MARIADB_REMOVE_COMMAND, stdout=devnull, stderr=devnull)

    global db_host

    db_host = run_db()
    try:
        yield
    finally:
        shutdown_db()