def set_interaction_request(self, description, interaction_type, callback): ''' Sets this infobar to request an interaction from the user @param description: a string describing the interaction needed @param interaction_type: a string describing the type of interaction (yes/no, only confirm, ok/cancel...) @param callback: the function to call when the user provides the feedback ''' self._populate() self.callback = callback self.set_message_type(gtk.MESSAGE_INFO) self.label.set_markup(description) self.connect("response", self._on_interaction_response) self.interaction_type = interaction_type if interaction_type == BackendSignals().INTERACTION_CONFIRM: self.add_button(_('Confirm'), gtk.RESPONSE_ACCEPT) elif interaction_type == BackendSignals().INTERACTION_TEXT: self.add_button(_('Continue'), gtk.RESPONSE_ACCEPT) self.show_all()
def main(self, once_thru=False, uri_list=[]): if uri_list: # before opening the requested tasks, we make sure that all of them # are loaded. BackendSignals().connect('default-backend-loaded', self.open_uri_list, uri_list) else: self.open_browser() GObject.threads_init() if not self.gtk_terminate: if once_thru: Gtk.main_iteration() else: Gtk.main() return 0
def do_periodic_import(self): # Establishing connection try: self.cancellation_point() client = Client('%s/api/soap/mantisconnect.php?wsdl' % (self._parameters['service-url'])) except KeyError: self.quit(disable=True) BackendSignals().backend_failed(self.get_id(), BackendSignals.ERRNO_AUTHENTICATION ) return projects = client.service.mc_projects_get_user_accessible( self._parameters['username'], self._parameters['password']) filters = client.service.mc_filter_get(self._parameters['username'], self._parameters['password'], 0) # Fetching the issues self.cancellation_point() my_issues = [] for filt in filters: if filt['name'] == 'gtg': for project in projects: my_issues = client.service.mc_filter_get_issues( self._parameters['username'], self._parameters['password'], project['id'], filt['id'], 0, 100) for issue in my_issues: self.cancellation_point() self._process_mantis_issue(issue) last_issue_list = self.sync_engine.get_all_remote() new_issue_list = [str(issue['id']) for issue in my_issues] for issue_link in set(last_issue_list).difference(set(new_issue_list)): self.cancellation_point() # we make sure that the other backends are not modifying the task # set with self.datastore.get_backend_mutex(): tid = self.sync_engine.get_local_id(issue_link) self.datastore.request_task_deletion(tid) try: self.sync_engine.break_relationship(remote_id=issue_link) except KeyError: pass return
def _authenticate(self): ''' authentication main function ''' self.authenticated.clear() while not self.authenticated.isSet(): if not self.token: self.rtm = createRTM(self.PUBLIC_KEY, self.PRIVATE_KEY, self.token) subprocess.Popen(['xdg-open', self.rtm.getAuthURL()]) self.auth_confirm() try: time.sleep(1) self.token = self.rtm.getToken() except Exception: # something went wrong. self.token = None continue try: if self._login(): self.authenticated.set() except exceptions.IOError: BackendSignals().backend_failed(self.get_id(), BackendSignals.ERRNO_NETWORK)
def do_periodic_import(self): ''' See GenericBackend for an explanation of this function. Connect to launchpad and updates the state of GTG tasks to reflect the bugs on launchpad. ''' # IMPORTANT NOTE! # Bugs can be splitted in bug tasks (such as, you can assign a single # bug to multiple projects: you have one bug and several bug tasks). # At least, one bug contains a bug task (if it's referring to a single # project). # Here, we process bug tasks, since those are the ones that get # assigned to someone. # To avoid having multiple GTG Tasks for the same bug (because we use # bug tasks, this may happen if somebody is working at the same bug for # different projects), we use the bug self_link for indexing the tasks. # Connecting to Launchpad CACHE_DIR = os.path.join(xdg_cache_home, 'gtg/backends/', self.get_id()) if TestingMode().get_testing_mode(): SERVICE_ROOT = STAGING_SERVICE_ROOT else: SERVICE_ROOT = EDGE_SERVICE_ROOT try: self.cancellation_point() self.launchpad = Launchpad.login_anonymously(GTG_NAME, SERVICE_ROOT, CACHE_DIR) except: # The connection is not working (the exception type can be # anything) BackendSignals().backend_failed(self.get_id(), BackendSignals.ERRNO_NETWORK) return # Getting the user data try: self.cancellation_point() me = self.launchpad.people[self._parameters["username"]] except KeyError: self.quit(disable=True) BackendSignals().backend_failed(self.get_id(), BackendSignals.ERRNO_AUTHENTICATION ) return # Fetching the bugs self.cancellation_point() my_bugs_tasks = me.searchTasks(assignee=me, status=["New", "Incomplete", "Confirmed", "Triaged", "In Progress", "Fix Committed"]) # Adding and updating for bug_task in my_bugs_tasks: self.cancellation_point() self._process_launchpad_bug(bug_task) # removing the old ones last_bug_list = self.sync_engine.get_all_remote() new_bug_list = [bug.self_link for bug in my_bugs_tasks] for bug_link in set(last_bug_list).difference(set(new_bug_list)): self.cancellation_point() # we make sure that the other backends are not modifying the task # set with self.datastore.get_backend_mutex(): tid = self.sync_engine.get_local_id(bug_link) self.datastore.request_task_deletion(tid) try: self.sync_engine.break_relationship(remote_id=bug_link) except KeyError: pass