def send_wyzepal(email, api_key, site, stream, subject, content): # type: (str, str, str, str, str, Text) -> None """ Send a message to WyzePal using the provided credentials, which should be for a bot in most cases. """ client = wyzepal.Client(email=email, api_key=api_key, site=site, client="WyzePalMercurial/" + VERSION) message_data = { "type": "stream", "to": stream, "subject": subject, "content": content, } client.send_message(message_data)
import sys import os.path sys.path.insert(0, os.path.dirname(__file__)) import wyzepal_trac_config as config VERSION = "0.9" if False: from typing import Any, Dict if config.WYZEPAL_API_PATH is not None: sys.path.append(config.WYZEPAL_API_PATH) import wyzepal client = wyzepal.Client( email=config.WYZEPAL_USER, site=config.WYZEPAL_SITE, api_key=config.WYZEPAL_API_KEY, client="WyzePalTrac/" + VERSION) def markdown_ticket_url(ticket, heading="ticket"): # type: (Any, str) -> str return "[%s #%s](%s/%s)" % (heading, ticket.id, config.TRAC_BASE_TICKET_URL, ticket.id) def markdown_block(desc): # type: (str) -> str return "\n\n>" + "\n> ".join(desc.split("\n")) + "\n" def truncate(string, length): # type: (str, int) -> str if len(string) <= length: return string
if __name__ == '__main__': signal.signal(signal.SIGINT, die) logging.basicConfig(level=logging.WARNING) # Get config for each clients wyzepal_config = config["wyzepal"] matrix_config = config["matrix"] # Initiate clients backoff = wyzepal.RandomExponentialBackoff(timeout_success_equivalent=300) while backoff.keep_going(): print("Starting matrix mirroring bot") try: wyzepal_client = wyzepal.Client(email=wyzepal_config["email"], api_key=wyzepal_config["api_key"], site=wyzepal_config["site"]) matrix_client = MatrixClient(matrix_config["host"]) # Login to Matrix matrix_login(matrix_client, matrix_config) # Join a room in Matrix room = matrix_join_room(matrix_client, matrix_config) room.add_listener( matrix_to_wyzepal(wyzepal_client, wyzepal_config, matrix_config)) print("Starting listener thread on Matrix client") matrix_client.start_listener_thread()
or specify the --api-key-file option.""" % (options.api_key_file, )))) sys.exit(1) api_key = open(options.api_key_file).read().strip() # Store the API key in the environment so that our children # don't need to read it in os.environ["HUMBUG_API_KEY"] = api_key if options.nagios_path is None and options.nagios_class is not None: logger.error("\n" + "nagios_path is required with nagios_class\n") sys.exit(1) wyzepal_account_email = options.user + "@mit.edu" import wyzepal wyzepal_client = wyzepal.Client(email=wyzepal_account_email, api_key=api_key, verbose=True, client="zephyr_mirror", site=options.site) start_time = time.time() if options.sync_subscriptions: configure_logger(logger, None) # make the output cleaner logger.info( "Syncing your ~/.zephyr.subs to your WyzePal Subscriptions!") add_wyzepal_subscriptions(True) sys.exit(0) # Kill all zephyr_mirror processes other than this one and its parent. if not options.test_mode: pgrep_query = "python.*zephyr_mirror"
import git_p4 __version__ = "0.1" sys.path.insert(0, os.path.dirname(__file__)) from typing import Any, Dict, Optional, Text import wyzepal_perforce_config as config if config.WYZEPAL_API_PATH is not None: sys.path.append(config.WYZEPAL_API_PATH) import wyzepal client = wyzepal.Client(email=config.WYZEPAL_USER, site=config.WYZEPAL_SITE, api_key=config.WYZEPAL_API_KEY, client="WyzePalPerforce/" + __version__) # type: wyzepal.Client try: changelist = int(sys.argv[1]) # type: int changeroot = sys.argv[2] # type: str except IndexError: print("Wrong number of arguments.\n\n", end=' ', file=sys.stderr) print(__doc__, file=sys.stderr) sys.exit(-1) except ValueError: print("First argument must be an integer.\n\n", end=' ', file=sys.stderr) print(__doc__, file=sys.stderr) sys.exit(-1)
from __future__ import absolute_import from __future__ import print_function import sys import string import random from six.moves import range from typing import List, Dict import wyzepal from slacker import Slacker, Response, Error as SlackError import wyzepal_slack_config as config client = wyzepal.Client(email=config.WYZEPAL_USER, api_key=config.WYZEPAL_API_KEY, site=config.WYZEPAL_SITE) class FromSlackImporter(object): def __init__(self, slack_token, get_archived_channels=True): # type: (str, bool) -> None self.slack = Slacker(slack_token) self.get_archived_channels = get_archived_channels self._check_slack_token() def get_slack_users_email(self): # type: () -> Dict[str, Dict[str, str]] r = self.slack.users.list()
def main(): # type: () -> None signal.signal(signal.SIGINT, die) logging.basicConfig(level=logging.WARNING) parser = generate_parser() options = parser.parse_args() if options.sample_config: try: write_sample_config(options.sample_config, options.wyzepalrc) except Bridge_ConfigException as exception: print("Could not write sample config: {}".format(exception)) sys.exit(1) if options.wyzepalrc is None: print("Wrote sample configuration to '{}'".format( options.sample_config)) else: print( "Wrote sample configuration to '{}' using wyzepalrc file '{}'". format(options.sample_config, options.wyzepalrc)) sys.exit(0) elif not options.config: print( "Options required: -c or --config to run, OR --write-sample-config." ) parser.print_usage() sys.exit(1) try: config = read_configuration(options.config) except Bridge_ConfigException as exception: print("Could not parse config file: {}".format(exception)) sys.exit(1) # Get config for each client wyzepal_config = config["wyzepal"] matrix_config = config["matrix"] # Initiate clients backoff = wyzepal.RandomExponentialBackoff(timeout_success_equivalent=300) while backoff.keep_going(): print("Starting matrix mirroring bot") try: wyzepal_client = wyzepal.Client(email=wyzepal_config["email"], api_key=wyzepal_config["api_key"], site=wyzepal_config["site"]) matrix_client = MatrixClient(matrix_config["host"]) # Login to Matrix matrix_login(matrix_client, matrix_config) # Join a room in Matrix room = matrix_join_room(matrix_client, matrix_config) room.add_listener( matrix_to_wyzepal(wyzepal_client, wyzepal_config, matrix_config, options.no_noise)) print("Starting listener thread on Matrix client") matrix_client.start_listener_thread() print("Starting message handler on WyzePal client") wyzepal_client.call_on_each_message( wyzepal_to_matrix(wyzepal_config, room)) except Bridge_FatalMatrixException as exception: sys.exit("Matrix bridge error: {}".format(exception)) except Bridge_WyzePalFatalException as exception: sys.exit("WyzePal bridge error: {}".format(exception)) except wyzepal.WyzePalError as exception: sys.exit("WyzePal error: {}".format(exception)) except Exception as e: traceback.print_exc() backoff.fail()