Пример #1
0
 def updatePublicList(self):
     try:
         data = GithubAuthorizator.listPublicCollections()
     except IOError as e:
         QMessageBox.warning(self, 'could not read the account file!',
                             'Error: %d : %s' % e.args)
     self.__publicModel.setStringList([x['user'] for x in data])
Пример #2
0
        def __init__(self, parent, flags=0):
            super(AccountsManager.__AccountsManager,
                  self).__init__(parent, flags)

            self.ui = accountsmanager_ui.Ui_MainWindow()
            self.ui.setupUi(self)

            data = GithubAuthorizator.listAuthorizations()
            self.__authModel = QStringListModel([x['user'] for x in data],
                                                self)
            self.ui.authListView.setEditTriggers(
                QAbstractItemView.NoEditTriggers)
            self.ui.authListView.setModel(self.__authModel)

            data = GithubAuthorizator.listPublicCollections()
            self.__publicModel = QStringListModel([x['user'] for x in data],
                                                  self)
            self.ui.publicListView.setEditTriggers(
                QAbstractItemView.NoEditTriggers)
            self.ui.publicListView.setModel(self.__publicModel)

            #slots-signals
            self.ui.addAuthPushButton.clicked.connect(self.newAuth)
            self.ui.removeAuthPushButton.clicked.connect(self.removeAuth)
            self.ui.addPublicPushButton.clicked.connect(self.newPublic)
            self.ui.removePublicPushButton.clicked.connect(self.removePublic)
            self.ui.reinitPushButton.clicked.connect(self.reinitCallback)
Пример #3
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)
Пример #4
0
 def updatePublicList(self):
     try:
         data = GithubAuthorizator.listPublicCollections()
     except IOError as e:
         QMessageBox.warning(self, 'could not read the account file!',
                             'Error: %d : %s' % e.args)
     self.__publicModel.setItemList(
         [[Qt.Checked if x['enabled'] else Qt.Unchecked, x['user']]
          for x in data])
Пример #5
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)
Пример #6
0
 def updatePublicList(self):
     data = GithubAuthorizator.listPublicCollections()
     self.__publicModel.setStringList([x['user'] for x in data])