def setup_drive(self): credentials = storage.get() self.queue = queue = Queue.Queue() if credentials is None: flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, redirect_uri=REDIRECT_URI) authorize_url = flow.step1_get_authorize_url() print 'Go to the following link in your browser: ' + authorize_url code = raw_input('Enter verification code: ').strip() credentials = flow.step2_exchange(code) storage.put(credentials) http = httplib2.Http() http = credentials.authorize(http) self.drive_service = drive_service = build('drive', 'v2', http=http) self.thread_pool = thread_pool = DriveThreadPool(1, queue, credentials)
def __init__(self, folders_to_track, start_sync_at, pyfile, **kwargs): super(DriveMainThread, self).__init__(**kwargs) self.drive_data = DBInterface( os.path.dirname(os.path.abspath(pyfile)) + '/drive_data/', 'drive_files') base_path = os.path.dirname(os.path.abspath(pyfile)) + '/' self.updated_folders = set() self.start_sync_at = start_sync_at self.folders_to_track = folders_to_track self.setup_drive() self.update_queue = Queue.Queue() self.get_tracked_folder_ids( folders_to_track, os.path.dirname(os.path.abspath(pyfile)) + '/') self.tracked_widgets = {} self.folders_to_track = [ base_path + path + '/' for path in folders_to_track ]
def __init__(self, num_threads): super(_ThreadPool, self).__init__() self.running = True self.tasks = queue.Queue() for _ in range(num_threads): _Worker(self, self.tasks)