Created
August 18, 2020 15:49
-
-
Save stdavis/b06dffae0a4e9945acbef6f81db280a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# * coding: utf8 * | |
''' | |
bootstrap_local_sde.py | |
Bootstraps a local SDE database with users. | |
Creates a new enterprise database with the sde schema. | |
Creates a connection file using operating system auth. | |
Adds passed in users (password matches the username) and creates connection files for each of them. | |
Usage example: | |
`python bootstrap_local_sde.py SGID CADASTRE,BOUNDARIES` | |
''' | |
from pathlib import Path | |
from sys import argv | |
import arcpy | |
LICENSE_FILE_PATH = r'C:\Program Files\ESRI\License10.7\sysgen\keycodes' | |
CURRENT_FOLDER = Path(__file__).parent | |
SDE_USERNAME = 'sde' | |
SDE_PASSWORD = 'sde' | |
database_name = argv[1] | |
users = argv[2].split(',') | |
print(f'creating database: {database_name}...') | |
arcpy.CreateEnterpriseGeodatabase_management( | |
'SQL_Server', | |
'(local)', | |
database_name=database_name, | |
account_authentication='OPERATING_SYSTEM_AUTH', | |
sde_schema=True, | |
gdb_admin_password=SDE_PASSWORD, | |
authorization_file=LICENSE_FILE_PATH, | |
) | |
connection = arcpy.CreateDatabaseConnection_management( | |
str(CURRENT_FOLDER), | |
database_name, | |
'SQL_SERVER', | |
'(local)', | |
account_authentication='OPERATING_SYSTEM_AUTH', | |
save_user_pass='SAVE_USERNAME', | |
database=database_name) | |
for user in users: | |
print(f'adding user: {user}') | |
arcpy.CreateDatabaseUser_management(connection, | |
'DATABASE_USER', | |
user_name=user, | |
user_password=user) | |
arcpy.CreateDatabaseConnection_management(str(CURRENT_FOLDER), | |
f'{database_name}@{user}', | |
'SQL_SERVER', | |
'(local)', | |
'DATABASE_AUTH', | |
username=user, | |
password=user, | |
save_user_pass=True, | |
database=database_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment