elog2labfolder/importing_from_elog.rst~
author weiher
Mon, 04 Jun 2018 16:38:36 +0200
changeset 18 57431f642e82
parent 13 a21f3604f1db
permissions -rw-r--r--
Minor additions for comprehension and changes in the document structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     1
Importing projects from e.g. the ELOGbook to Labfolder at the FHI
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     2
=================================================================
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
     3
18
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
     4
This is how you generally do it::
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
     5
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
     6
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
     7
	1. In labfolder, create a new group project.
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
     8
	2. Get the ELOG logbook "operating" and export it as RAW. Remember where you've put the text file with the raw output and the directory with attachments files.
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
     9
	3. Only once: Get the elog2labfolder repository from github.
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    10
	4. Adapt elog2labfolder.py to your needs. Specify the name of the project that you created previously.
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    11
	4. Run elog2labfolder.py
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    12
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    13
These steps are explained in more detail in the following.
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    14
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    15
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    16
Creating a group project
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    17
------------------------
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    18
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    19
As the group admin (or one of the admins) in labfolder create a group project, for example, "operating" in a group named "FEL". You are now the owner of this project. Make sure you don't have several projects of the same name in one group.
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    20
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    21
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    22
Entries from ELOG
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    23
-----------------
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    24
3
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    25
The ELOG entries of a certain project need to be exported as *Raw* which looks like this::
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    26
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    27
	$@MID@$: 12
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    28
	Date: Tue, 03 Dec 2013 12:15:14 +0100
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    29
	Author: Wieland Schöllkopf
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    30
	Author Email: mailto:wschoell@fhi-berlin.mpg.de
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    31
	Category: Shift summary
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    32
	Subject: 1st solid-state experiment with FHI FEL
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    33
	Severity: DOCU
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    34
	Keywords:
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    35
	Record date: 1386069171
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    36
	Attachment:
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    37
	Encoding: HTML
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    38
	========================================
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    39
	<p>Today Alex Paarmann and Marc Herzog are measuring in the wavelength range from 10 to 20 micron with a 0.5 mm thick GGG (Gadolinium Gallium Garnet, <a title="Gadolinium" href="http://en.wikipedia.org/wiki/Gadolinium">Gd</a><sub>3</sub><a title="Gallium" href="http://en.wikipedia.org/wiki/Gallium">Ga</a><sub>5</sub><a title="Oxygen" href="http://en.wikipedia.org/wiki/Oxygen">O</a><sub>12</sub>). Electron energy is set to 26 MeV.</p>
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    40
11
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    41
The entry shown above looks like this in the ELOG webinterface:
3
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    42
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    43
.. image:: _static/elog_entry.png
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    44
   :width: 100 %
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    45
   :align: center
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    46
11
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    47
What is noticeable is that the ELOG export comes with an "ö" instead of an "ö". Interestingly, if only entries done by Wieland are exported the export file has UTF-8 encoding which can actually print German "Umlaute" (ö, ä, ü). If, however, all entries are exported the encoding changes to an encoding that cannot handle e.g. "ö". 
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    48
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    49
After importing the above ELOG entry into labfolder this entry appears like that:
3
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    50
11
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    51
.. image:: _static/entry_after_import.png
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    52
   :width: 100 %
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    53
   :align: center
3
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    54
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    55
11
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    56
Using python to import from ELOG to labfolder
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    57
---------------------------------------------
3
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
    58
11
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    59
There is a GitHub project containing a python program for importing a raw (see the export example above) ELOG project. Get the project files by typing::
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    60
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    61
	$ git clone https://github.molgen.mpg.de/weiher/elog2labfolder.git
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    62
13
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
    63
The script *elog2labfolder.py* is meant to be executed from remote, that is, not on the machine on which labfolder is running. A prerequisit is the python MySQLDB package because for a few methods the labfolder API cannot be used, instead, direct manipulation of the labfolder MySQL database is needed. The actual labfolder API is applied in the methodes collected in *myPythonAPIv1.py* and *myPythonAPIv2.py*. Mostly, API version 2 is used but adding text at the end of an entry can only be accomplished by using the version 1 API call. *getListOfAuthors.py* gives you a list of all authors that are mentioned in a raw ELOG export file.
11
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    64
18
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    65
To finally import an ELOG logbook to a labfolder project you need to run ``$ python elog2labfolder.py``. Prior to this you need to make some changes to the header of the file, that is, these lines:
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    66
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    67
	### Set the hostname 
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    68
	#hostname = 'lftest'
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    69
	hostname = 'labfolder'
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    70
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    71
	if hostname == 'lftest':
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    72
	    server = 'http://' + hostname + '.rz-berlin.mpg.de:9091'
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    73
	elif hostname == 'labfolder':
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    74
	    server = 'https://' + hostname + '.rz-berlin.mpg.de:9091'
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    75
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    76
	### The entries will be created using the following labfolder account which specifies the author of the entry. During the creation process, however, the entry's author ID will be changed to the real 		author's ID if the real author is already contained in the user table of the labfolder DB.
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    77
	email = 'weiher@fhi-berlin.mpg.de'
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    78
	password = getpass.getpass('Enter the labfolder password associated with ' + emailAddress+': ')
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    79
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    80
	### Specify the absolute path to the raw ELOG export file.
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    81
	elogExportFile = '/home/stefan/Dokumente/labfolder/OperatingLogbook_exportRaw_ORIGINAL.txt'
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    82
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    83
	### Full path to where the attachments of the logbook to be imported are stored:
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    84
	attachmentsDirectory = '/home/stefan/Dokumente/labfolder/Operating/'
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    85
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    86
	### Project name in labfolder
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    87
	projectName = 'operating'
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    88
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    89
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
    90
13
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
    91
Alternatives to manipulating the labfolder DB on MySQL level
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
    92
------------------------------------------------------------
11
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    93
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    94
As mentioned previously: a few methods in the python API use a direct manipulation of the labfolder DB via MySQL queries. These methods are:
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    95
13
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
    96
* *createUserAccount(email, author, entryContent, verboseOutput, cursor, db)*: If an author of an ELOG logbook entry does not yet have a labolder account this account is created on the fly by setting a default (encrypted) password. This password is irrelevant because labfolder checks the entered password with the one from the LDAP server. Note: when setting a password in the DB labfolder's LDAP authentication needs to be disabled (FEATURE_LDAP_AUTHENTICATION=false) beforehand and enabled again after the setting process is finished.
11
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    97
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    98
* *updateAuthor(userID, blockID, cursor, db)*: Update the author of an entry. With the script *elog2labfolder.py* an entry is created with the author that is the person whose labfolder credentials are used to get the login token. Via this method the true author can be set to the passed in *userID*.
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
    99
13
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
   100
* *updateDateAndTime(date, blockID, cursor, db)*: Similar to *updateAuthor()* this method sets the creation and modification date to the creation time and date of the entry to be imported. This is necessary because otherwise creation and modification date in labfolder are the time and date when the import took place.
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
   101
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
   102
The labfolder support suggested the following alternative involving using the labfolder API:
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
   103
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
   104
* User account: A user account can be created via the API 2 endpoint ``/auth/signup``. The password will be an encrypted dummy password. In order for this to work the LDAP authentication must be turned off when this endpoint is called. After the account creation LDAP authentication should be turned on again. Once the true user of this account logs in labfolder will ignore the dummy password and check the entered password against the password stored in LDAP.
11
ccfe3c7fa0d2 Erweiterung der Doku um ein Kapitel zum Import und Export; das Kapitel ist noch nicht ganz fertig
weiher
parents: 3
diff changeset
   105
13
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
   106
* Author: To create a labfolder entry by using the original entry's author needs a special work-around. **First, make sure to prevent labfolder users from accessing labfolder for the time of the import.** Then, manually change all user passwords in the DB to the same (encrypted) password. Switch off the LDAP authentication and restart labolder. Now, import entry by entry and get a new login token for each new entry. It is only possible to get login tokens for all users because they all have the same known password. If the author of the entry to be imported does not exist yet in the DB you need to create an account via the API 2 endpoint ``/auth/signup``. Now you reopen the access to the labfolder instance and switch on LDAP again restarting labfolder afterwards. The users can login using their FHI credentials no matter the "universal" password in the DB. If LDAP authentication is not turned on the users could do a password recovery on the login screen and re-set their password to their liking.
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
   107
18
57431f642e82 Minor additions for comprehension and changes in the document structure
weiher
parents: 13
diff changeset
   108
* Date and time: Since you cannot change creation and modification time stamp of an entry via the API you could instead create custom dates during the import of an entry. The original entry creation timestamp could be "Original entry creation" followed by the creation time and date of the import. All entries can be filtered and searched by the custom dates.
3
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   109
b71be85a294c Initial commit of labfolder at FHI documentation
weiher
parents:
diff changeset
   110
13
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
   111
a21f3604f1db Added new chapter about CUPS printers
weiher
parents: 11
diff changeset
   112