Esempio n. 1
0
        def _authCallback(self, callbackinfo):
            auth, public, action = callbackinfo

            if self.__insideAuthCallback: return  # prevent looping
            self.__insideAuthCallback = True

            try:
                if action == 0 or (action == 2 and not auth['enabled']):
                    good = self.removeCollection(auth['user'])
                    if not good:  # means something went wrong during  removal attempt - probably async collection syncing problem. Try later
                        if public:
                            GithubAuthorizator.setPublicCollsctionEnabled(
                                auth['user'], True)
                        else:
                            GithubAuthorizator.setAuthorizationEnabled(
                                auth['user'], True)

                elif action == 1 or (action == 2 and auth['enabled']):
                    if public:
                        self.addCollection(
                            GithubCollection(auth['user'], public=True),
                            async=True
                        )  # TODO: reuse some token for public access
                    else:
                        self.addCollection(GithubCollection(auth['token']),
                                           async=True)
            except CollectionSyncError as e:
                QMessageBox.critical(
                    self, 'something went wrong!',
                    'could not add/remove collection: %s' % e.message)
            finally:
                self.__insideAuthCallback = False
Esempio n. 2
0
    def __init__(self, parent):
        if (HPasteCollectionWidget.__instance is None):
            HPasteCollectionWidget.__instance = HPasteCollectionWidget.__HPasteCollectionWidget(
                parent)
            try:
                auths = []
                while len(auths) == 0:
                    auths = list(GithubAuthorizator.listAuthorizations())
                    if (len(auths) == 0):
                        if (GithubAuthorizator.newAuthorization()):
                            continue
                        else:
                            raise RuntimeError("No collections")
                    #test
                    todel = []
                    for auth in auths:
                        if (not GithubAuthorizator.testAuthorization(auth)):
                            if (not GithubAuthorizator.newAuthorization(auth)):
                                todel.append(auth)
                    for d in todel:
                        auths.remove(d)
            except Exception as e:
                hou.ui.displayMessage('Something went wrong.\n%s' % e.message)
                self.__instance = None
                raise

            for auth in auths:
                HPasteCollectionWidget.__instance.addCollection(
                    GithubCollection(auth['token']))

            #now public collections

            cols = GithubAuthorizator.listPublicCollections()
            for col in cols:
                try:
                    #TODO: test if collection works
                    ptkn = None
                    if (len(auths) > 0):
                        import random
                        ptkn = random.sample(auths, 1)[0]['token']
                    HPasteCollectionWidget.__instance.addCollection(
                        GithubCollection(col['user'],
                                         public=True,
                                         token_for_public_access=ptkn))
                except Exception as e:
                    msg = ''
                    if (isinstance(e, urllib2.HTTPError)):
                        msg = 'code %d. %s' % (e.code, e.reason)
                    elif (isinstance(e, urllib2.URLError)):
                        msg = e.reason
                    else:
                        msg = e.message
                    hou.ui.displayMessage(
                        'unable to load public collection %s' % col['user'])

        elif (parent is not HPasteCollectionWidget.__instance.parent()):
            print("reparenting")
            HPasteCollectionWidget.__instance.setParent(parent)
Esempio n. 3
0
    def __init__(self, parent):
        if (HPasteCollectionWidget.__instance is None):
            HPasteCollectionWidget.__instance = HPasteCollectionWidget.__HPasteCollectionWidget(
                parent)
            try:
                auths = []

                if (True):
                    auths = list(GithubAuthorizator.listAuthorizations())
                    ## test
                    #todel = []
                    #for auth in auths:
                    #	if (not GithubAuthorizator.testAuthorization(auth)):
                    #		if (not GithubAuthorizator.newAuthorization(auth)):
                    #			todel.append(auth)
                    #for d in todel:
                    #	auths.remove(d)
                # For now don't force people to have their own collections
                while False and len(auths) == 0:
                    auths = list(GithubAuthorizator.listAuthorizations())
                    if (len(auths) == 0):
                        if (GithubAuthorizator.newAuthorization()):
                            continue
                        else:
                            raise RuntimeError("No collections")
                    #test
                    todel = []
                    for auth in auths:
                        if (not GithubAuthorizator.testAuthorization(auth)):
                            if (not GithubAuthorizator.newAuthorization(auth)):
                                todel.append(auth)
                    for d in todel:
                        auths.remove(d)
            except Exception as e:
                hou.ui.displayMessage('Something went wrong.\n%s' % e.message)
                HPasteCollectionWidget.__instance = None
                raise

            for auth in auths:
                if auth['enabled']:
                    HPasteCollectionWidget.__instance.addCollection(
                        GithubCollection(auth['token']), async=True)

            #now public collections
            cols = GithubAuthorizator.listPublicCollections()
            for col in cols:
                if not col['enabled']:
                    continue
                try:
                    #TODO: test if collection works
                    ptkn = None
                    if (len(auths) > 0):
                        import random
                        ptkn = random.sample(auths, 1)[0]['token']
                    HPasteCollectionWidget.__instance.addCollection(
                        GithubCollection(col['user'],
                                         public=True,
                                         token_for_public_access=ptkn),
                        async=True)
                except Exception as e:
                    msg = ''
                    if (isinstance(e, urllib2.HTTPError)):
                        msg = 'code %d. %s' % (e.code, e.reason)
                    elif (isinstance(e, urllib2.URLError)):
                        msg = e.reason
                    else:
                        msg = e.message
                    hou.ui.displayMessage(
                        'unable to load public collection %s: %s' %
                        (col['user'], msg))

            # set callback
            GithubAuthorizator.registerCollectionChangedCallback((
                HPasteCollectionWidget.__instance,
                HPasteCollectionWidget.__HPasteCollectionWidget._authCallback))
        elif (parent is not HPasteCollectionWidget.__instance.parent()):
            log("reparenting", 0)
            HPasteCollectionWidget.__instance.setParent(parent)