<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Attaching a python script in a custom tool to live in a custom toolbox, in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158341#M12129</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Probably what you want is this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scheduling a Python script to run at prescribed times&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Desktop » Geoprocessing » Executing tools&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//002100000038000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//002100000038000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It probably doesn't make sense, not practical sense, to make this a script tool - unless you mean you only want a part of this as a tool.&amp;nbsp; At the very beginning of the webhelp documentation, the purpose of the design of this script is posted:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"This topic discusses the process an administrator might go through to run a scheduled nightly reconciliation of versions."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At any rate, this is a rather long and intensive administrator task that:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;a)&amp;nbsp; You wouldn't likely want users' to launch, particularly during the day (which would effectively take the database offline for a lengthy period of time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;b)&amp;nbsp; You would very likely need to monitor the log and need time as an administrator to fix any hiccups that are bound to occur.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;c)&amp;nbsp; There are so many input parameters in this script, users would think they are filling out a job application....just setting it up for the run, unless you set it up in some kind of default mode, will be a headache for most any user...doubtful an administrator would even use it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps, and by the way - I have written overnight scheduled tasks before and they work very well.&amp;nbsp; This one you have chosen to tackle is likely the most complexly powerful one I have ever seen....and it is critical to get it right, particularly if you have many users.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck!&amp;nbsp; It is very interesting though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 27 Jan 2013 21:43:18 GMT</pubDate>
    <dc:creator>T__WayneWhitley</dc:creator>
    <dc:date>2013-01-27T21:43:18Z</dc:date>
    <item>
      <title>Attaching a python script in a custom tool to live in a custom toolbox,</title>
      <link>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158340#M12128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Attaching a python script in a custom tool to live in a custom toolbox,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I couldn�??t manage how the script below (&lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//003n000000v7000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//003n000000v7000000&lt;/A&gt;&lt;SPAN&gt;) can be attached in a custom tool in a custom toolbox such that the end user just needs to enter the connection of the database to run the entire script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-----------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, time, smtplib&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# set the workspace &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = 'Database Connections/admin.sde'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# set a variable for the workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;workspace = arcpy.env.workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# get a list of connected users.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;userList = arcpy.ListUsers("Database Connections/admin.sde")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# get a list of usernames of users currently connected and make email addresses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;emailList = [u.Name + "@yourcompany.com" for user in arcpy.ListUsers("Database Connections/admin.sde")]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# take the email list and use it to send an email to connected users.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SERVER = "mailserver.yourcompany.com"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;FROM = "SDE Admin &amp;lt;&lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:python@yourcompany.com"&gt;python@yourcompany.com&lt;/A&gt;&lt;SPAN&gt;&amp;gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TO = emailList&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SUBJECT = "Maintenance is about to be performed"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MSG = "Auto generated Message.\n\rServer maintenance will be performed in 15 minutes. Please log off."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Prepare actual message&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MESSAGE = """\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;From: %s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;To: %s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Subject: %s&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;%s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;""" % (FROM, ", ".join(TO), SUBJECT, MSG)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Send the mail&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;server = smtplib.SMTP(SERVER)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;server.sendmail(FROM, TO, MESSAGE)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;server.quit()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#block new connections to the database.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AcceptConnections('Database Connections/admin.sde', False)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# wait 15 minutes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;time.sleep(900)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#disconnect all users from the database.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.DisconnectUser('Database Connections/admin.sde', "ALL")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get a list of versions to pass into the ReconcileVersions tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;versionList = arcpy.ListVersions('Database Connections/admin.sde')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Execute the ReconcileVersions tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.ReconcileVersions_management('Database Connections/admin.sde', "ALL_VERSIONS", "sde.DEFAULT", versionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "DELETE_VERSION", "c:/temp/reconcilelog.txt")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Run the compress tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Compress_management('Database Connections/admin.sde')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Allow the database to begin accepting connections again&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AcceptConnections('Database Connections/admin.sde', True)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Get a list of datasets owned by the admin user&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the user name for the workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# this assumes you are using database authentication.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# OS authentication connection files do not have a 'user' property.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;userName = arcpy.Describe(arcpy.env.workspace).connectionProperties.user&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get a list of all the datasets the user has access to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# First, get all the stand alone tables, feature classes and rasters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dataList = arcpy.ListTables('*.' + userName + '.*') + arcpy.ListFeatureClasses('*.' + userName + '.*') + arcpy.ListRasters('*.' + userName + '.*')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Next, for feature datasets get all of the featureclasses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# from the list and add them to the master list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for dataset in arcpy.ListDatasets('*.' + userName + '.*'):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dataList += arcpy.ListFeatureClasses(feature_dataset=dataset)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# pass in the list of datasets owned by the admin to the rebuild indexes and analyze datasets tools&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Note: to use the "SYSTEM" option the user must be an administrator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RebuildIndexes_management(workspace, "SYSTEM", dataList, "ALL")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AnalyzeDatasets_management(workspace, "SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;----------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How such custom tool can be developed to live in a toolbox?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jamal&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Jan 2013 17:23:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158340#M12128</guid>
      <dc:creator>JamalNUMAN</dc:creator>
      <dc:date>2013-01-27T17:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Attaching a python script in a custom tool to live in a custom toolbox,</title>
      <link>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158341#M12129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Probably what you want is this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scheduling a Python script to run at prescribed times&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Desktop » Geoprocessing » Executing tools&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//002100000038000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//002100000038000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It probably doesn't make sense, not practical sense, to make this a script tool - unless you mean you only want a part of this as a tool.&amp;nbsp; At the very beginning of the webhelp documentation, the purpose of the design of this script is posted:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"This topic discusses the process an administrator might go through to run a scheduled nightly reconciliation of versions."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At any rate, this is a rather long and intensive administrator task that:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;a)&amp;nbsp; You wouldn't likely want users' to launch, particularly during the day (which would effectively take the database offline for a lengthy period of time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;b)&amp;nbsp; You would very likely need to monitor the log and need time as an administrator to fix any hiccups that are bound to occur.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;c)&amp;nbsp; There are so many input parameters in this script, users would think they are filling out a job application....just setting it up for the run, unless you set it up in some kind of default mode, will be a headache for most any user...doubtful an administrator would even use it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps, and by the way - I have written overnight scheduled tasks before and they work very well.&amp;nbsp; This one you have chosen to tackle is likely the most complexly powerful one I have ever seen....and it is critical to get it right, particularly if you have many users.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck!&amp;nbsp; It is very interesting though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Jan 2013 21:43:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158341#M12129</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-01-27T21:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Attaching a python script in a custom tool to live in a custom toolbox,</title>
      <link>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158342#M12130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Probably what you want is this:&lt;BR /&gt;&lt;BR /&gt;Scheduling a Python script to run at prescribed times&lt;BR /&gt;Desktop » Geoprocessing » Executing tools&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//002100000038000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//002100000038000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It probably doesn't make sense, not practical sense, to make this a script tool - unless you mean you only want a part of this as a tool.&amp;nbsp; At the very beginning of the webhelp documentation, the purpose of the design of this script is posted:&lt;BR /&gt;&lt;BR /&gt;"This topic discusses the process an administrator might go through to run a scheduled nightly reconciliation of versions."&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;At any rate, this is a rather long and intensive administrator task that:&lt;BR /&gt;&lt;BR /&gt;a)&amp;nbsp; You wouldn't likely want users' to launch, particularly during the day (which would effectively take the database offline for a lengthy period of time.&lt;BR /&gt;&lt;BR /&gt;b)&amp;nbsp; You would very likely need to monitor the log and need time as an administrator to fix any hiccups that are bound to occur.&lt;BR /&gt;&lt;BR /&gt;c)&amp;nbsp; There are so many input parameters in this script, users would think they are filling out a job application....just setting it up for the run, unless you set it up in some kind of default mode, will be a headache for most any user...doubtful an administrator would even use it.&lt;BR /&gt;&lt;BR /&gt;Hope that helps, and by the way - I have written overnight scheduled tasks before and they work very well.&amp;nbsp; This one you have chosen to tackle is likely the most complexly powerful one I have ever seen....and it is critical to get it right, particularly if you have many users.&lt;BR /&gt;&lt;BR /&gt;Good luck!&amp;nbsp; It is very interesting though.&lt;BR /&gt;&lt;BR /&gt;-Wayne&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks Wayne for the time and effort and the distinct help,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I do totally agree with you. You have perfectly described the best workflow for the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My aim from this tool is just to test the behavior of the script by SIMPLE TOOL (accommodated in a toolbox).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Attached is a script tool developed for the same purpose. But it doesn�??t do the �??disconnect users�?� part of the work. All what the user needs to do is to provide the data connection and then the script will run smoothly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]21114[/ATTACH], [ATTACH=CONFIG]21115[/ATTACH], [ATTACH=CONFIG]21116[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jamal&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2013 04:53:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158342#M12130</guid>
      <dc:creator>JamalNUMAN</dc:creator>
      <dc:date>2013-01-28T04:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Attaching a python script in a custom tool to live in a custom toolbox,</title>
      <link>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158343#M12131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't see in your script where you are disconnecting the users&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.DisconnectUser("Database Connections/admin@sde.sde", "ALL")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2013 13:14:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158343#M12131</guid>
      <dc:creator>CarlSunderman</dc:creator>
      <dc:date>2013-01-28T13:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Attaching a python script in a custom tool to live in a custom toolbox,</title>
      <link>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158344#M12132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I don't see in your script where you are disconnecting the users&lt;BR /&gt;&lt;BR /&gt;arcpy.DisconnectUser("Database Connections/admin@sde.sde", "ALL")&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks Carl for the answer. Sorry for the confusion&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Below is the code that I need to have a SCRIPT TOOL (in a toolbox) for (As I don�??t have sufficient skills to do so):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, time, smtplib&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# set the workspace &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = 'Database Connections/admin.sde'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# set a variable for the workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;workspace = arcpy.env.workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# get a list of connected users.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;userList = arcpy.ListUsers("Database Connections/admin.sde")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# get a list of usernames of users currently connected and make email addresses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;emailList = [u.Name + "@yourcompany.com" for user in arcpy.ListUsers("Database Connections/admin.sde")]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# take the email list and use it to send an email to connected users.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SERVER = "mailserver.yourcompany.com"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;FROM = "SDE Admin &amp;lt;&lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:python@yourcompany.com"&gt;python@yourcompany.com&lt;/A&gt;&lt;SPAN&gt;&amp;gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;TO = emailList&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SUBJECT = "Maintenance is about to be performed"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MSG = "Auto generated Message.\n\rServer maintenance will be performed in 15 minutes. Please log off."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Prepare actual message&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MESSAGE = """\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;From: %s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;To: %s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Subject: %s&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;%s&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;""" % (FROM, ", ".join(TO), SUBJECT, MSG)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Send the mail&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;server = smtplib.SMTP(SERVER)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;server.sendmail(FROM, TO, MESSAGE)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;server.quit()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#block new connections to the database.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AcceptConnections('Database Connections/admin.sde', False)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# wait 15 minutes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;time.sleep(900)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#disconnect all users from the database.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.DisconnectUser('Database Connections/admin.sde', "ALL")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get a list of versions to pass into the ReconcileVersions tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;versionList = arcpy.ListVersions('Database Connections/admin.sde')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Execute the ReconcileVersions tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.ReconcileVersions_management('Database Connections/admin.sde', "ALL_VERSIONS", "sde.DEFAULT", versionList, "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "DELETE_VERSION", "c:/temp/reconcilelog.txt")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Run the compress tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Compress_management('Database Connections/admin.sde')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Allow the database to begin accepting connections again&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AcceptConnections('Database Connections/admin.sde', True)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Get a list of datasets owned by the admin user&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get the user name for the workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# this assumes you are using database authentication.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# OS authentication connection files do not have a 'user' property.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;userName = arcpy.Describe(arcpy.env.workspace).connectionProperties.user&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get a list of all the datasets the user has access to.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# First, get all the stand alone tables, feature classes and rasters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dataList = arcpy.ListTables('*.' + userName + '.*') + arcpy.ListFeatureClasses('*.' + userName + '.*') + arcpy.ListRasters('*.' + userName + '.*')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Next, for feature datasets get all of the featureclasses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# from the list and add them to the master list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for dataset in arcpy.ListDatasets('*.' + userName + '.*'):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dataList += arcpy.ListFeatureClasses(feature_dataset=dataset)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# pass in the list of datasets owned by the admin to the rebuild indexes and analyze datasets tools&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Note: to use the "SYSTEM" option the user must be an administrator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RebuildIndexes_management(workspace, "SYSTEM", dataList, "ALL")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AnalyzeDatasets_management(workspace, "SYSTEM", dataList, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;--------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Here is the code that has already a script tool (attached to my previous post)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;---------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Name: GDBMaintenance.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Description: Rebuilds indexes and statistics &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# on geodatabase feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# using an existing .sde file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Author: Esri&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, traceback&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# set the workspace environment using the data owner account&amp;nbsp; D:\Practical2_Editing\Data\Sa_A.sde&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;path=arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = path&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ###########################################################&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Gather all the FeatureClasses and Tables from the Workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datasets = arcpy.ListTables() + arcpy.ListFeatureClasses()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Save geodatabase path to use for concatonating feature dataset names&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;path = arcpy.env.workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Determine if any were found&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for fd in arcpy.arcpy.ListDatasets("","Feature"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = path + "\\" + fd&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Gather the FeatureClasses from the Current Dataset&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; datasets += arcpy.ListFeatureClasses()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = path&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Rebuild and analyze all datasets&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RebuildIndexes_management(arcpy.env.workspace,"NO_SYSTEM",datasets,"ALL")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print arcpy.GetMessages()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AnalyzeDatasets_management(arcpy.env.workspace,"NO_SYSTEM",datasets,"ANALYZE_BASE","ANALYZE_DELTA","ANALYZE_ARCHIVE") &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print arcpy.GetMessages()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Rebuild and analyze all system tables and compress the Geodatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# set the workspace environment using the Geodatabase administrative account&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = path&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ######################################################&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RebuildIndexes_management(arcpy.env.workspace,"SYSTEM","","ALL")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print arcpy.GetMessages()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AnalyzeDatasets_management(arcpy.env.workspace,"SYSTEM","","ANALYZE_BASE","ANALYZE_DELTA","ANALYZE_ARCHIVE") &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print arcpy.GetMessages()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Compress_management(arcpy.env.workspace)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print arcpy.GetMessages()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Processing complete"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jamal&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2013 16:41:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/attaching-a-python-script-in-a-custom-tool-to-live/m-p/158344#M12132</guid>
      <dc:creator>JamalNUMAN</dc:creator>
      <dc:date>2013-01-28T16:41:22Z</dc:date>
    </item>
  </channel>
</rss>

