Skip to content

Commit

Permalink
Renamed references to Sync to Overwrite consistent with rename of scr…
Browse files Browse the repository at this point in the history
…ipt and config file
  • Loading branch information
chris-fox committed Apr 20, 2016
1 parent 4791b82 commit 2272faa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion overwrite_hosted_features.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ maxAllowableOffset: 100
nameMapping: WidthHeightAlerts,WidthHeightAlerts;WorkZones WidthHeight,WorkZonesWidthHeight;WorkZones,WorkZones;Alerts Severe,AlertsSevere;Alerts NonSevere,AlertsNonSevere;Windspeed,Windspeed;Cameras,WebCameras;Closed Roads,RoadConditionsClosed;RoadConditions,RoadConditionsOpen

[Log File]
path: D:\Data\SyncLog.txt
path: D:\Data\OverwriteLog.txt
isVerbose: false
24 changes: 12 additions & 12 deletions overwrite_hosted_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _py3(self):
textwriter.write('--{}--\r\n\r\n'.format(boundary))
self.form_data = buf.getvalue()

class _SyncFeatureCollection(object):
class _OverwriteHostedFeatures(object):

def __init__(self):
self._config_options = {}
Expand All @@ -158,12 +158,12 @@ def _read_config(self, config_file):
Keyword arguments:
config_file - Path to the configuration file.
If None it will look for a file called SyncFeatureCollection.cfg in the same directory as the executing script.
If None it will look for a file called overwrite_hosted_features.cfg in the same directory as the executing script.
"""

config = configparser.ConfigParser()
if config_file is None:
config_file = os.path.join(os.path.dirname(__file__), 'SyncFeatureCollection.cfg')
config_file = os.path.join(os.path.dirname(__file__), 'overwrite_hosted_features.cfg')
config.readfp(open(config_file))

log_path = _validate_input(config, 'Log File', 'path', 'path', False)
Expand Down Expand Up @@ -218,13 +218,13 @@ def _start_logging(self):
if is_file:
path = log_path
else:
path = os.path.join(logfile_location, "SyncLog.txt")
path = os.path.join(logfile_location, "OverwriteLog.txt")

log_path = path
log = open(path, "a")
date = self._config_options['start_time'].strftime('%Y-%m-%d %H:%M:%S')
log.write("----------------------------" + "\n")
log.write("Begin Data Sync: " + str(date) + "\n")
log.write("Begin Data Overwrite: " + str(date) + "\n")
log.close()

def _log_message(self, my_message, is_error=False):
Expand Down Expand Up @@ -381,11 +381,11 @@ def _find_and_delete_gdb(self, gdb_name):
Keyword arguments:
gdb_name - the name of the geodatabase"""
url = '{0}sharing/rest/search'.format(self._config_options['org_url'])
request_parameters = {'f' : 'json', 'q' : 'SyncFeatureCollection owner:{0} type:"File Geodatabase"'.format(self._config_options['username']),
request_parameters = {'f' : 'json', 'q' : 'OverwriteHostedFeatures owner:{0} type:"File Geodatabase"'.format(self._config_options['username']),
'token' : self._config_options['token']}
response = self._url_request(url, request_parameters, error_text='Failed to upload file geodatabase')
results = response['results']
existing_gdb = next((r['id'] for r in results if r['name'] == gdb_name and "SyncFeatureCollection" in r['tags']), None)
existing_gdb = next((r['id'] for r in results if r['name'] == gdb_name and "OverwriteHostedFeatures" in r['tags']), None)
if existing_gdb is None:
self._log_message("Failed to find file geodatabase on the portal named {0}: {1}".format(gdb_name, response))
return
Expand All @@ -407,7 +407,7 @@ def _upload_fgdb(self):
self._log_message("Uploading file geodatabase {}".format(fgdb))

try:
request_parameters = {'f' : 'json', 'token' : self._config_options['token'], 'tags' : 'SyncFeatureCollection',
request_parameters = {'f' : 'json', 'token' : self._config_options['token'], 'tags' : 'OverwriteHostedFeatures',
'itemType' : 'file', 'async' : False,
'type' : 'File Geodatabase', 'descriptipion' : 'GDB',
'filename' : os.path.basename(fgdb), 'title' : self._config_options['basename']}
Expand Down Expand Up @@ -534,7 +534,7 @@ def _remove_temp_content(self):
self._log_message("Failed to delete file geodatabase: {0}".format(response))

def run(self, config_file):
"""Run the feature collection sync."""
"""Overwrite hosted features."""
try:
self._read_config(config_file)
self._config_options['token'] = self._get_token()
Expand Down Expand Up @@ -582,9 +582,9 @@ def _validate_input(config, group, name, variable_type, required):
return None

def run(config_file=None):
"""Run the feature collection sync."""
sync = _SyncFeatureCollection()
sync.run(config_file)
"""Overwrite hosted features."""
overwrite = _OverwriteHostedFeatures()
overwrite.run(config_file)

if __name__ == "__main__":
CONFIG_FILE = None
Expand Down

0 comments on commit 2272faa

Please sign in to comment.