arcresthelper package¶
Subpackages¶
Submodules¶
arcresthelper.common module¶
-
exception
arcresthelper.common.
ArcRestHelperError
[source]¶ Bases:
exceptions.Exception
Raised when error occurs in utility module functions.
-
class
arcresthelper.common.
Tee
(*files)[source]¶ Bases:
object
Combines standard output with a file for logging.
-
arcresthelper.common.
chunklist
(l, n)[source]¶ Yield successive n-sized chunks from l.
Parameters: Yields: The next chunk in the object.
Raises: Examples
>>> for c in arcresthelper.common.chunklist(list(range(20)), 6): ... print(c) [0, 1, 2, 3, 4, 5] [6, 7, 8, 9, 10, 11] [12, 13, 14, 15, 16, 17] [18, 19] >>> list(arcresthelper.common.chunklist(string.ascii_uppercase, 7)) ['ABCDEFG', 'HIJKLMN', 'OPQRSTU', 'VWXYZ']
-
arcresthelper.common.
close_log
(log_file)[source]¶ Closes the open file and returns
sys.stdout
to the default (i.e., console output).Parameters: log_file (file) – The file object to close.
-
arcresthelper.common.
find_replace
(obj, find, replace)[source]¶ Searches an object and performs a find and replace.
Parameters: Returns: The object with replaced strings.
Return type:
-
arcresthelper.common.
find_replace_string
(obj, find, replace)[source]¶ Performs a string.replace() on the input object.
Parameters: Returns: The replaced string.
Return type:
-
arcresthelper.common.
getLayerIndex
(url)[source]¶ Extract the layer index from a url.
Parameters: url (str) – The url to parse. Returns: The layer index. Return type: int Examples
>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12" >>> arcresthelper.common.getLayerIndex(url) 12
-
arcresthelper.common.
getLayerName
(url)[source]¶ Extract the layer name from a url.
Parameters: url (str) – The url to parse. Returns: The layer name. Return type: str Examples
>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12" >>> arcresthelper.common.getLayerIndex(url) 'test'
-
arcresthelper.common.
getOrgId
(url)[source]¶ Extract the org ID from a url.
Parameters: url (str) – The url to parse. Returns: The org ID. Return type: str Examples
>>> url = "http://services.arcgis.com/<random>/arcgis/rest/services/test/FeatureServer/12" >>> arcresthelper.common.getLayerIndex(url) '<random>'
-
arcresthelper.common.
init_config_json
(config_file)[source]¶ Deserializes a JSON configuration file.
Parameters: config_file (str) – The path to the JSON file. Returns: A dictionary object containing the JSON data. If config_file
does not exist, returnsNone
.Return type: dict
-
arcresthelper.common.
init_log
(log_file)[source]¶ Creates log file on disk and “Tees”
sys.stdout
to console and diskParameters: log_file (str) – The path on disk to append or create the log file. Returns: The opened log file. Return type: file
-
arcresthelper.common.
is_number
(s)[source]¶ Determines if the input is numeric
Parameters: s – The value to check. Returns: True
if the input is numeric,False
otherwise.Return type: bool
-
arcresthelper.common.
local_time_to_online
(dt=None)[source]¶ Converts datetime object to a UTC timestamp for AGOL.
Parameters: dt (datetime) – The datetime.datetime
object to convert. Defaults toNone
, i.e.,datetime.datetime.now()
.Returns: A UTC timestamp as understood by AGOL (time in ms since Unix epoch * 1000) Return type: float Examples
>>> arcresthelper.common.local_time_to_online() # PST 1457167261000.0 >>> dt = datetime.datetime(1993, 3, 5, 12, 35, 15) # PST >>> arcresthelper.common.local_time_to_online(dt) 731392515000.0
See also
online_time_to_string()
for converting a UTC timestamp
-
arcresthelper.common.
merge_dicts
(dicts, op=<built-in function add>)[source]¶ Merge a list of dictionaries.
Parameters: - dicts (list) – a list of dictionary objects
- op (operator) – an operator item used to merge the dictionaries. Defaults to
operator.add()
.
Returns: the merged dictionary
Return type:
-
arcresthelper.common.
noneToValue
(value, newValue)[source]¶ Convert
None
to a different value.Parameters: - value – The value to convert. This can be anything.
- newValue – The resultant value. This can be anything.
Returns: newValue
-
arcresthelper.common.
online_time_to_string
(value, timeFormat, utcOffset=0)[source]¶ Converts AGOL timestamp to formatted string.
Parameters: Returns: A string representation of the timestamp.
Return type: Examples
>>> arcresthelper.common.online_time_to_string(1457167261000.0, "%Y-%m-%d %H:%M:%S") '2016-03-05 00:41:01' >>> arcresthelper.common.online_time_to_string(731392515000.0, '%m/%d/%Y %H:%M:%S', -8) # PST is UTC-8:00 '03/05/1993 12:35:15'
See also
local_time_to_online()
for converting adatetime.datetime
object to AGOL timestamp
-
arcresthelper.common.
random_int_generator
(maxrange)[source]¶ Generates a random integer from 0 to maxrange, inclusive.
Parameters: maxrange (int) – The upper range of integers to randomly choose. Returns: The randomly generated integer from random.randint()
.Return type: int Examples
>>> arcresthelper.common.random_int_generator(15) 9
-
arcresthelper.common.
random_string_generator
(size=6, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ')[source]¶ Generates a random string from a set of characters.
Parameters: - size (int) – The length of the resultant string. Defaults to 6.
- chars (str) – The characters to be used by
random.choice()
. Defaults tostring.ascii_uppercase
.
Returns: The randomly generated string.
Return type: Examples
>>> arcresthelper.common.random_string_generator() 'DCNYWU' >>> arcresthelper.common.random_string_generator(12, "arcREST") 'cESaTTEacTES'
-
arcresthelper.common.
trace
()[source]¶ Determine information about where an error was thrown.
Returns: line number, filename, error message Return type: tuple
arcresthelper.featureservicetools module¶
-
class
arcresthelper.featureservicetools.
featureservicetools
(securityinfo)[source]¶ Bases:
arcresthelper.securityhandlerhelper.securityhandlerhelper
-
AddFeaturesToFeatureLayer
(url, pathToFeatureClass, chunksize=0, lowerCaseFieldNames=False)[source]¶ Appends local features to a hosted feature service layer.
Parameters: - url (str) – The URL of the feature service layer.
- pathToFeatureClass (str) – The path of the feature class on disk.
- chunksize (int) – The maximum amount of features to upload at a time. Defaults to 0.
- lowerCaseFieldNames (bool) – A boolean value indicating if field names should be converted
to lowercase before uploading. Defaults to
False
.
Returns: The result from
arcrest.agol.services.FeatureLayer.addFeatures()
.Raises: ArcRestHelperError
– ifarcpy
can’t be found.Notes
If publishing to a PostgreSQL database, it is suggested to to set
lowerCaseFieldNames
toTrue
.
-
DeleteFeaturesFromFeatureLayer
(url, sql, chunksize=0)[source]¶ Removes features from a hosted feature service layer by SQL query.
Parameters: Returns: The result from
arcrest.agol.services.FeatureLayer.deleteFeatures()
.Notes
If you want to delete all features, it is suggested to use the SQL query
"1=1"
.
-
EnableEditingOnService
(url, definition=None)[source]¶ Enables editing capabilities on a feature service.
Parameters: Returns: The existing feature service definition capabilities.
Return type: When
definition
is not provided (None
), the following values are used by default:Key Value hasStaticData False
allowGeometryUpdates True
enableEditorTracking False
enableOwnershipAccessControl False
allowOthersToUpdate True
allowOthersToDelete True
capabilities "Query,Editing,Create,Update,Delete"
-
GetFeatureService
(itemId, returnURLOnly=False)[source]¶ Obtains a feature service by item ID.
Parameters: Returns: When
returnURLOnly
isTrue
, the URL of the feature service is returned.When
False
, the result fromarcrest.agol.services.FeatureService()
orarcrest.ags.services.FeatureService()
.
-
GetLayerFromFeatureService
(fs, layerName='', returnURLOnly=False)[source]¶ Obtains a layer from a feature service by feature service reference.
Parameters: - fs (FeatureService) – The feature service from which to obtain the layer.
- layerName (str) – The name of the layer. Defaults to
""
. - returnURLOnly (bool) – A boolean value to return the URL of the layer. Defaults to
False
.
Returns: When
returnURLOnly
isTrue
, the URL of the layer is returned.When
False
, the result fromarcrest.agol.services.FeatureService()
orarcrest.ags.services.FeatureService()
.
-
GetLayerFromFeatureServiceByURL
(url, layerName='', returnURLOnly=False)[source]¶ Obtains a layer from a feature service by URL reference.
Parameters: Returns: When
returnURLOnly
isTrue
, the URL of the layer is returned.When
False
, the result fromarcrest.agol.services.FeatureService()
orarcrest.ags.services.FeatureService()
.
-
QueryAllFeatures
(url, sql, out_fields='*', chunksize=1000, savePath=None)[source]¶ Performs an SQL query against a hosted feature service layer.
Parameters: - url (str) – The URL of the feature service layer.
- sql (str) – The SQL query to apply against the feature service. Those features that satisfy the query will be returned.
- out_fields (str) – A comma delimited list of field names to return.
Defaults to
"*"
, i.e., return all fields - chunksize (int) – The maximum amount of features to query at a time. Defaults to 1000.
- savePath (str) – The full path on disk where the features will be saved. Defaults to
None
.
Returns: - When
savePath
is not provided (None
), the result from - When
savePath
is provided, the result from
-
RemoveAndAddFeatures
(url, pathToFeatureClass, id_field, chunksize=1000)[source]¶ Deletes all features in a feature service and uploads features from a feature class on disk.
Parameters: Raises: ArcRestHelperError
– ifarcpy
can’t be found.
-
disableSync
(url, definition=None)[source]¶ Disables Sync capabilities for an AGOL feature service.
Parameters: Returns: The result from
arcrest.hostedservice.service.AdminFeatureService.updateDefinition()
.Return type:
-
enableSync
(url, definition=None)[source]¶ Enables Sync capability for an AGOL feature service.
Parameters: Returns: The result from
arcrest.hostedservice.service.AdminFeatureService.updateDefinition()
.Return type:
-
-
arcresthelper.featureservicetools.
trace
()[source]¶ Determines information about where an error was thrown.
Returns: line number, filename, error message Return type: tuple Examples
>>> try: ... 1/0 ... except: ... print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace())) ... Error on 'line 1234' in file 'C:\foo\baz.py' with error 'ZeroDivisionError: integer division or modulo by zero'
arcresthelper.orgtools module¶
-
class
arcresthelper.orgtools.
orgtools
(securityinfo)[source]¶ Bases:
arcresthelper.securityhandlerhelper.securityhandlerhelper
-
createGroup
(title, tags, description='', snippet='', phone='', access='org', sortField='title', sortOrder='asc', isViewOnly=False, isInvitationOnly=False, thumbnail=None)[source]¶ Creates a new group.
Parameters: - title (str) – The name of the new group, limited to 250 characters.
- tags (str) – A comma delimited list of tag names.
- description (str) – A description of the group that can be any length.
- snippet (str) – Snippet or summary of the group that has a character limit of 250 characters.
Defaults to
""
. - phone (str) – Group contact information, limited to 250 characters. Defaults to
""
. - access (str) – Sets the access level for the group. Defaults to
"org"
. - sortField (str) – Sets sort field for group items. Defaults to
"title"
. - sortOrder (str) – Sets sort order for group items. Defaults to
"asc"
. - isViewOnly (bool) – A boolean value to create a view-only group with no sharing. Defaults to
False
. - isInvitationOnly (bool) – A boolean value to not accept join requests. Defaults to
False
. - thumbnail (str) – The full pathname to the group thumbnail to upload. Defaults to
None
.
Returns: If sucessful, the result from
arcrest.manageorg._community.Community.createGroup()
.If the group already exists or there is an error,
None
is returned.Parameters Possible Values access private|org|public
sortField title|owner|avgrating|numviews|created|modified
sortOrder asc|desc
-
createRole
(name, description='', privileges=None)[source]¶ Creates a new role.
Parameters: Returns: If
privileges
isNone
, the result fromarcrest.manageorg._portals.Portal.createRole()
.If
privileges
were succesfully added, the result fromarcrest.manageorg._portals.Roles.setPrivileges()
.
-
getGroupContent
(groupName, onlyInOrg=False, onlyInUser=False)[source]¶ Gets all the content from a group.
Parameters: Returns: A list of content belonging to the group.
Return type: See also
getGroupContentItems()
for retrieving only items.
-
getGroupContentItems
(groupName)[source]¶ Gets all the items owned by a group(s).
Parameters: groupName (list) – The name of the group(s) from which to get items. Returns: A list of items belonging to the group(s). Return type: list Notes
If you want to get items from a single group,
groupName
can be passed as astr
.See also
getGroupContent()
for retrieving all content, not just items.
-
getThumbnailForItem
(itemId, fileName, filePath)[source]¶ Gets an item’s thumbnail and saves it to disk.
Parameters: Returns: The result from
arcrest.manageorg._content.UserItem.saveThumbnail()
Return type:
Share already published items with a group(s).
Parameters: Notes
If you want to share with a single group,
shareToGroupName
can be passed as astr
.
-
-
arcresthelper.orgtools.
trace
()[source]¶ Determines information about where an error was thrown.
Returns: line number, filename, error message Return type: tuple Examples
>>> try: ... 1/0 ... except: ... print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace())) ... Error on 'line 1234' in file 'C:\foo\baz.py' with error 'ZeroDivisionError: integer division or modulo by zero'
arcresthelper.portalautomation module¶
-
class
arcresthelper.portalautomation.
portalautomation
(securityinfo)[source]¶ Bases:
arcresthelper.securityhandlerhelper.securityhandlerhelper
-
createGroups
(configFiles, dateTimeFormat=None)[source]¶ Parses a JSON configuration file to create groups.
Parameters: - configFiles (list) – A list of JSON files on disk containing configuration data for creating groups.
- dateTimeFormat (str) – A valid date formatting directive, as understood
by
datetime.datetime.strftime()
. Defaults toNone
, i.e.,'%Y-%m-%d %H:%M'
.
-
createRoles
(configFiles, dateTimeFormat=None)[source]¶ Parses a JSON configuration file to create roles.
Parameters: - configFiles (list) – A list of JSON files on disk containing configuration data for creating roles.
- dateTimeFormat (str) – A valid date formatting directive, as understood
by
datetime.datetime.strftime()
. Defaults toNone
, i.e.,'%Y-%m-%d %H:%M'
.
-
publishfromconfig
(configFiles, combinedApp=None, dateTimeFormat=None)[source]¶ Parses a JSON configuration file to publish data.
Parameters: - configFiles (list) – A list of JSON files on disk containing configuration data for publishing.
- combinedApp (str) – A JSON file on disk containing configuration data
for app publishing. Defaults to
None
. - dateTimeFormat (str) – A valid date formatting directive, as understood
by
datetime.datetime.strftime()
. Defaults toNone
, i.e.,'%Y-%m-%d %H:%M'
.
-
stageContent
(configFiles, dateTimeFormat=None)[source]¶ Parses a JSON configuration file to stage content.
Parameters: - configFiles (list) – A list of JSON files on disk containing configuration data for staging content.
- dateTimeFormat (str) – A valid date formatting directive, as understood
by
datetime.datetime.strftime()
. Defaults toNone
, i.e.,'%Y-%m-%d %H:%M'
.
-
-
arcresthelper.portalautomation.
trace
()[source]¶ Determines information about where an error was thrown.
Returns: line number, filename, error message Return type: tuple Examples
>>> try: ... 1/0 ... except: ... print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace())) ... Error on 'line 1234' in file 'C:\foo\baz.py' with error 'ZeroDivisionError: integer division or modulo by zero'
arcresthelper.publishingtools module¶
-
class
arcresthelper.publishingtools.
publishingtools
(securityinfo)[source]¶ Bases:
arcresthelper.securityhandlerhelper.securityhandlerhelper
-
folderExist
(name, folders)[source]¶ Determines if a folder exists, case insensitively.
Parameters: Returns: True
if the folder exists in the list,False
otherwise.Return type:
-
getItem
(userContent, title=None, name=None, itemType=None)[source]¶ Gets an item by a combination of title, name, and type.
Parameters: Returns: The item’s ID. If the item does not exist,
None
.Return type: Raises: AttributeError
– If bothtitle
andname
are not specified (None
).See also
-
getItemID
(userContent, title=None, name=None, itemType=None)[source]¶ Gets the ID of an item by a combination of title, name, and type.
Parameters: Returns: The item’s ID. If the item does not exist,
None
.Return type: Raises: AttributeError
– If bothtitle
andname
are not specified (None
).See also
-
publishApp
(app_info, map_info=None, fsInfo=None)[source]¶ Publishes apps to AGOL/Portal
Parameters: Returns: A dictionary of results objects.
Return type:
-
publishCombinedWebMap
(maps_info, webmaps)[source]¶ Publishes a combination of web maps.
Parameters: maps_info (list) – A list of JSON configuration combined web maps to publish. Returns: A list of results from arcrest.manageorg._content.UserItem.updateItem()
.Return type: list
-
publishFeatureCollections
(configs)[source]¶ Publishes feature collections to a feature service.
Parameters: configs (list) – A list of JSON configuration feature service details to publish. Returns: A dictionary of results objects. Return type: dict
-
publishFsFromMXD
(fs_config)[source]¶ Publishes the layers in a MXD to a feauture service.
Parameters: fs_config (list) – A list of JSON configuration feature service details to publish. Returns: A dictionary of results objects. Return type: dict
-
publishItems
(items_info)[source]¶ Publishes a list of items.
Parameters: items_info (list) – A list of JSON configuration items to publish. Returns: A list of results from arcrest.manageorg._content.User.addItem()
.Return type: list
-
-
arcresthelper.publishingtools.
trace
()[source]¶ Determines information about where an error was thrown.
Returns: line number, filename, error message Return type: tuple Examples
>>> try: ... 1/0 ... except: ... print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace())) ... Error on 'line 1234' in file 'C:\foo\baz.py' with error 'ZeroDivisionError: integer division or modulo by zero'
arcresthelper.resettools module¶
-
class
arcresthelper.resettools.
resetTools
(securityinfo)[source]¶ Bases:
arcresthelper.securityhandlerhelper.securityhandlerhelper
-
arcresthelper.resettools.
trace
()[source]¶ Determines information about where an error was thrown.
Returns: line number, filename, error message Return type: tuple Examples
>>> try: ... 1/0 ... except: ... print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace())) ... Error on 'line 1234' in file 'C:\foo\baz.py' with error 'ZeroDivisionError: integer division or modulo by zero'
arcresthelper.securityhandlerhelper module¶
-
arcresthelper.securityhandlerhelper.
lineno
()[source]¶ Returns the current line number in our program.
-
class
arcresthelper.securityhandlerhelper.
securityhandlerhelper
(securityinfo)[source]¶ Bases:
object
A number of different security handlers are suppoted by ArcGIS; this function simplifies the creation of the handlers.
Parameters: securityinfo (dict) – A dict
with the type of handler and information to be created.Key Description Required? security_type security type used to connect See Values * username username for log in LDAP|NTLM
**password password for log in LDAP|NTLM
**proxy_url url for proxy server Optional proxy_port port for proxy server Optional token_url url for token server Optional referer_url url for referer Optional certificatefile PKI
keyfile PKI
client_id OAuth
secret_id OAuth
* Values: ArcGIS|Portal|LDAP|NTLM|PKI|OAuth
(defaults toPortal
)** Also required for ArcGIS|Portal
unless using anonymous loginsExamples
>>> securityinfo = {'username' : 'secret', 'password' : 'really_secret'} >>> shh = arcresthelper.securityhandlerhelper.securityhandlerhelper(securityinfo) >>> print(shh._org_url) http://myorg.maps.arcgis.com
-
dispose
()[source]¶ Disposes the
securityhandlerhelper
object.
-
securityhandler
¶ Returns: The security handler object. Return type: securityhandlerhelper
-
-
arcresthelper.securityhandlerhelper.
trace
()[source]¶ Determines information about where an error was thrown.
Returns: line number, filename, error message Return type: tuple Examples
>>> try: ... 1/0 ... except: ... print("Error on '{}'\nin file '{}'\nwith error '{}'".format(*trace())) ... Error on 'line 1234' in file 'C:\foo\baz.py' with error 'ZeroDivisionError: integer division or modulo by zero'