Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def update_content(self, relative_path):
if self.update_document_action(os.path.join(self.path, relative_path)):
self.updated[relative_path] = 0
logger.info('Updating remote content: {0}'.format(relative_path))
def rm(file_names, **kwargs):
"""
Disassociates local doc(s) from Lingotek Cloud and removes them from the project by cancelling them. If the remote copy should be deleted, use the -r flag.
"""
try:
action = rm_action.RmAction(os.getcwd())
init_logger(action.path)
if not file_names and not (('all' in kwargs and kwargs['all']) or ('local' in kwargs and kwargs['local'])):
logger.info("Usage: ltk rm [OPTIONS] FILE_NAMES...")
return
if len(file_names) > 0:
file_names = remove_powershell_formatting(file_names)
action.rm_action(file_names, **kwargs)
except (UninitializedError, ResourceNotFound, RequestFailedError) as e:
print_log(e)
logger.error(e)
return
def delete_local(self, title, document_id, message=None):
# print('local delete:', title, document_id)
if not title:
title = document_id
message = '{0} has been deleted locally.'.format(title) if not message else message
try:
file_name = self.doc_manager.get_doc_by_prop('id', document_id)['file_name']
except TypeError:
logger.info('Document to remove not found in the local database')
return
try:
os.remove(os.path.join(self.path, file_name))
logger.info(message)
except OSError:
logger.info('Something went wrong trying to delete the local file.')
def delete_local(self, title, document_id, message=None):
# print('local delete:', title, document_id)
if not title:
title = document_id
message = '{0} has been deleted locally'.format(title) if not message else message
try:
file_name = self.doc_manager.get_doc_by_prop('id', document_id)['file_name']
except TypeError:
logger.info('Document to remove not found in the local database')
return
try:
os.remove(os.path.join(self.path, file_name))
logger.info(message)
except OSError:
logger.info('Something went wrong trying to delete the local file')
def delete_local(self, title, document_id, message=None):
# print('local delete:', title, document_id)
if not title:
title = document_id
message = '{0} has been deleted locally'.format(title) if not message else message
try:
file_name = self.doc_manager.get_doc_by_prop('id', document_id)['file_name']
except TypeError:
logger.info('Document to remove not found in the local database')
return
try:
os.remove(os.path.join(self.path, file_name))
logger.info(message)
except OSError:
logger.info('Something went wrong trying to delete the local file')
def delete_local_translation(self, file_name):
try:
if not file_name:
logger.info('Please provide a valid file name')
logger.info('{0} (local translation) has been deleted'.format(self.get_relative_path(file_name)))
os.remove(os.path.join(self.path, file_name))
except OSError:
logger.info('Something went wrong trying to download the local translation')
if display_type == 'community':
input_prompt = 'Which community should this project belong to? '
elif display_type == 'project':
input_prompt = 'Which existing project should be used? '
else:
raise exceptions.ResourceNotFound("Cannot display info asked for")
mapper = choice_mapper(info)
choice = 'none-chosen'
while choice not in mapper:
choice = input(input_prompt)
try:
choice = int(choice)
except ValueError:
print("That's not a valid option!")
for v in mapper[choice]:
logger.info('Selected "{0}" {1}.'.format(mapper[choice][v], display_type))
return v, mapper[choice][v]
# remove entry for local doc -- possibly delete local file too?
if locals_to_delete:
for curr_id in locals_to_delete:
removed_doc = self.doc_manager.get_doc_by_prop('id', curr_id)
if not removed_doc:
continue
removed_title = removed_doc['name']
# todo somehow this line^ doc is null... after delete files remotely, then delete locally
if force:
self.delete_local(removed_title, curr_id)
self.doc_manager.remove_element(curr_id)
logger.info('Removing association for document {0}'.format(removed_title))
else:
logger.info('Local documents already up-to-date with Lingotek Cloud')
return
logger.info('Cleaned up associations between local documents and Lingotek Cloud')
except Exception as e:
log_error(self.error_file_name, e)
if 'string indices must be integers' in str(e) or 'Expecting value: line 1 column 1' in str(e):
logger.error("Error connecting to Lingotek's TMS")
else:
logger.error("Error on clean: "+str(e))