<commit_before>require 'yaml'

module Shipmate

  class AppImporter

    attr_reader :import_dir, :apps_dir

    def initialize(import_dir, apps_dir)
      @import_dir = import_dir
      @apps_dir = apps_dir

      FileUtils.mkdir_p(@import_dir)
      FileUtils.mkdir_p(@apps_dir)
    end

    def import_app(ipa_file)
      plist_hash = parse_ipa_plist(ipa_file)
      app_name = plist_hash["CFBundleDisplayName"]
      app_version = plist_hash["CFBundleVersion"]
      create_app_directory(app_name, app_version)
      move_ipa_file(ipa_file, app_name, app_version)
      write_plist_info(plist_hash, app_name, app_version)
    end

    def parse_ipa_plist(ipa_file)
      ipa_info = nil
      begin
        IPA::IPAFile.open(ipa_file) do |ipa| 
          ipa_info = ipa.info
        end
      rescue Zip::ZipError

      end
      ipa_info
    end

    def create_app_directory(app_name, app_version)
      FileUtils.mkdir_p(@apps_dir.join(app_name,app_version))<commit_msg>app importer import_apps method<commit_after>require 'yaml'
require 'ipa'
require 'pathname'

module Shipmate

  class AppImporter

    attr_reader :import_dir, :apps_dir

    def initialize(import_dir, apps_dir)
      @import_dir = import_dir.is_a?(Pathname) && import_dir || Pathname.new(import_dir)
      @apps_dir = apps_dir.is_a?(Pathname) && apps_dir || Pathname.new(apps_dir)

      FileUtils.mkdir_p(@import_dir)
      FileUtils.mkdir_p(@apps_dir)
    end

    def import_apps
      ipa_files = Dir.glob("#{@import_dir}/**/*").reject { |entry| !entry.upcase.end_with?('IPA') }
      ipa_files.each do |ipa_file|
        begin
          import_app ipa_file
        rescue
          puts "Unable to import #{ipa_file}"
        end
      end
    end

    def import_app(ipa_file)
      plist_hash = parse_ipa_plist(ipa_file)
      app_name = plist_hash["CFBundleDisplayName"]
      app_version = plist_hash["CFBundleVersion"]
      create_app_directory(app_name, app_version)
      move_ipa_file(ipa_file, app_name, app_version)
      write_plist_info(plist_hash, app_name, app_version)
    end

    def parse_ipa_plist(ipa_file)
      ipa_info = nil
      begin
        IPA::IPAFile.open(ipa_file) do |ipa| 
          ipa_info = ipa.info
        end
      rescue Zip::ZipError

      end
      ipa_info
    end

    def create_app_directory(app_name, app_version)
      FileUtils.mkdir_p(@apps_dir.join(app_name,app_version))
{'fraction_non_alphanumeric': 0.0872093023255814, 'fraction_numerical': 0.0, 'mean_word_length': 3.0830508474576273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4911036', 'n_tokens_mistral': 861, 'n_tokens_neox': 848, 'n_words': 143}