<commit_before>module Cifrado
  class CLI
  # @returns [Array] a list of Fog::OpenStack::File or
    # Fog::OpenStack::Directory
    #
    desc "list [CONTAINER]", "List containers and objects"
    option :list_segments, :type => :boolean
    option :decrypt_filenames, :type => :boolean
    option :display_hash, :type => :boolean
    def list(container = nil)
      client = client_instance
      list = []
      if container
        dir = client.service.directories.get container
        if dir
          Log.info "Listing objects in '#{container}'"
          files = dir.files
          files.each do |f|
            unless options[:decrypt_filenames]
              list << f.key
              puts f.key
              next
            end
            # Skip segments
            next if f.key =~ /\/segments\/\d+\.\d{2}\/\d+\/\d+/ and \
                    not options[:list_segments]

            metadata = f.metadata
            if metadata[:encrypted_name] 
              fname = decrypt_filename metadata[:encrypted_name], 
                                       @config[:password] + @config[:secure_random]
              puts "#{fname.ljust(55)} #{set_color("[encrypted]",:red, :bold)}"
              puts "  hash: #{f.key}" if options[:display_hash]
            else
              puts f.key.ljust(55)
            end
            list << f.key
          end 
          list
        else
          raise "Container '#{container}' not found"
        end
      else
        Log.info "Listing containers"
        directories = client.service.directories
        directories.each { |d| puts d.key }
        directories
      end
    end
  end
end


<commit_msg>code cleanup and fixes for the list 'command'<commit_after>module Cifrado
  class CLI
  # @returns [Array] a list of Fog::OpenStack::File or
    # Fog::OpenStack::Directory
    #
    desc "list [CONTAINER]", "List containers and objects"
    option :list_segments, :type => :boolean
    option :decrypt_filenames, :type => :boolean
    option :display_hash, :type => :boolean
    def list(container = nil)
      client = client_instance
      list = []
      if container
        dir = client.service.directories.get container
        if dir
          Log.info "Listing objects in '#{container}'"
          files = dir.files
          files.each do |f|
            fname = f.key
            unless options[:decrypt_filenames]
              list << fname
              Log.info fname
              next
            end
            # Skip segments
            next if fname =~ /\/segments\/\d+\.\d{2}\/\d+\/\d+/ and \
                    not options[:list_segments]

            # Raises exception if the object is a
            # manifest but there are no segments available
            begin 
              metadata = f.metadata
            rescue Fog::Storage::OpenStack::NotFound
              Log.warn "The file #{fname} is an object manifest, but there are no segments"
              Log.warn "available. I won't be able to decrypt the filename."
              Log.info fname
              list << fname
              next
            end
            if metadata[:encrypted_name] 
              fname = decrypt_filename metadata[:encrypted_name], 
                                       @config[:password] + @config[:secure_random]
              Log.info "#{fname.ljust(55)} #{set_color("[encrypted]",:red, :bold)}"
              Log.info "  hash: #{f.key}" if options[:display_hash]
            else
              Log.info fname.ljust(55)
            end
            list << fname
          end 
          list
        else
          raise "Container '#{container}' not found"
        end
      else
        Log.info "Listing containers"
        directories = client.service.directories
        directories = directories.map { |d| Log.info d.key; d.key }
        directories
      end
    end
  end
end



{'fraction_non_alphanumeric': 0.0997937080969572, 'fraction_numerical': 0.0025786487880350697, 'mean_word_length': 1.5808383233532934, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5684352', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1047, 'n_words': 295}