arcpy.listusers(workspace) not giving consistent results

3620
4
Jump to solution
04-26-2015 10:32 PM
BenVan_Kesteren1
Occasional Contributor III

Hi All,

I have been running the below line in python, trying to build a list of PC numbers that I can use elsewhere in my script. As PC numbers/names can vary in length I have to modify the output of arcpy.listUsers() to clip the version name which is appended to the ClientName part of the output.

So to clarify what I am doing:

import arcpy
current_users = arcpy.ListUsers(r'Database Connections\GISADMIN@SDE_Spatial@Smithy.sde')

for user in current_users:
     print user

this outputs my users currently connected to the DB, this is an example output:

user(ClientName=u'ACC5283-12:10.3.0.1823', ConnectionTime=datetime.datetime(2015, 4, 27, 12, 21, 48, 1), ID=66566, IsDirectConnection=True, Name=u'GISADMIN')

user(ClientName=u'ACC5285-12:10.3.0.1823', ConnectionTime=datetime.datetime(2015, 4, 27, 13, 13, 17), ID=66589, IsDirectConnection=True, Name=u'"ALBURY\\KERRIERO"')

user(ClientName=u'ACC5623-12:10.3.0.1823', ConnectionTime=datetime.datetime(2015, 4, 27, 13, 36, 35), ID=66594, IsDirectConnection=True, Name=u'"ALBURY\\KADENBR"')

user(ClientName=u'ACC5279-12', ConnectionTime=datetime.datetime(2015, 4, 27, 14, 16, 21), ID=66599, IsDirectConnection=True, Name=u'"ALBURY\\PATREAON"')

Now in order for my script to work I have to make all the ClientNames similar, so what I need is basically 'ACCXXXX-12', and cut off the rest of the clientName which I believe is the version the user is running. Normally I would simply do

     print user.ClientName[:-12]

and this would be fine, but as the ClientName is not consistent it is breaking my code.

See in my output, the user PatreaON (PC name is ACC5279-12), it for some unknown reason does not include the version number.

And that is my problem, is anyone able to tell me why this users output is different to everybody elses?

P.S unfortunately I cannot simply use user.ClientName[0:10] as the pc numbers range from 0-6000, meaning varying length, and ACC is for my current site, this also varies.

Any ideas as to why this user is different?

Cheers

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

Excuse the brevity, using my phone to reply.

Use the split() method i.e user.ClientName.split(':')[0]

View solution in original post

4 Replies
Luke_Pinner
MVP Regular Contributor

Excuse the brevity, using my phone to reply.

Use the split() method i.e user.ClientName.split(':')[0]

BenVan_Kesteren1
Occasional Contributor III

Thanks luke, I have not used that one before, I will give that one a go!

May I ask what happens if the character ':' is not within the specified string?

Works great for what I wanted. As I want everything preceding the colon,  it works. If I need to return anything after (eg. user.ClientName.split(':')[1]) it errors out as soon as a string is found that does not contain a colon.

Thanks for your help.

Cheers!

0 Kudos
Luke_Pinner
MVP Regular Contributor

try:version = user.ClientName.split(':')[1]
except IndexError:version = ''

BenVan_Kesteren1
Occasional Contributor III

Hi All, we also worked out why this user was missing the version number from the listUser results, it turns out this user was running arcMap 10.2.2, not 10.3 like all other users.

Seems obvious now we think about it.

Cheers

0 Kudos