def test_check_path_exists(): print("HBtest/test_check_path_exists()") verbose = True path = "/Users/robbert/" res = HBFun.check_path_exists(path, verbose) if res == True: print(" pass") else: print(" FAIL:", res) path = "/Users/bernard/" res = HBFun.check_path_exists(path, verbose) if res == False: print(" pass") else: print(" FAIL:", res) path = "/Users/robbert/croc_tests.py" res = HBFun.check_path_exists(path, verbose) if res == True: print(" pass") else: print(" FAIL:", res) path = "/Users/robbert/does_not_exist.py" res = HBFun.check_path_exists(path, verbose) if res == False: print(" pass") else: print(" FAIL:", res)
def add_photos(self, index, flag_new_properties_list = False, flag_redo_resize = False, flag_redo_thumbs = False, verbose = False): """ add_photos: add photos to an event 20130103/RB: started function INPUT: - index (int): index of the event in event_array. Use 'list_events' to find the correct index. - flag_new_properties_list (BOOL, False): complicated. The properties list is a csv-file with the file names and space for titles and caption for individual photos. You don't want to override it. The file is found in 'album_path + resources_dir + event_dir + 'props.csv'' - if the file does not exist, it will be made - if the file exists and the flag is False, it will not make a new one - if the file exists and the flag is True, it will make a new file, with a number appended to it (like 'props_1.csv'). THE OLD FILE WILL CONTINUE TO BE USED. You have to manually rename it to 'props.csv'. - flag_redo_resize (BOOL, False): the photos are copied from the source, resize and put in the destination folder. During this, the exif information is copied to the resized photos. - no photos found in destination: will always resize them - photos are found, flag is False: will not do anything - photos are found, flag is True: will resize the photos - flag_redo_thumbs (BOOL, False): similar to flag_redo_resize, but for the thumbnails. REMARK: This function is a convenient collection of steps. Error checking etc should be done in the respective functions. """ HBFUN.verbose("\nHBalbum/add_photos(): redo resize: " + str(flag_redo_resize), verbose) self.event_array[index].add_and_resize_photos(flag_redo_resize, verbose) self.event_array[index].add_and_resize_thumbs(flag_redo_thumbs, verbose) self.event_array[index].add_photos_to_array(verbose) if HBFUN.check_path_exists(self.album_path + self.resources_dir + self.event_array[index].event_dir) or flag_new_properties_list: self.event_array[index].make_new_properties_list(verbose) self.event_array[index].read_properties_list(verbose)
def init_new_album(album_title, album_path, default_source_path, verbose): """ init_new_album: start or restart an album 20130103/RB: started function INPUT: - album_title: title of the page (as seen on the web page) - album_path: path to where the album is located on the computer - default_source_path: the default path to the folder with the originals INTERACTION: - the album will be saved. If it already exists it will ask for confirmation before it overwrites the old album. """ HBFUN.verbose("== INIT NEW ALBUM ==", True) # make new album album = HBAL.album(album_title = album_title, album_path = album_path, default_source_path = default_source_path, verbose = verbose) # save it, if it already exists, ask for confirmation if HBFUN.check_path_exists(pickle_path): if HBFUN.ask_user_confirmation("This will overwrite the old pickle. Destroy it? y/n"): HBAL.save_album(album, pickle_path) else: HBAL.save_album(album, pickle_path)
def add_event(self, index, event_title, event_dir, event_dir_src = "", source_path = "", verbose = False): """ add_event: add an event to the album 20130103/RB: started the function INPUT: - index (int): position of the new album. Use 'list_events' to find the correct position. The newest event should have index = 0 - event_title (str): the title of the event. It usually has the format 'Some event (July 2012)' - event_dir (str): the directory name of the event on the web - event_dir_src (str, opt): if the source directory (with the original photos) has a different directory name - source_path (str, opt): is the source_path of the original photos is not the default. OUTPUT: - True: success or False: fail """ HBFUN.verbose("HBalbum/add_event(): " + str(index) + ", " + event_title + ", " + event_dir + ", " + source_path, verbose) # if no new source_path is given, use the default if source_path == "": source_path = self.default_source_path # if a new source_path is given, check for correctness else: source_path = HBFUN.check_path(source_path, verbose) if self.album_path == source_path: HBFUN.printError("album_path and source_path are the same, this is not allowed!", inspect.stack()) return False # check the event_dir event_dir = HBFUN.check_path(event_dir) # is the source event dir different? if event_dir_src == "": event_dir_src = event_dir else: event_dir_src = HBFUN.check_path(event_dir_src, verbose) # check if the source exists if HBFUN.check_path_exists(source_path + event_dir_src) == False: HBFUN.printError("The source path does not exist!", inspect.stack()) return False # check if the event already exists. If not, make it if self.check_event_exists(event_title, event_dir, verbose): ev = HBEV.event(event_title, event_dir, event_dir_src, self.album_title, self.album_path, source_path, self.pics_dir, self.thumbs_dir, self.resources_dir, self.html_dir, verbose) self.event_array.insert(index, ev) self.save_events_in_csv(verbose) return True