# Path: foos/process.py
# def call_and_log(*args, **kwargs):
#     """Run process, gather output and write to log"""
#     p = subprocess.Popen(*args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
#     stdout, stderr = p.communicate()
#     if len(stdout) > 0:
#         logger.info(stdout.decode("utf-8").strip())
#     if len(stderr) > 0:
#         logger.error(stderr.decode("utf-8").strip())
#     if p.returncode != 0:
#         logger.error("{} returned {}".format(p.args, p.returncode))


import http.client
import httplib2
import os
import random
import sys
import time
import logging
import foos.config as config
from foos.process import call_and_log
from apiclient.discovery import build
from apiclient.errors import HttpError
from apiclient.http import MediaFileUpload
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import argparser, run_flow
            if retry > MAX_RETRIES:
                logger.error("No longer attempting to retry.")

            max_sleep = 2 ** retry
            sleep_seconds = random.random() * max_sleep
            logger.error("Sleeping %f seconds and then retrying...", sleep_seconds)
            time.sleep(sleep_seconds)


class Plugin:
    def __init__(self, bus):
        self.bus = bus
        self.bus.subscribe(self.process_event, thread=True)
        self.replay_data = {}
        self.current_score = ('?', '?')

    def process_event(self, ev):
        if ev.name == 'score_changed':
            self.current_score = ev.data['yellow'], ev.data['black']
        elif ev.name == 'replay_start':
            self.replay_data = ev.data

        if ev.name != 'upload_request':
            return

        self.bus.notify('upload_start')
        text = 'Replay'
        if self.replay_data.get('type') == 'goal':
            text = '{} goal'.format(self.replay_data.get('team', '?').capitalize())


# Path: foos/process.py
# def call_and_log(*args, **kwargs):
#     """Run process, gather output and write to log"""
#     p = subprocess.Popen(*args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
#     stdout, stderr = p.communicate()
#     if len(stdout) > 0:
#         logger.info(stdout.decode("utf-8").strip())
#     if len(stderr) > 0:
#         logger.error(stderr.decode("utf-8").strip())
#     if p.returncode != 0:
#         logger.error("{} returned {}".format(p.args, p.returncode))


# Path: plugins/upload.py
import http.client
import httplib2
import os
import random
import sys
import time
import logging
import foos.config as config
from foos.process import call_and_log
from apiclient.discovery import build
from apiclient.errors import HttpError
from apiclient.http import MediaFileUpload
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import argparser, run_flow

            if retry > MAX_RETRIES:
                logger.error("No longer attempting to retry.")

            max_sleep = 2 ** retry
            sleep_seconds = random.random() * max_sleep
            logger.error("Sleeping %f seconds and then retrying...", sleep_seconds)
            time.sleep(sleep_seconds)


class Plugin:
    def __init__(self, bus):
        self.bus = bus
        self.bus.subscribe(self.process_event, thread=True)
        self.replay_data = {}
        self.current_score = ('?', '?')

    def process_event(self, ev):
        if ev.name == 'score_changed':
            self.current_score = ev.data['yellow'], ev.data['black']
        elif ev.name == 'replay_start':
            self.replay_data = ev.data

        if ev.name != 'upload_request':
            return

        self.bus.notify('upload_start')
        text = 'Replay'
        if self.replay_data.get('type') == 'goal':
            text = '{} goal'.format(self.replay_data.get('team', '?').capitalize())


        title = "{}: {}-{}".format(text, self.current_score[0], self.current_score[1])