Exemplo n.º 1
0
		def _renameItem(self, index):
			item=index.internalPointer()
			oldname=item.name()
			olddesc=item.description()
			newname,newdesc,good=QDoubleInputDialog.getDoubleText(self,'modify item info','Enter new item name and description','name','description',oldname,olddesc)
			if(not good):return
			if(newname!=oldname):item.setName(newname)
			if(newdesc!=olddesc):item.setDescription(newdesc)
Exemplo n.º 2
0
        def _addItem(self, collection):
            #Please, dont throw from here!
            try:
                nodes = hou.selectedItems()
            except:
                nodes = hou.selectedNodes()
            if (len(nodes) == 0):
                QMessageBox.warning(self, 'not created',
                                    'selection is empty, nothing to add')
                return

            while True:
                #btn,(name,desc) = (0,('1','2'))#hou.ui.readMultiInput('enter some information about new item',('name','description'),buttons=('Ok','Cancel'))
                name, desc, public, good = QDoubleInputDialog.getDoubleTextCheckbox(
                    self, 'adding a new item to %s' % collection.name(),
                    'enter new item details', 'name', 'description', 'public',
                    '', 'a snippet', False)
                if (not good): return

                if (len(name) > 0):
                    break
                    #validity check

            try:
                #print(name)
                #print(desc)
                #print(hpaste.nodesToString(nodes))
                self.model().addItemToCollection(
                    collection,
                    name,
                    desc,
                    hpaste.nodesToString(nodes),
                    public,
                    metadata={'nettype': self.__netType})
            except CollectionSyncError as e:
                QMessageBox.critical(self, 'something went wrong!',
                                     'Server error occured: %s' % e.message)
Exemplo n.º 3
0
    def newAuthorization(cls, auth=None, altparent=None):
        # appends or changes auth in file
        # auth parameter is used as default data when promped user, contents of auth will get replaced if user logins successfully
        code = 0

        data = cls.readAuthorizationsFile()
        newauth = {}

        if (auth is not None and 'user' in auth and 'token' in auth):
            #just write to config and get the hell out
            #or maybe we can test it first...
            oldones = [
                x for x in data['collections'] if x['user'] == auth['user']
            ]
            for old in oldones:
                data['collections'].remove(old)
            data['collections'].append(auth)
            cls.writeAuthorizationFile(data)
            return True

        while True:
            defuser = auth['user'] if auth is not None else ''
            if (hou.isUIAvailable()):
                btn, (username, password) = hou.ui.readMultiInput(
                    'github authorization required. code %d' % code,
                    ('username', 'password'), (1, ),
                    buttons=('Ok', 'Cancel'),
                    initial_contents=(defuser, ))
            else:
                username, password, btn = QDoubleInputDialog.getUserPassword(
                    altparent, 'authorization',
                    'github authorization required. code %d' % code,
                    'username', 'password', defuser)
                btn = 1 - btn
            if (btn != 0):
                if (auth is None):
                    return False
                else:
                    if (hou.isUIAvailable()):
                        btn = hou.ui.displayMessage(
                            'Do you want to remove account %s from remembered?'
                            % auth['user'],
                            buttons=('Yes', 'No'),
                            close_choice=1)
                    else:
                        btn = QMessageBox.question(
                            altparent, 'question',
                            'Do you want to remove account %s from remembered?'
                            % auth['user'])
                        btn = btn == QMessageBox.No
                    if (btn == 1): return False
                    oldones = [
                        x for x in data['collections']
                        if x['user'] == auth['user']
                    ]
                    for old in oldones:
                        data['collections'].remove(old)
                    try:
                        cls.writeAuthorizationFile(data)
                    except:
                        if (hou.isUIAvailable()):
                            hou.ui.displayMessage(
                                "writing token to file failed!")
                        else:
                            QMessageBox.warning(
                                altparent, 'error',
                                "writing token to file failed!")
                    return False

            for attempt in xrange(
                    4):  #really crude way of avoiding conflicts for now
                headers = {
                    'User-Agent':
                    'HPaste',
                    'Authorization':
                    'Basic %s' % base64.b64encode('%s:%s' %
                                                  (username, password))
                }
                postdata = {
                    'scopes': ['gist'],
                    'note':
                    'HPaste Collection Access at %s, %s' %
                    (socket.gethostname(), ''.join(
                        random.choice(string.ascii_letters)
                        for _ in xrange(6)))
                }
                req = urllib2.Request(r'https://api.github.com/authorizations',
                                      json.dumps(postdata),
                                      headers=headers)
                code, rep = cls.urlopen_nt(req)

                if (code == 201):
                    repdata = json.loads(rep.read())

                    newauth['token'] = repdata[
                        'token']  #TODO: check if reply is as expected
                    newauth['user'] = username
                    if auth is None: auth = {}
                    for key in newauth:
                        auth[key] = newauth[key]
                    oldones = [
                        x for x in data['collections'] if x['user'] == username
                    ]
                    for old in oldones:
                        data['collections'].remove(old)
                    data['collections'].append(newauth)
                    try:
                        cls.writeAuthorizationFile(data)
                    except:
                        if (hou.isUIAvailable()):
                            hou.ui.displayMessage(
                                "writing token to file failed!")
                        else:
                            QMessageBox.warning(
                                altparent, 'error',
                                "writing token to file failed!")
                    return True
                elif (code == 422):
                    #postdata was not accepted
                    #so we just make another attempt of creating a token (github requires unique note)
                    pass
                elif (code == 401):
                    if (hou.isUIAvailable()):
                        hou.ui.displayMessage('wrong username or password')
                    else:
                        QMessageBox.warning(altparent, 'error',
                                            'wrong username or password')
                    break
            else:
                if (hou.isUIAvailable()):
                    hou.ui.displayMessage(
                        'Could not receive token from github.\nDid you verify your email address?\nAlso please check and manually delete all HPaste tokens from your github account here: https://github.com/settings/tokens'
                    )
                else:
                    QMessageBox.warning(
                        altparent, 'error',
                        'Could not receive token from github.\nDid you verify your email address?\nAlso please check and manually delete all HPaste tokens from your github account here: https://github.com/settings/tokens'
                    )
        return False