예제 #1
0
    def upload_reports(self, ids, path=os.getcwd()):
        nuxeo_dialects = {}
        got_dialects = False
        dialects = None
        while not got_dialects:
            try:
                dialects = self.nuxeo.documents.query(
                    opts={
                        'query':
                        "SELECT * FROM FVDialect "
                        "WHERE ecm:path STARTSWITH '/FV/Workspaces/Data'"
                    })
                got_dialects = True
            except HTTPError:
                nuxeo = Nuxeo(host=Authorize.nuxeoUrl,
                              auth=(Authorize.nuxeoUser,
                                    Authorize.nuxeoPassword))

        entries = dialects.get("entries")
        for item in entries:
            nuxeo_dialects[item.get("fvl:import_id")] = item

        for dialect_id, dialect_name in ids.items():
            if nuxeo_dialects.get(dialect_id):
                for type in self.tables:
                    self.upload_link(
                        dialect_name + type + ".csv", path,
                        nuxeo_dialects.get(dialect_id).path,
                        "List of " + type.lower() + " from legacy site")
                self.upload_link(dialect_name + "Users.csv", path,
                                 nuxeo_dialects.get(dialect_id).path,
                                 "List of users from legacy site")
            else:
                print(dialect_name + " does not exist in nuxeo")
    def get_phrases(self):

        phrase_rows = self.legacy.execute("SELECT ID, PHRASE, DOMINANT_LANGUAGE_PHRASE, CATEGORY_ID, ASSIGNED_USR_ID, "
                                          "CONTRIBUTER, CULTURAL_NOTE, REFERENCE, IMAGE_ENTRY_ID, SOUND_ENTRY_ID, "
                                          "VIDEO_ENTRY_ID, AVAILABLE_IN_CHILDRENS_ARCHIVE, STATUS_ID, CHANGE_DTTM "
                                          "FROM FIRSTVOX.PHRASE_ENTRY WHERE DICTIONARY_ID = '"+str(self.id)+"'")
        for r in phrase_rows:
            phrase = Phrase(self, r[0], r[1].strip(), r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13])
            self.legacy_phrases.append(phrase)
            if r[8] is not None:
                self.dialect_media.append(r[8])
            if r[9] is not None:
                self.dialect_media.append(r[9])
            if r[10] is not None:
                self.dialect_media.append(r[10])

        got_phrases = False
        while not got_phrases:
            try:
                queried_phrases = self.nuxeo.documents.query(opts={'query': "SELECT * FROM FVPhrase WHERE "
                                                                   "fva:dialect = '"+self.doc.uid+"' "
                                                                   "AND ecm:path STARTSWITH '/FV/Workspaces/Data' "})
                got_phrases = True
            except HTTPError:
                self.nuxeo = Nuxeo(host=Authorize.nuxeoUrl, auth=(Authorize.nuxeoUser, Authorize.nuxeoPassword))

        for phrase in queried_phrases.get("entries"):
            self.nuxeo_phrases[phrase.get("fvl:import_id")] = phrase
    def get_alphabet(self):
        rows = self.legacy.execute("SELECT ID, CHAR_DATA, UPPER_CASE_CHAR_DATA, EXTENDED, ALPH_ORDER, "
                                   "SAMPLE_WORD, SOUND_MEDIA_FILENAME, SOUND_DESCRIPTION, "
                                   "SOUND_CONTRIBUTER, SOUND_RECORDER, SOUND_STATUS_ID, CHANGE_DTTM "
                                   "FROM FIRSTVOX.ORTHOGRAPHY WHERE DICTIONARY_ID = '"+str(self.id)+"'")

        for r in rows:
            self.legacy_letters.append(Letter(self, r[0], r[1], r[2], r[3], r[4], r[5], [r[6], r[7], r[8], r[9], r[10]], r[11]))

        # alphabet = None
        # for child in self.nuxeo.documents.get_children(uid=self.doc.uid):
        #     if child.get('dc:title') == "Alphabet":
        #         alphabet = child
        #         break
        #
        # for letter in self.nuxeo.documents.get_children(uid=alphabet.uid):
        #     self.nuxeo_letters[letter.get("fvl:import_id")] = letter

        got_letters = False
        while not got_letters:
            try:
                queried_letters = self.nuxeo.documents.query(opts={'query': "SELECT * FROM FVCharacter WHERE "
                                                                   "fva:dialect = '"+self.doc.uid+"' AND ecm:path "
                                                                   "STARTSWITH '/FV/Workspaces/Data' "})
                got_letters = True
            except HTTPError:
                self.nuxeo = Nuxeo(host=Authorize.nuxeoUrl, auth=(Authorize.nuxeoUser, Authorize.nuxeoPassword))
        for letter in queried_letters.get("entries"):
            self.nuxeo_letters[letter.get("fvl:import_id")] = letter
    def get_links(self):
        rows = self.legacy.execute("SELECT INSTRUCTIONS_MEDIA_FILENAME, INSTRUCTIONS_DESCRIPTION, "
                                   "INSTRUCTIONS_CONTRIBUTER, INSTRUCTIONS_RECORDER, INSTRUCTION_STATUS_ID, "
                                   "MAC_MEDIA_FILENAME, MAC_DESCRIPTION, MAC_CONTRIBUTER, MAC_RECORDER, MAC_STATUS_ID, "
                                   "PC_MEDIA_FILENAME, PC_DESCRIPTION, PC_CONTRIBUTER, PC_RECORDER, PC_STATUS_ID, "
                                   "FROM FIRSTVOX.KEYBOARD ID = '"+str(self.id)+"'")
        for r in rows:
            link = Link(self, r[0], r[0][r[0].rindex('/')+1:], r[1], r[2], r[3], r[4], "instructions")
            self.legacy_links.append(link)
            link = Link(self, r[5], r[5][r[5].rindex('/')+1:], r[6], r[7], r[8], r[9], "mac")
            self.legacy_links.append(link)
            link = Link(self, r[10], r[10][r[10].rindex('/')+1:], r[11], r[12], r[13], r[14], "pc")
            self.legacy_links.append(link)

        # links = None
        # for child in self.nuxeo.documents.get_children(uid=self.doc.uid):
        #     if child.get('dc:title') == "Links":
        #         links = child
        #         break
        #
        # self.nuxeo_links = self.nuxeo.documents.get_children(uid=links.uid)

        got_links = False
        while not got_links:
            try:
                queried_links = self.nuxeo.documents.query(opts={'query': "SELECT * FROM FVLink WHERE "
                                                                 "fva:dialect = '"+self.doc.uid+"' "
                                                                 "AND ecm:path STARTSWITH '/FV/Workspaces/Data' "})
                got_links = True
            except HTTPError:
                self.nuxeo = Nuxeo(host=Authorize.nuxeoUrl, auth=(Authorize.nuxeoUser, Authorize.nuxeoPassword))

        self.nuxeo_links = queried_links.get("entries")
예제 #5
0
def test_update_user_autoset_change_password(server, host):
    with Georges(server) as georges:
        georges.change_password("Test2")
        georges.save()

        auth = BasicAuth("georges", "Test2")
        server2 = Nuxeo(host=host, auth=auth)
        assert server2.users.current_user()
예제 #6
0
def server():
    cookies = RequestsCookieJar()
    cookies.set('device', 'python-client')
    server = Nuxeo(host=os.environ.get('NXDRIVE_TEST_NUXEO_URL',
                                       'http://localhost:8080/nuxeo'),
                   auth=('Administrator', 'Administrator'),
                   cookies=cookies)
    server.client.set(schemas=['dublincore'])
    return server
예제 #7
0
def test_update_user(server, host):
    with Georges(server) as georges:
        company = "Classe Américaine"
        georges.properties["company"] = company
        georges.save()
        user = server.users.get("georges")
        assert user.properties["company"] == company

        auth = BasicAuth("georges", "Test")
        server2 = Nuxeo(host=host, auth=auth)
        assert server2.users.current_user()
예제 #8
0
def server(host):
    cookies = RequestsCookieJar()
    cookies.set("device", "python-client")
    server = Nuxeo(
        host=host,
        auth=BasicAuth("Administrator", "Administrator"),
        cookies=cookies,
    )
    server.client.set(schemas=["dublincore"])

    # Coverage
    assert repr(server)
    assert str(server)

    return server
예제 #9
0
def main():

    # Connection
    host = 'http://localhost:8080/nuxeo/'
    auth = ('Administrator', 'Administrator')
    nuxeo = Nuxeo(host=host, auth=auth)

    # Create a workspace
    new_ws = Document(name='Tests',
                      type='Workspace',
                      properties={
                          'dc:title': 'Tests',
                      })
    workspace = nuxeo.documents.create(
        new_ws, parent_path='/default-domain/workspaces')
    print(workspace)

    # Create a document
    operation = nuxeo.operations.new('Document.Create')
    operation.params = {
        'type': 'File',
        'name': 'foo.txt',
        'properties': {
            'dc:title': 'foo.txt',
            'dc:description': 'bar'
        }
    }
    operation.input_obj = '/'
    doc = operation.execute()
    print(doc)

    # Create a proxy live
    operation = nuxeo.operations.new('Document.CreateLiveProxy')
    operation.params = {
        # NOTICE - ATTENTION
        # CREATE A WORKSPACE AS default-domain/workspaces/ws
        'Destination Path': '/default-domain/workspaces/ws',
    }
    operation.input_obj = '/{}'.format(doc['title'])
    proxy = operation.execute()
    print(proxy)

    entry = nuxeo.documents.get(uid=proxy['uid'])
    print(entry.type)
    def get_words(self):
        word_rows = self.legacy.execute("SELECT ID, WORD_VALUE, DOMINANT_LANGUAGE_WORD_VALUE, PART_OF_SPEECH_ID, "
                                        "CATEGORY_ID, ABORIGINAL_LANGUAGE_SENTENCE, DOMINANT_LANGUAGE_SENTENCE, "
                                        "ASSIGNED_USR_ID, CONTRIBUTER, CULTURAL_NOTE, PHONETIC_INFO, REFERENCE, "
                                        "IMAGE_ENTRY_ID, SOUND_ENTRY_ID, VIDEO_ENTRY_ID, AVAILABLE_IN_CHILDRENS_ARCHIVE"
                                        ", STATUS_ID, DOMINANT_LANGUAGE_DEFINITION, CHANGE_DTTM "
                                        "FROM FIRSTVOX.WORD_ENTRY WHERE DICTIONARY_ID = '"+str(self.id)+"'")
        for r in word_rows:
            word = Word(self, r[0], r[1].strip(), r[2], self.Data.legacy_pos[r[3]], self.Data.legacy_categories[r[4]], r[5], r[6],
                        r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15], r[16], r[17], r[18])
            self.legacy_words.append(word)
            self.word_titles.append(word.title)

            if r[12] is not None:
                self.dialect_media.append(r[12])
            if r[13] is not None:
                self.dialect_media.append(r[13])
            if r[14] is not None:
                self.dialect_media.append(r[14])
        # dictionary = None
        # for child in self.nuxeo.documents.get_children(uid=self.doc.uid):
        #     if child.get('dc:title') == "Dictionary":
        #         dictionary = child
        #         break
        # print(self.nuxeo.client.request("GET", "https://preprod.firstvoices.com/nuxeo/api/v1/id/2a277629-1220-4c29-a068-fc608c64e31d/@children"))
        # i=0
        # while self.nuxeo.documents.get_children(uid=dictionary.uid).get("isNextPageAvailable"):
        #     for w in self.nuxeo.documents.get_children(uid=dictionary.uid):
        #         if w.type == "FVWord":
        #             self.nuxeo_words[w.get("fvl:import_id")] = w
        #         if w.type == "FVPhrase":
        #             self.nuxeo_phrases[w.get("fvl:import_id")] = w
        #     i += 1
        got_words = False
        while not got_words:
            try:
                queried_words = self.nuxeo.documents.query(opts={'query': "SELECT * FROM FVWord WHERE "
                                                                 "fva:dialect = '"+self.doc.uid+"' "
                                                                 "AND ecm:path STARTSWITH '/FV/Workspaces/Data'"})
                got_words = True
            except HTTPError:
                self.nuxeo = Nuxeo(host=Authorize.nuxeoUrl, auth=(Authorize.nuxeoUser, Authorize.nuxeoPassword))
        for w in queried_words.get("entries"):
            self.nuxeo_words[w.get("fvl:import_id")] = w
예제 #11
0
 def auth() -> None:
     """Retrieve a token and create the account."""
     user = str(username.text())
     pwd = str(password.text())
     nuxeo = Nuxeo(host=url, auth=(user, pwd))
     try:
         token = nuxeo.client.request_auth_token(
             device_id=self.manager.device_id,
             app_name=APP_NAME,
             permission=TOKEN_PERMISSION,
             device=get_device(),
         )
     except Exception as exc:
         log.error(f"Connection error: {exc}")
         token = ""
     finally:
         del nuxeo
     self.api.handle_token(token, user)
     dialog.close()
예제 #12
0
    def launch(self, body) -> (str, int):
        output = 'Service TODO: ' + str(body)
        outputStatus = status.HTTP_400_BAD_REQUEST

        # params should looks like :
        # {
        #   "instance":
        #   {
        #       "url": "https://.../nuxeo",
        #       "user": "******",
        #       "pwd":  "xxx"
        #   },
        #   "query": "SELECT * FROM Document WHERE ..."
        #  }

        if body['instance'] and body['instance']['url'] and body['instance']['user'] and body['instance']['pwd'] and \
                body['query']:

            try:
                # output = None
                nuxeo = Nuxeo(host=body['instance']['url'],
                              auth=(body['instance']['user'],
                                    body['instance']['pwd']))

                # Make the request
                search = nuxeo.client.query(body['query'])

                # Get results
                entries = search['entries']
                output = json.dumps(entries)
                if output:
                    outputStatus = status.HTTP_200_OK
                else:
                    outputStatus = status.HTTP_204_NO_CONTENT

            except:
                print("Oops!", sys.exc_info()[0], "occured.")
                output = str(sys.exc_info()[0])
                outputStatus = status.HTTP_500_INTERNAL_SERVER_ERROR

        return output, outputStatus
    def get_contributors(self):
        # contributors = None
        # for child in self.nuxeo.documents.get_children(uid=self.doc.uid):
        #     if child.get('dc:title') == "Contributors":
        #         contributors = child
        #         break
        #
        # self.nuxeo_contributors = self.nuxeo.documents.get_children(uid=contributors.uid)

        got_contributors = False
        while not got_contributors:
            try:
                queried_sources = self.nuxeo.documents.query(opts={'query': "SELECT * FROM FVContributor WHERE "
                                                                   "fva:dialect = '"+self.doc.uid+"' "
                                                                   "AND ecm:path STARTSWITH '/FV/Workspaces/Data' "})

                got_contributors = True
            except HTTPError:
                self.nuxeo = Nuxeo(host=Authorize.nuxeoUrl, auth=(Authorize.nuxeoUser, Authorize.nuxeoPassword))

        self.nuxeo_contributors = queried_sources.get("entries")
예제 #14
0
def server(nuxeo_url):
    """
    Get the Nuxeo instance.

    For now, we do not allow to use another than Administrator:Administrator
    to prevent unexpected actions on critical servers.
    """
    auth = ("Administrator", "Administrator")
    server = Nuxeo(host=nuxeo_url, auth=auth)
    server.client.set(schemas=["dublincore"])

    # Save bandwith by caching operations details
    global OPS_CACHE
    if not OPS_CACHE:
        OPS_CACHE = server.operations.operations
        nuxeo.operations.API.ops = OPS_CACHE
    global SERVER_INFO
    if not SERVER_INFO:
        SERVER_INFO = server.client.server_info()
        nuxeo.client.NuxeoClient._server_info = SERVER_INFO

    return server
예제 #15
0
def main():

    # Connection
    host = "http://localhost:8080/nuxeo/"
    auth = ("Administrator", "Administrator")
    nuxeo = Nuxeo(host=host, auth=auth)

    # Create a workspace
    new_ws = Document(name="Tests", type="Workspace", properties={"dc:title": "Tests"})
    workspace = nuxeo.documents.create(new_ws, parent_path="/default-domain/workspaces")
    print(workspace)

    # Create a document
    operation = nuxeo.operations.new("Document.Create")
    operation.params = {
        "type": "File",
        "name": "foo.txt",
        "properties": {"dc:title": "foo.txt", "dc:description": "bar"},
    }
    operation.input_obj = "/"
    doc = operation.execute()
    print(doc)

    # Create a proxy live
    operation = nuxeo.operations.new("Document.CreateLiveProxy")
    operation.params = {
        # NOTICE - ATTENTION
        # CREATE A WORKSPACE AS default-domain/workspaces/ws
        "Destination Path": "/default-domain/workspaces/ws"
    }
    operation.input_obj = f"/{doc['title']}"
    proxy = operation.execute()
    print(proxy)

    entry = nuxeo.documents.get(uid=proxy["uid"])
    print(entry.type)
예제 #16
0
        operation.execute(file_out=file_out)
    finally:
        os.remove(filename)
        os.remove(file_out)


@profile
def run_test(server):
    file_in = "test_in"
    n = 10
    docs = []
    for i in range(n):
        filename = create_random_file(file_in, i)
        docs.append(upload_file(server, filename))

    for i in range(n):
        download_file(server, file_in, i)

    for doc in docs:
        doc.delete()


if __name__ == "__main__":
    server = Nuxeo(
        host=os.environ.get("NXDRIVE_TEST_NUXEO_URL",
                            "http://localhost:8080/nuxeo"),
        auth=("Administrator", "Administrator"),
    )
    server.client.set(schemas=["dublincore"])
    run_test(server)
예제 #17
0
"""Cleanup old test users and workspaces."""
import os

from nuxeo.client import Nuxeo


def remove_old_ws(server: Nuxeo) -> None:
    docs = server.documents.get_children(path="/default-domain/workspaces")
    for doc in docs:
        if doc.title.startswith(("ndt-", "test_")):
            print(f"Deleting old {doc}")
            doc.delete()


def remove_old_users(server: Nuxeo) -> None:
    op = server.operations.new("User.Query")
    op.params = {"username": "******"}
    for user in op.execute()["users"]:
        print(f"Deleting old {user}")
        server.users.delete(user["username"])


url = os.getenv("NXDRIVE_TEST_NUXEO_URL", "http://localhost:8080/nuxeo")
auth = ("Administrator", "Administrator")
server = Nuxeo(host=url, auth=auth)
server.client.set(schemas=["dublincore"])

remove_old_ws(server)
remove_old_users(server)
예제 #18
0
파일: tccdump.py 프로젝트: dejon97/tccdump
from nuxeo.client import Nuxeo
import csv


def writefile(docId):
    doc = nuxeo.documents.get(uid=docId)
    output_filename = docId + '.pdf'
    output_file = open(output_filename, "wb")
    output_file.write(doc.fetch_blob())
    output_file.close()


nuxeo = Nuxeo(host='http://eagle.wisepoint.info:8082/nuxeo/',
              auth=('UserName', 'Password'))

with open('test.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    for row in csv_reader:
        print(row[0])
        writefile(row[0])
예제 #19
0
class BColors(object):
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'


host = os.environ.get('NXDRIVE_TEST_SERVER_URL', 'http://localhost:8080/nuxeo')
auth = (os.environ.get('NXDRIVE_TEST_USER', 'Administrator'),
        os.environ.get('NXDRIVE_TEST_PASSWORD', 'Administrator'))

nuxeo = Nuxeo(host=host, auth=auth)


def color_print(text, color):
    print('{}{}{}'.format(color, text, BColors.ENDC))


def print_duplicates(path, uids):
    print('{}\'{}\'{} appears {} times with following uids:\n{}'.format(
        BColors.OKBLUE, path, BColors.ENDC, len(uids), '\n'.join(uids)))


def compute_uid_line(item):
    if item['state'] == 'deleted':
        return ''.join([item['uid'], ' (deleted)'])
    else:
예제 #20
0
"""Cleanup old test users and workspaces."""
import env
from nuxeo.client import Nuxeo


def remove_old_ws(server: Nuxeo) -> None:
    docs = server.documents.get_children(path=env.WS_DIR)
    for doc in docs:
        if doc.title.startswith(("ndt-", "test_")):
            doc.delete()
            print(f"Deleted old {doc}")


def remove_old_users(server: Nuxeo) -> None:
    op = server.operations.new("User.Query")
    op.params = {"username": "******"}
    for user in op.execute()["users"]:
        server.users.delete(user["username"])
        print(f"Deleted old {user}")


auth = (env.NXDRIVE_TEST_USERNAME, env.NXDRIVE_TEST_PASSWORD)
server = Nuxeo(host=env.NXDRIVE_TEST_NUXEO_URL, auth=auth)
server.client.set(schemas=["dublincore"])

remove_old_ws(server)
remove_old_users(server)
예제 #21
0
def init_nuxeo():
    return Nuxeo(host=str(os.environ['NUXEO_URL']),
                 auth=(str(os.environ['NUXEO_USERNAME']),
                       str(os.environ['NUXEO_PASSWORD'])))
예제 #22
0
 def start(self):
     super(NuxeoKernel, self).start()
     self.nuxeo = Nuxeo(host='http://127.0.0.1:8080/nuxeo/',
                        auth=('Administrator', 'Administrator'))
     self.log.error("Nuxeo client started")
    def get_books(self):
        rows = self.legacy.execute("SELECT ID, ABORIGINAL_LANGUAGE_TITLE, DOMINANT_LANGUAGE_TITLE, ASSIGNED_USR_ID, "
                                   "CONTRIBUTER, CULTURAL_NOTE, IMAGE_ENTRY_ID, SOUND_ENTRY_ID, VIDEO_ENTRY_ID, "
                                   "AVAILABLE_IN_CHILDRENS_ARCHIVE, STATUS_ID,  ABORIGINAL_LANGUAGE_INTRO, "
                                   "DOMINANT_LANGUAGE_INTRO, AUTHOR, AUTHOR_REFERENCE, CONTRIBUTER_REFERENCE, "
                                   "DOMINANT_LANGUAGE_TRANSLATION, SSTYPE_ID, CHANGE_DTTM, SORT_MAP "
                                   "FROM FIRSTVOX.SENTRY_BOOK WHERE DICTIONARY_ID = '"+str(self.id)+"'")
        for r in rows:
            book = Book(self, r[0], r[1], r[2], r[3], r[4], r[5], "", r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15], r[16], r[17], r[18], r[19])
            self.legacy_books.append(book)
            if r[6] is not None:
                self.dialect_media.append(r[6])
            if r[7] is not None:
                self.dialect_media.append(r[7])
            if r[8] is not None:
                self.dialect_media.append(r[8])
        # books = None
        # for child in self.nuxeo.documents.get_children(uid=self.doc.uid):
        #     if child.get('dc:title') == "Stories & Songs":
        #         books = child
        #         break
        #
        # for book in self.nuxeo.documents.get_children(uid=books.uid):
        #     self.nuxeo_books[book.get("fvl:import_id")] = book

        got_books = False
        while not got_books:
            try:
                queried_books = self.nuxeo.documents.query(opts={'query': "SELECT * FROM FVBook WHERE "
                                                                 "fva:dialect = '"+self.doc.uid+"' "
                                                                 "AND ecm:path STARTSWITH '/FV/Workspaces/Data' "})

                got_books = True
            except HTTPError:
                self.nuxeo = Nuxeo(host=Authorize.nuxeoUrl, auth=(Authorize.nuxeoUser, Authorize.nuxeoPassword))

        for book in queried_books.get("entries"):
            self.nuxeo_books[book.get("fvl:import_id")] = book

        rows = self.legacy.execute("SELECT ID, ABORIGINAL_LANGUAGE_TEXT, DOMINANT_LANGUAGE_TEXT, ASSIGNED_USR_ID, "
                                   "DOMINANT_LANGUAGE_TRANSLATION, SENTRY_BOOK_ID, CULTURAL_NOTE, "
                                   "IMAGE_ENTRY_ID, SOUND_ENTRY_ID, VIDEO_ENTRY_ID, CHANGE_DTTM, SORT_MAP "
                                   "FROM FIRSTVOX.SENTRY WHERE DICTIONARY_ID = '"+str(self.id)+"'")
        for r in rows:
            entry = BookEntry(self, r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11])
            self.legacy_book_entries.append(entry)
            if r[7] is not None:
                self.dialect_media.append(r[7])
            if r[8] is not None:
                self.dialect_media.append(r[8])
            if r[9] is not None:
                self.dialect_media.append(r[9])

        # for book in self.nuxeo_books.values():
        #     for entry in self.nuxeo.documents.get_children(uid=book.uid):
        #         self.nuxeo_book_entries[entry.get("fvl:import_id")] = entry


        got_entries = False
        while not got_entries:
            try:
                queried_entries = self.nuxeo.documents.query(opts={'query': "SELECT * FROM FVBookEntry WHERE "
                                                                   "fva:dialect = '"+self.doc.uid+"' "
                                                                   "AND ecm:path STARTSWITH '/FV/Workspaces/Data' "})

                got_entries = True
            except HTTPError:
                self.nuxeo = Nuxeo(host=Authorize.nuxeoUrl, auth=(Authorize.nuxeoUser, Authorize.nuxeoPassword))

        for entry in queried_entries.get("entries"):
            self.nuxeo_book_entries[entry.get("fvl:import_id")] = entry
    def get_media(self):
        i = 0
        j = min(len(self.dialect_media), 1000)
        while j <= len(self.dialect_media) and j != 0:
            rows = self.legacy.execute("SELECT ID, FILENAME, DESCR, ASSIGNED_USR_ID, CONTRIBUTER, RECORDER, "
                                       "MEDIA_TYPE_ID, IS_SHARED, STATUS_ID "
                                       "FROM FIRSTVOX.ENTRY_MEDIA WHERE ID IN "+str(tuple(self.dialect_media[i:j]))+"")

            for r in rows:
                file = MediaFile(self, r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8])
                self.legacy_media[r[0]] = file
            i += 1000
            j += 1000
            if j > len(self.dialect_media) > i:
                j = len(self.dialect_media)

        # media = None
        # for child in self.nuxeo.documents.get_children(uid=self.doc.uid):
        #     if child.get('dc:title') == "Resources":
        #         media = child
        #         break
        #
        # for file in self.nuxeo.documents.get_children(uid=media.uid):
        #     if file.type == "FVAudio":
        #         self.nuxeo_audio[file.get("fvl:import_id")] = file
        #     elif file.type == "FVVideo":
        #         self.nuxeo_videos[file.get("fvl:import_id")] = file
        #     elif file.type == "FVPicture":
        #         self.nuxeo_imgs[file.get("fvl:import_id")] = file

        got_entries = False
        while not got_entries:
            try:
                queried_imgs = self.nuxeo.documents.query(opts={'query': "SELECT * FROM FVPicture WHERE "
                                                                "fva:dialect = '"+self.doc.uid+"' "
                                                                "AND ecm:path STARTSWITH '/FV/Workspaces/Data' "})

                got_entries = True
            except HTTPError:
                self.nuxeo = Nuxeo(host=Authorize.nuxeoUrl, auth=(Authorize.nuxeoUser, Authorize.nuxeoPassword))

        for img in queried_imgs.get("entries"):
            self.nuxeo_imgs[img.get("fvl:import_id")] = img

        got_entries = False
        while not got_entries:
            try:
                queried_audio = self.nuxeo.documents.query(opts={'query': "SELECT * FROM FVAudio WHERE "
                                                                 "fva:dialect = '"+self.doc.uid+"' "
                                                                 "AND ecm:path STARTSWITH '/FV/Workspaces/Data' "})

                got_entries = True
            except HTTPError:
                self.nuxeo = Nuxeo(host=Authorize.nuxeoUrl, auth=(Authorize.nuxeoUser, Authorize.nuxeoPassword))

        for audio in queried_audio.get("entries"):
            self.nuxeo_audio[audio.get("fvl:import_id")] = audio

        got_entries = False
        while not got_entries:
            try:
                queried_video = self.nuxeo.documents.query(opts={'query': "SELECT * FROM FVVideo WHERE "
                                                                 "fva:dialect = '"+self.doc.uid+"' "
                                                                 "AND ecm:path STARTSWITH '/FV/Workspaces/Data' "})

                got_entries = True
            except HTTPError:
                self.nuxeo = Nuxeo(host=Authorize.nuxeoUrl, auth=(Authorize.nuxeoUser, Authorize.nuxeoPassword))

        for video in queried_video.get("entries"):
            self.nuxeo_videos[video.get("fvl:import_id")] = video
def validate_dialect(dialect_id):
    """ gathers all data for the dialect (words, phrases, media files, etc), compares them to corresponding data in nuxeo,
     creates a csv reports of the dialect numbers and errors. If dialect.update_dialect() is uncommented then will also
     fix simple dialect errors"""

    dialect = ""
    entries = cur.execute(
        "SELECT ID, NAME, ADMIN_EMAIL_ADDRESS, ADMIN_FIRST_NAME, ADMIN_LAST_NAME, "  # 0-4
        "ADMIN_PHONE_NUMBER, CHANGE_DTTM, CONTACT_INFORMATION"  # 5-7 
        ", CONTACT_INFORMATION2, CONTACT_INFORMATION3, CONTACT_INFORMATION4, COUNTRY_ID, DESCR, "  # 8-12
        "DESCR2, DESCR3, DESCR4, DOMINANT_LANGUAGE, DOMINANT_LANGUAGE_FR, FIRST_WORD_ONE_ID, "  # 13-18
        "FIRST_WORD_TWO_ID, FIRST_WORD_THREE_ID, FIRST_WORD_FOUR_ID, FIRST_WORD_FIVE_ID, "  # 19-22
        "GRAMMAR_RULES_NAME, GRAMMAR_RULES_DESCRIPTION, GRAMMAR_RULES_CONTRIBUTER, "  # 23-25
        "GRAMMAR_RULES_MEDIA_FILENAME, GRAMMAR_RULES_RECORDER, GRAMMAR_RULES_STATUS_ID, "  # 26-28
        "IMAGE_MEDIA_FILENAME, IMAGE_DESCRIPTION, IMAGE_RECORDER, IMAGE_CONTRIBUTER, "  # 29-32
        "IMAGE_STATUS_ID, LANG_GRP_ID, LANGUAGE_FAMILY_ID, PORTAL_ABOUT_MORE, PORTAL_ABOUT_MORE_2,"  # 33-37
        " PORTAL_ABOUT_TEXT, PORTAL_ART_GALLERY_STATUS_ID, PORTAL_PHOTO_ALBUMN_STATUS_ID, "  # 38-40
        "PORTAL_GREETING, PORTAL_COLUMN_TITLE, PORTAL_COLUMN_TEXT, PORTAL_PEOPLE_NAME, "  # 41-44
        "PORTAL_RELATED_LINKS, PORTAL_STATUS_ID, PORTAL_THEME_ID, PRONUNCIATION_GUIDE_FILENAME, "  # 45-48
        "PRONUNCIATION_NAME, PRONUNCIATION_GUIDE_DESCR, PRONUNCIATION_GUIDE_RECORDER, "  # 49-51
        "PRONUNCIATION_GUIDE_CONTRIB, PRONUNCIATION_GUIDE_STATUS_ID, PUBLIC_ACCESS, REGION, "  # 52-55
        "SHOW_ALPHABET_LIST, SHOW_KEYBOARD, SOUND_MEDIA_FILENAME, SOUND_DESCRIPTION, "  # 56-59
        "SOUND_CONTRIBUTER, SOUND_RECORDER, SOUND_STATUS_ID, SPECIAL_CSS, STATUS_ID, "  # 60-64
        "FRIENDLY_URL_SEGMENT FROM FIRSTVOX.DICTIONARY WHERE ID = " +
        str(dialect_id) + "")

    for r in entries:
        admin_info = [r[2], r[3], r[4], r[5]]
        contact_info = [r[7], r[8], r[9], r[10]]
        descriptions = [r[12], r[13], r[14], r[15]]
        first_words = [r[18], r[19], r[20], r[21], r[22]]
        grammar_rules = [r[23], r[24], r[25], r[26], r[27], r[28]]
        image = [r[29], r[30], r[31], r[32], r[33]]
        portal_info = [
            r[36], r[37], r[38], r[41], r[42], r[43], r[44], r[45], r[46],
            r[47]
        ]
        pronunciation = [r[48], r[49], r[50], r[51], r[52], r[53]]
        sound = [r[58], r[59], r[60], r[61], r[62]]
        dialect = Dialect(r[0], r[1], admin_info, contact_info, descriptions,
                          r[11], r[16], r[17], r[54], r[55], r[64], r[65],
                          grammar_rules, pronunciation, r[39], r[40], r[34],
                          r[35], r[6], data)
        portal = Portal(dialect, portal_info, first_words, image, sound, r[56],
                        r[57])
        dialect.portal = portal
        missing = [145, 401, 403, 185, 406
                   ]  # these don't exist in nuxeo (are all test/demo dialects)
        if dialect.id not in missing:
            while True:
                try:
                    dialect.get_attributes()
                    dialect.validate()
                    dialect.report()
                    # dialect.update_dialect()  # uncomment to update flagged properties in Flags.update_names
                    print(
                        str(dialect.id) + " " + dialect.title + " is complete")
                    break
                except ConnectionError as connect:
                    print("CONNECTION RETRY")
                    print(connect)
                    nuxeo = Nuxeo(host=Authorize.nuxeoUrl,
                                  auth=(Authorize.nuxeoUser,
                                        Authorize.nuxeoPassword))
                    continue
        else:
            print(str(dialect.id) + " " + dialect.title + " is MISSING")
    return dialect
예제 #26
0
    except Exception:
        doc.delete()
    return doc


@profile
def download_file(server, filename):
    operation = server.operations.new('Blob.Get')
    operation.input_obj = '/default-domain/workspaces/{}'.format(filename)
    operation.execute(file_out=filename)


@profile
def run_test(server):
    filename = 'big_mama.bin'
    create_file(filename)

    doc = upload_file(server, filename)
    os.remove(filename)

    download_file(server, filename)
    doc.delete()


if __name__ == '__main__':
    server = Nuxeo(host=os.environ.get('NXDRIVE_TEST_NUXEO_URL',
                                       'http://localhost:8080/nuxeo'),
                   auth=('Administrator', 'Administrator'))
    server.client.set(schemas=['dublincore'])
    run_test(server)