We're Hiring!

Reg Bulk User id creation

Having a problem deploying OMERO? Please ask new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

The OMERO.server installation documentation begins here and you can find OMERO.web deployment documentation here.

Reg Bulk User id creation

Postby mayav » Mon Nov 26, 2018 4:28 am

Hi,

is any way to add or create bulk user id's creation in omero ? more than 40 user in single file in csv or excel formats to omero id creation

thanks
mayav
 
Posts: 51
Joined: Mon Jan 30, 2017 10:50 am

Re: Reg Bulk User id creation

Postby jmoore » Mon Nov 26, 2018 9:21 am

There's no built in way to bulk add, but it's fairly easy to script. Assuming your user CSV looks like this:

Code: Select all
bulk-user1,Albert,A.,bulk-groups,abc123
bulk-user2,Barbara,B.,bulk-groups,def456


then you can use the following code to add the users:

Code: Select all
#!/usr/bin/env python
import omero
import omero.cli
import fileinput

with omero.cli.cli_login() as cli:
    for line in fileinput.input():
        line = line.strip()
        parts = line.split(",")
        assert len(parts) == 5
        omeName, firstName, lastName, groupName, password  = parts
        cli.invoke(["-q", "user", "add", "--ignore-existing",
                    omeName, firstName, lastName, groupName,
                    "--userpassword", password],
                   strict=True)


For example,
Code: Select all
$ bin/omero login root@localhost
Created session for root@localhost:4064. Idle timeout: 10 min. Current group: system
$ bin/omero group add bulk-groups
Added group bulk-groups (id=4) with permissions rw----
$ PYTHONPATH=lib/python ./bulk.py bulk.csv
Added user bulk-user1 (id=3) with password
Added user bulk-user2 (id=4) with password


The "--ignore-existing" flag means that if you update the CSV and re-run the code, you'll see that some users have already been added:
Code: Select all
$ PYTHONPATH=lib/python ./bulk.py bulk.csv
User exists: bulk-user1 (id=3)
User exists: bulk-user2 (id=4)
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Reg Bulk User id creation

Postby mayav » Wed Nov 28, 2018 3:32 am

Hi

Thanks for reply

The group is added successfully, but user creation show some error

Code: Select all
omero@ubuntu-14:~/OMERO.server$ PYTHONPATH=lib/python ./bulk.py bulk.csv
Traceback (most recent call last):
  File "./bulk.py", line 6, in <module>
    with omero.cli.cli_login() as cli:
AttributeError: 'module' object has no attribute 'cli_login'
mayav
 
Posts: 51
Joined: Mon Jan 30, 2017 10:50 am

Re: Reg Bulk User id creation

Postby jmoore » Wed Nov 28, 2018 8:39 am

Hmm...what version of OMERO are you using? (cli_login was added in 5.3.0) but the code is simple enough to be copied into your script completely. Another alternative would be to do the same with bash.

~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Reg Bulk User id creation

Postby mayav » Wed Nov 28, 2018 10:54 am

Hi

My Omero Version is 5.2

Thanks
mayav
 
Posts: 51
Joined: Mon Jan 30, 2017 10:50 am

Re: Reg Bulk User id creation

Postby jmoore » Wed Nov 28, 2018 11:03 am

Gotcha. For being able to maintain this script, would you rather see more Python or Bash? ~J
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Reg Bulk User id creation

Postby mayav » Thu Nov 29, 2018 9:48 am

Bash
mayav
 
Posts: 51
Joined: Mon Jan 30, 2017 10:50 am

Re: Reg Bulk User id creation

Postby jmoore » Thu Nov 29, 2018 10:04 am

Bash script:
Code: Select all
#!/usr/bin/env bash

set -e
set -u
CSVFILE="$1"

omero login

IFS=","
while read omeName firstName lastName groupName password
do
   omero -q user add --ignore-existing \
     "$omeName" "$firstName" "$lastName" "$groupName" \
     --userpassword "$password"
done < "$CSVFILE"


Example:
Code: Select all
$ export PATH=$PATH:/opt/omero/server/OMERO.server/bin/
$ ./bulk.sh bulk.csv
Previous session expired for root on localhost:4064
Server: [localhost:4064]
Username: [root]
Password:
Created session for root@localhost:4064. Idle timeout: 10 min. Current group: system
User exists: bulk-user1 (id=3)
User exists: bulk-user2 (id=4)


~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: Reg Bulk User id creation

Postby mayav » Fri Nov 30, 2018 5:30 am

Hi

it working good, but first line user only created. It skips all other lines without any errors.
And how to delete the unused or unwanted user and group ?

Thanks
mayav
 
Posts: 51
Joined: Mon Jan 30, 2017 10:50 am

Re: Reg Bulk User id creation

Postby jmoore » Fri Nov 30, 2018 6:36 am

Hmmm.... that's surprising. Is there any other output that you can share with us that might give a clue as to what's going on?
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Next

Return to Installation and Deployment

Who is online

Users browsing this forum: No registered users and 1 guest

cron