def move_to_path(path, new_path): """ Move a file to a new path, optionally give unique filename Return (ok, new_path) """ ok = True overwrite = cfg.overwrite_files() if overwrite and os.path.exists(new_path): try: os.remove(new_path) except: overwrite = False if not overwrite: new_path = get_unique_filename(new_path) if new_path: logging.debug("Moving. Old path:%s new path:%s overwrite?:%s", path, new_path, overwrite) try: # First try cheap rename renamer(path, new_path) except: # Cannot rename, try copying try: if not os.path.exists(os.path.dirname(new_path)): create_dirs(os.path.dirname(new_path)) shutil.copyfile(path, new_path) os.remove(path) except: if not (cfg.marker_file() and cfg.marker_file() in path): logging.error(Ta('Failed moving %s to %s'), path, new_path) logging.info("Traceback: ", exc_info = True) ok = False return ok, new_path
def move_to_path(path, new_path): """ Move a file to a new path, optionally give unique filename Return (ok, new_path) """ ok = True overwrite = cfg.overwrite_files() new_path = os.path.abspath(new_path) if overwrite and os.path.exists(new_path): try: os.remove(new_path) except: overwrite = False if not overwrite: new_path = get_unique_filename(new_path) if new_path: logging.debug("Moving. Old path:%s new path:%s overwrite?:%s", path, new_path, overwrite) try: # First try cheap rename renamer(path, new_path) except: # Cannot rename, try copying try: if not os.path.exists(os.path.dirname(new_path)): create_dirs(os.path.dirname(new_path)) shutil.copyfile(path, new_path) os.remove(path) except: if not (cfg.marker_file() and cfg.marker_file() in path): logging.error(T('Failed moving %s to %s'), clip_path(path), clip_path(new_path)) logging.info("Traceback: ", exc_info=True) ok = False return ok, new_path
def move_to_path(path, new_path): """ Move a file to a new path, optionally give unique filename Return (ok, new_path) """ ok = True overwrite = cfg.overwrite_files() new_path = os.path.abspath(new_path) if overwrite and os.path.exists(new_path): try: os.remove(new_path) except: overwrite = False if not overwrite: new_path = get_unique_filename(new_path) if new_path: logging.debug("Moving. Old path: %s New path: %s Overwrite: %s", path, new_path, overwrite) try: # First try cheap rename renamer(path, new_path) except: # Cannot rename, try copying logging.debug("File could not be renamed, trying copying: %s", path) try: if not os.path.exists(os.path.dirname(new_path)): create_dirs(os.path.dirname(new_path)) shutil.copyfile(path, new_path) os.remove(path) except: # Check if the old-file actually exists (possible delete-delays) if not os.path.exists(path): logging.debug("File not moved, original path gone: %s", path) return True, None if not (cfg.marker_file() and cfg.marker_file() in path): logging.error(T('Failed moving %s to %s'), clip_path(path), clip_path(new_path)) logging.info("Traceback: ", exc_info=True) ok = False return ok, new_path
def set_marker(folder): """ Set marker file and return name """ name = cfg.marker_file() if name: path = os.path.join(folder, name) logging.debug('Create marker file %s', path) try: fp = open(path, 'w') fp.close() except: logging.info('Cannot create marker file %s', path) logging.info("Traceback: ", exc_info = True) name = None return name
def move_to_path(path, new_path, unique=True): """ Move a file to a new path, optionally give unique filename """ if unique: new_path = get_unique_path(new_path, create_dir=False) if new_path: logging.debug("Moving. Old path:%s new path:%s unique?:%s", path,new_path, unique) try: # First try cheap rename renamer(path, new_path) except: # Cannot rename, try copying try: if not os.path.exists(os.path.dirname(new_path)): create_dirs(os.path.dirname(new_path)) shutil.copyfile(path, new_path) os.remove(path) except: if not (cfg.marker_file() and cfg.marker_file() in path): logging.error(Ta('Failed moving %s to %s'), path, new_path) logging.info("Traceback: ", exc_info = True) new_path = None return new_path
def set_marker(folder): """ Set marker file and return name """ name = cfg.marker_file() if name: path = os.path.join(folder, name) logging.debug("Create marker file %s", path) try: fp = open(path, "w") fp.close() except: logging.info("Cannot create marker file %s", path) logging.info("Traceback: ", exc_info=True) name = None return name