コード例 #1
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def addUserToWriteGroup(newUserName, RemoteDeckID, serverURL, username,
                        password):
    server = connectionHandler(serverURL, username, password)
    try:
        server.addUserToWriteGroup(newUserName, RemoteDeckID)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
コード例 #2
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def getAccessGroups(RemoteDeckID, serverURL, username, password):
    server = connectionHandler(serverURL, username, password)
    try:
        return server.getAccessGroups(RemoteDeckID)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
        return None
コード例 #3
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def removeUserFromAdminGroup(removeUserName, RemoteDeckID, serverURL, username,
                             password):
    server = connectionHandler(serverURL, username, password)
    try:
        server.removeUserFromAdminGroup(removeUserName, RemoteDeckID)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
コード例 #4
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def getAccessGroups(RemoteDeckID, serverURL, username, password):
    server = connectionHandler(serverURL, username, password)
    try:
        return server.getAccessGroups(RemoteDeckID)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
        return None
コード例 #5
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def sync(localDeckID, serverURL, username, password, firsttime=True):
    """Syncronice a local deck with a remote deck."""
    col = mw.col
    col.flush()
    # Create a Server handle to send the requests to
    server = connectionHandler(serverURL, username, password)
    col = mw.col
    print("Starting sync")
    # Create a Deck object from the localDeckID
    localDeckToPush = AnkipubSubDeck.fromLocalID(localDeckID)
    # Check if we have a RemoteId for the deck
    # if not we assume the Deck doesnt exist on the server
    if not localDeckToPush.getRemoteID():

        print("The deck with the {0} did not have a RemoteId\
         so we push it to the server".format(localDeckID))
        # copy that stuff because server.push push does conversion magic
        remoteDeck = server.push_deck(localDeckToPush)
        """deepcopy that bitch because of conversion magic in serverupdate\
        UserDict-->Json and not back todo maybe do this in serverupdate not\
         sure but for now f**k it"""

        print('write new entry to DeckIDs RemoteId\
         = {0} localid = {1}'.format(remoteDeck.getRemoteID(), localDeckID))

        remoteDeck.save(mw.col, serverURL)
    else:  # deck exists
        print('The we are trying to sync\
        has following remote ID {0}'.format(localDeckToPush.getRemoteID()))
        """We pull the Deck from the Server to check if there\
         where any changes done"""
        remoteDeckPull = server.pull_deck(localDeckToPush.getRemoteID())
        """If the Date from the last Change on the Server is newer then the\
         Date we wrote in our Database local"""
        #
        print('Last Change on the Server\
         Deck {0}'.format(remoteDeckPull.getLastChange()))
        print('Last Change on the Local\
         Deck {0}'.format(localDeckToPush.getLastChange()))

        newNotes = False
        for note in localDeckToPush.getNotes():
            if not note.getRemoteID():
                newNotes = True

        if (remoteDeckPull.getLastChange() >
                localDeckToPush.getLastChange()) and firsttime:
            print('Deck on the Server is newer so we pull the deck')
            remoteDeckPull.save(col, serverURL)
            sync(localDeckID, serverURL, username, password, False)
            # We call sync again to push the local changes we made
        elif (newNotes):
            print('We have a newer deck so we push to the server')
            remoteDeckPush = server.push_deck(localDeckToPush)
            remoteDeckPush.save(col, serverURL)
        else:
            print(
                'We have not added new Notes and the Server has no new notes for us so we dont do anything'
            )
コード例 #6
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def upload(localDeckID, serverURL, username, password):
    localDeckToPush = AnkipubSubDeck.fromLocalID(localDeckID)
    server = connectionHandler(serverURL, username, password)
    try:
        remoteDeck = server.push_deck(localDeckToPush)
        remoteDeck.save(mw.col, serverURL)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
コード例 #7
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def publishDeck(localDeckID, name, serverURL, username, password, readingPassword=None, writingPassword=None):
    localDeckToPush = AnkipubSubDeck.fromLocalID(localDeckID)
    server = connectionHandler(serverURL, username, password)
    try:
        remoteDeck = server.push_deck(localDeckToPush)
        remoteDeck.save(mw.col, serverURL)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
コード例 #8
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def download(localDeckID, serverURL, username, password):
    localDeckToPush = AnkipubSubDeck.fromLocalID(localDeckID)
    server = connectionHandler(serverURL, username, password)
    try:
        remoteDeckPull = server.pull_deck(localDeckToPush.getRemoteID())
        remoteDeckPull.save(mw.col, serverURL)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
コード例 #9
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def sync(localDeckID, serverURL, username, password, firsttime=True):
    """Syncronice a local deck with a remote deck."""
    col = mw.col
    col.flush()
    # Create a Server handle to send the requests to
    server = connectionHandler(serverURL, username, password)
    col = mw.col
    print("Starting sync")
    # Create a Deck object from the localDeckID
    localDeckToPush = AnkipubSubDeck.fromLocalID(localDeckID)
    # Check if we have a RemoteId for the deck
    # if not we assume the Deck doesnt exist on the server
    if not localDeckToPush.getRemoteID():

        print("The deck with the {0} did not have a RemoteId\
         so we push it to the server".format(localDeckID))
        # copy that stuff because server.push push does conversion magic
        remoteDeck = server.push_deck(localDeckToPush)

        """deepcopy that bitch because of conversion magic in serverupdate\
        UserDict-->Json and not back todo maybe do this in serverupdate not\
         sure but for now f**k it"""

        print('write new entry to DeckIDs RemoteId\
         = {0} localid = {1}'.format(remoteDeck.getRemoteID(), localDeckID))

        remoteDeck.save(mw.col, serverURL)
    else:  # deck exists
        print('The we are trying to sync\
        has following remote ID {0}'.format(localDeckToPush.getRemoteID()))
        """We pull the Deck from the Server to check if there\
         where any changes done"""
        remoteDeckPull = server.pull_deck(localDeckToPush.getRemoteID())
        """If the Date from the last Change on the Server is newer then the\
         Date we wrote in our Database local"""
        #
        print('Last Change on the Server\
         Deck {0}'.format(remoteDeckPull.getLastChange()))
        print('Last Change on the Local\
         Deck {0}'.format(localDeckToPush.getLastChange()))

        newNotes = False
        for note in localDeckToPush.getNotes():
            if not note.getRemoteID():
                newNotes = True

        if (remoteDeckPull.getLastChange() > localDeckToPush.getLastChange()) and firsttime:
            print('Deck on the Server is newer so we pull the deck')
            remoteDeckPull.save(col, serverURL)
            sync(localDeckID, serverURL, username, password, False)
            # We call sync again to push the local changes we made
        elif(newNotes):
            print('We have a newer deck so we push to the server')
            remoteDeckPush = server.push_deck(localDeckToPush)
            remoteDeckPush.save(col, serverURL)
        else:
            print('We have not added new Notes and the Server has no new notes for us so we dont do anything')
コード例 #10
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def removeUserFromAdminGroup(removeUserName,
                             RemoteDeckID,
                             serverURL,
                             username,
                             password):
    server = connectionHandler(serverURL, username, password)
    try:
        server.removeUserFromAdminGroup(removeUserName, RemoteDeckID)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
コード例 #11
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def addUserToWriteGroup(newUserName,
                        RemoteDeckID,
                        serverURL,
                        username,
                        password):
    server = connectionHandler(serverURL, username, password)
    try:
        server.addUserToWriteGroup(newUserName, RemoteDeckID)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
コード例 #12
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def addRemoteDeck(remoteDeckID, serverURL, username, password):
    """Download a Remote Deck From the Server \
    and creates it in the local database."""
    # Create a Server handle to send the requests to
    server = connectionHandler(serverURL, username, password)
    print('Starting to add a Remote Deck with the id {0}'.format(remoteDeckID))
    # pull the remote Deck from the server with the passed rID
    try:
        remoteDeckPull = server.pull_deck(remoteDeckID)
        print(remoteDeckPull.getNotes())
        # Create the Deck
        remoteDeckPull.save(mw.col, serverURL)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
コード例 #13
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def addRemoteDeck(remoteDeckID, serverURL, username, password):
    """Download a Remote Deck From the Server \
    and creates it in the local database."""
    # Create a Server handle to send the requests to
    server = connectionHandler(serverURL, username, password)
    print('Starting to add a Remote Deck with the id {0}'.format(remoteDeckID))
    # pull the remote Deck from the server with the passed rID
    try:
        remoteDeckPull = server.pull_deck(remoteDeckID)
        print(remoteDeckPull.getNotes())
        # Create the Deck
        remoteDeckPull.save(mw.col, serverURL)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
コード例 #14
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def getReadGroup(RemoteDeckID, serverURL, username, password):
    server = connectionHandler(serverURL, username, password)
    try:
        server.getReadGroup(RemoteDeckID)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)
コード例 #15
0
ファイル: database.py プロジェクト: Sohalt/Ankipubsub-Client
def getReadGroup(RemoteDeckID, serverURL, username, password):
    server = connectionHandler(serverURL, username, password)
    try:
        server.getReadGroup(RemoteDeckID)
    except (AuthError, NotFoundError) as e:
        showInfo(e.message)