Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions example.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# username, name, email, [organization], [location], [group], [access_level]
wayne,Bruce Wayne,bruce.wayne@wayne-entreprises.com,Wayne Entreprises,Gotham City,board,owner
kent,Clark Kent,clark.kent@krypton.univ,,Smallville
# username, name, email, [organization], [location], [group], [access_level], [can_create_group], [external], [skip_confirmation], [projects_limit]
wayne,Bruce Wayne,bruce.wayne@wayne-entreprises.com,Wayne Entreprises,Gotham City,group,developer,False,True,True,0
kent,Clark Kent,clark.kent@krypton.univ,test,Smallville,group,reporter,False,True,True,0
12 changes: 9 additions & 3 deletions src/gitlab_users/gitlab_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import gitlab
import os
import sys
import json


ACCESS_LEVEL = {'guest': gitlab.GUEST_ACCESS,
Expand Down Expand Up @@ -404,11 +405,16 @@ def _check(self):

def _create(self):
print("Creating...")
print(self.userdict)
self.gluser = self.gl.users.create(self.userdict)
# 'organization' and 'location' field are not created by current
# version of python-gitlab (0.20) so add them using .save() method
self.gluser.organization = self.userdict['organization']
self.gluser.location = self.userdict['location']
self.gluser.external = json.loads(self.userdict['external'].lower())
self.gluser.can_create_group = json.loads(self.userdict['can_create_group'].lower())
self.gluser.skip_confirmation = json.loads(self.userdict['skip_confirmation'].lower())
self.gluser.projects_limit = int(self.userdict['projects_limit'])
self.gluser.save()
print(" User {} created".format(self.userdict['username']))

Expand Down Expand Up @@ -493,17 +499,17 @@ def delete(self):

def get_usernames_from_csv(filename):
"""Return a list of usernames"""
with open(filename, 'r') as csvfile:
with open(filename, 'r', encoding='utf-8-sig') as csvfile:
csvreader = csv.reader(row for row in csvfile
if not row.startswith('#'))
return [row[0] for row in csvreader]


def get_users_from_csv(filename):
"""Return a dict containing users information"""
with open(filename, 'r') as csvfile:
with open(filename, 'r', encoding='utf-8-sig') as csvfile:
fieldnames = 'username', 'name', 'email', 'organization', 'location', \
'group', 'access_level'
'group', 'access_level', 'can_create_group', 'external', 'skip_confirmation', 'projects_limit'
# Filter csv file header
csvreader = csv.reader(row for row in csvfile
if not row.startswith('#'))
Expand Down