Пример #1
0
 def __init__(self, args, auth):
     folder = BibFolder(folderurl=args.folderurl, decode_output=False, mimetype=args.mimetype, **auth)
     data = args.filename.read()
     try:
         response = folder.put(data)
     except Exception, e:
         print e
Пример #2
0
    def __init__(self, args, auth):
        folder = BibFolder(folderurl=args.folderurl, decode_output=False,
                           mimetype=args.mimetype, **auth)
        simula_author_usernames = args.simula_author_username or []
        if args.mine:
            simula_author_usernames.append(auth['username'])

        paramcount = 0
        for param in (simula_author_usernames, args.author_name, args.search, args.itemid):
            if param:
                paramcount += 1
            if paramcount > 1:
                raise SystemExit('Supplying more than one of (--simula_author_username/--mine), --author_name, --search or --itemid makes no sense, since only the first one is used in the liste order.')

        response = folder.search(simula_author_usernames=simula_author_usernames,
                                 author_names=args.author_name,
                                 search=args.search,
                                 itemids=args.itemid)
        print response
from pprint import pprint
from simula_bibrestclient.client import BibFolder, BibItem
from simula_bibrestclient.diff import create_diff


# Setup our login credentials.
auth = dict(username='******', password='******')
exampleitemid = auth['username'] + '-example'
portal_type = 'ArticleReference'


# Create a bibitem
folder = BibFolder(decode_output=True, **auth)
create_response = folder.create_item(exampleitemid, portal_type,
                                     attributes={'title': 'Example',
                                                 'publication_year': '2012'})
print 'Created {title}'.format(**create_response['attributes'])
print '   View it here: {url}'.format(**create_response)
#pprint(create_response) # Pretty-print the entire response



# Get the created bibitem
itemid = create_response['attributes']['id']
exampleitem = BibItem(itemid, decode_output=True, **auth)


# Pretend to update (no changes are stored in the database, but the response is just like it would be on a regular update)
update_attributes = {'title': 'Updated example item using the Python REST client library'}
pretend_update_response = exampleitem.update(portal_type,
                                             attributes=update_attributes,
Пример #4
0
from simula_bibrestclient.client import BibFolder
from simula_bibrestclient.diff import create_diff
from pprint import pprint

auth = dict(username='******', password='******')
folder = BibFolder(decode_output=True, **auth)

# Add as many items as you like to this list. We only use a single item here
# (we used example.py to create it).
items = [{'portal_type': 'ArticleReference',
          'attributes': {'id': 'grandma-example',
                   'title': 'Super bulk updated example'}}]


# Lets start with getting the current values for our items,
# just to have values to compare with when asking the 
# user to confirm the changes (below)
itemids = [item['attributes']['id'] for item in items]
current_values = folder.search(itemids=itemids)
#pprint(current_values) # pretty-print response


# Then pretend to update to get the changes that will be applied when we update
# for real
pretend_response = folder.bulk_update(pretend=True,
                                      items=items)
#pprint(pretend_response) # pretty-print response


# Ask the user to confirm before bulk updating
print 'Are you sure you want to make the following changes:'
Пример #5
0
from simula_bibrestclient.client import BibFolder, BibItem
from getpass import getpass
from pprint import pprint


def portal_state_updatedmessage(update_response):
    print 'Updated', update_response['attributes']['id']
    print 'The current portal_state is "{portal_state}", and the next possible states are: '.format(**update_response)
    pprint(update_response['portal_state_transitions'])


## Setup our login credentials.
auth = dict(username='******', password='******')
folder = BibFolder(decode_output=True, **auth)
exampleitemid = auth['username'] + '-pubexample'


## Create the item (it will be private by default)
pdf = BibItem.encode_pdf('my.pdf', 'Testdata')
create_response = folder.create_item(exampleitemid, 'ArticleReference',
                                     attributes={'title': 'Example',
                                                 'publication_year': '2012',
                                                 'authors': [{'firstnames': 'Hans Petter',
                                                              'lastname': 'Langtangen',
                                                              'username': '******'},
                                                             {'username': '******',
                                                              'firstnames': 'Carsten',
                                                              'lastname': 'Griwodz'}],
                                                 'simula_pdf_file': pdf})
print 'Created {title}'.format(**create_response['attributes'])
print '   View it here: {url}'.format(**create_response)
Пример #6
0
# We create and update a new ArticleReference with this id/shortname.
# Note that we prefix it with our username so anyone running this script will
# create an article named "<username>-example".
exampleitemid = auth['username'] + '-example'



##################################################
# Work with the folder API
# - search/list
# - create new items in the folder
# - bulk update (update many items in one request)
##################################################

folder = BibFolder(decode_output=True, **auth)

# We can use search() to get bibliography items. If we do not use any
# parameters, ALL simula publications are returned
search_reponse = folder.search(simula_author_usernames=['griff', 'hpl'])
print 'Search for {!r}:'.format(search_reponse['parameters'])
print '    returned {0} items'.format(len(search_reponse['items']))
print '    parameters as they appear to the server:'
print '       ', repr(search_reponse['parameters'])
#pprint(search_reponse) # Pretty-print the entire response


# We can use create_item() to create a new item in the folder
create_response = folder.create_item(exampleitemid, 'ArticleReference',
                                     attributes={'title': 'Example',
                                                 'publication_year': '2012',