# treevisitor require 'treevisitor/tree_node_visitor' require 'treevisitor/dir_tree_walker' require 'treevisitor/visitors/callback_tree_node_visitor2' # ralbum require 'ralbum/catalog' require 'ralbum/photo_tree/photo_tree_item' require 'ralbum/photo_tree/photo_tree_node' class JalbumPhotoTreeBuilder def run( phototree_dirname ) photoTree = build_photo_tree_from_directory( phototree_dirname ) # read_meta_info_old_format( photoTree ) # update_meta_info( photoTree ) photoTree end # ------------------------------------------------------------------------------ # # build photo tree senza metainfo # def build_photo_tree_from_directory( jalbum_dirname ) ralbum_verbose( 1, "phototree - building phototree from #{jalbum_dirname}" ) @photo_tree_dirname = jalbum_dirname dtw = DirTreeWalker.new( jalbum_dirname ) # TODO: ignorare tutti le directory che iniziano per "." questa deve essere un'opzione di DirTreeWalker dtw.add_ignore_dir( ".svn" ) dtw.add_ignore_dir( ".csv" ) dtw.add_ignore_dir( ".git" ) dtw.add_ignore_dir( Catalog::DEFAULT_CATALOG_DIRNAME ) dtw.add_ignore_pattern(".jalbum") visitor = CallbackTreeNodeVisitor2.new(self) dtw.run( visitor ).root # return a photo_tree end def on_enter_tree_node(pathname, parent) # puts "_on_enter_tree_node #{pathname}" if parent.nil? photo_tree_node = PhotoTreeNode.new( File.basename(pathname) , parent ) photo_tree_node.prefix_path= File.dirname( pathname ) + File::SEPARATOR else photo_tree_node = PhotoTreeNode.new( File.basename(pathname), parent ) end albumfiles_path = File.join(pathname, "albumfiles.txt") if File.exist?( albumfiles_path ) create_leaf_node_from_album_file( photo_tree_node, albumfiles_path ) end photo_tree_node end def on_visit_leaf_node( src_leaf_node, parent_node ) end def create_leaf_node_from_album_file(parent, albumfiles_path) # puts "-----------------" File.open(albumfiles_path).each_line do |line| i = line.index('#') if i next if i == 0 line = [0..i-1].strip end next if line.length == 0 image_filename = line.split("\t")[1] next if image_filename.nil? image_filename.chomp! # puts image_filename PhotoTreeItem.new(image_filename, parent ) end # puts "----------------" end end