def get_user_copy_dest(category): try: if ModelSetting.get_bool('use_user_setting'): rule_list = ModelSetting.get_list('user_copy_dest_rules', '\n') for rule in rule_list: orig, converted = rule.split('|') if orig.endswith('*'): orig = orig.replace('*', '') logger.debug('orig(%s), category(%s)', orig, category) if category.startswith(orig): return converted return category except Exception as e: logger.error('Exception %s', e) logger.error(traceback.format_exc()) return None
def gclone_copy(id): try: entity = ListModelItem.get(id) if entity is None: return {'ret': False, 'data': '유효한 아이템이 없습니다'} category = LogicGSheet.get_user_copy_dest(entity.category) logger.debug('category: %s -> %s', entity.category, category) from gd_share_client.logic_user import LogicUser #logger.debug(category) my_remote = LogicUser.instance.get_my_copy_path('gsheet', category) logger.debug('my_remote(%s)', my_remote) if ModelSetting.get_bool('use_user_setting'): dest_folder = entity.title2 if entity.title2 != u'' else entity.title gcstring = 'gc:{%s}|%s/%s' % (entity.folder_id, my_remote, dest_folder) else: dest_folder = entity.category + '/' + entity.title2 if entity.title2 != u'' else entity.title gcstring = 'gc:{%s}|%s/%s' % (entity.folder_id, "gc:{}", dest_folder) tmp = ModelSetting.get('gclone_queue_list') if tmp.find(gcstring) != -1: return {'ret': True, 'data': '이미 큐에 존재합니다.'} else: LogicGclone.queue_append([gcstring]) entity.copied_time = datetime.now() # 처음 복사하는 경우만 시트정보에 카운트 갱신 if entity.copy_count == 0: wsentity = WSModelItem.get(entity.sheet_id) if wsentity is not None: wsentity.copy_count += 1 wsentity.save() entity.copy_count += 1 entity.save() return {'ret': True, 'data': '큐에 추가하였습니다.'} except Exception as e: logger.error('Exception %s', e) logger.error(traceback.format_exc()) return {'ret': False, 'data': 'Exception'}