<commit_before>class Deb < ActiveRecord::Base
  belongs_to :metapackage
  belongs_to :distribution
  belongs_to :derivative

  require 'utils'

  # command for adding keys
  APT_KEY_COMMAND = "apt-key adv --recv-keys --keyserver"
  KEYSERVER = "wwwkeys.eu.pgp.net"
  # communtu repository
  COMMUNTU_REPO = "http://packages.communtu.de"
  COMMUNTU_KEY = "<KEY>"
  # command for uploading debs to repository
  REPREPRO = "reprepro -v -b #{RAILS_ROOT} --outdir public/debs --confdir debs --logdir log --dbdir debs/db --listdir debs/list"

  def codename
    Metapackage.codename(self.distribution,self.derivative,self.license_type,self.security_type)
  end

  def name
    self.metapackage.debian_name
  end
  
  # generate debian package
  def generate
    # create a lock in order to avoid concurrent debianizations
    safe_system "dotlockfile #{RAILS_ROOT}/debs/lock"
    begin
      meta = self.metapackage
      dist = self.distribution
      der = self.derivative
      lic = self.license_type
      sec = self.security_type
      name = self.name
      codename = self.codename
      mlic = meta.compute_license_type
      msec = meta.compute_security_type
      version = "#{meta.version}-#{self.codename}1"
      f=File.open("#{RAILS_ROOT}/log/debianize.log","a")
      f.puts
      f.puts
      f.puts "++++++++++++++++++++++ Processing version #{name}-#{version}"
      f.puts
      # compute list of packages contained in metapackage (todo: delegate this to an own method, preferably using more :includes)
      mcs = Metacontent.find(:all,:conditions => 
             ["metapackage_id = ? and metacontents_distrs.distribution_id = ? and metacontents_derivatives.derivative_id = ?",
              meta.id,dist.id,der.id],:include => [:metacontents_distrs, :metacontents_derivatives])
      packages = mcs.map{|mc| mc.base_package}.select{|p| p.is_present(dist,lic,sec)}.map{|p| p.debian_name}
      f.puts "Included packages:"
      f.puts packages.join(", ")
      f.close
      
      begin
        # build metapackage
        debfile = Metapackage.makedeb(name,version,packages,meta.description,codename,Derivative.find(:first),[])
  
        # make name of .deb unique by adding the codename
        # newfile = debfile.gsub("_all.deb","~"+codename+"_all.deb")
        # safe_system "mv #{debfile} #{newfile}"
        newfile = debfile

        # what license types and security types are actually used in the bundle?
        # use this info to determine the component
        component = Metapackage.components[[lic,mlic].min][[sec,msec].min]
        # upload metapackage
        # todo: make name of .deb unique
        puts "Uploading #{newfile}"
        safe_system "#{REPREPRO} -C #{component} includedeb #{codename} #{newfile} >> #{RAILS_ROOT}/log/debianize.log 2>&1"
        # remove package files, but not folder
        safe_system "rm #{RAILS_ROOT}/debs/#{name}/#{name}* >/dev/null 2>&1 || true"
        # mark this deb as susccessfully generated
        # self.generated = true
        self.errmsg = nil
        self.log = IO.popen("tail -n80 #{RAILS_ROOT}/log/debianize.log").read
        self.save
        # was this the last deb to be generated for the bundle? Then mark bundle as updated
        if Deb.find(:first,:conditions => ["metapackage_id = ? and generated = ?",meta.id,false]).nil?
          meta.modified = false
          meta.debianizing = false
          meta.deb_error = false
          meta.save
        end
      rescue StandardError => err
        self.generated = false
        self.errmsg = err
        self.log = IO.popen("tail -n80 #{RAILS_ROOT}/log/debianize.log").read
        self.save
        meta.deb_error = true
        meta.save
      end
    rescue 
      self.generated = false
      self.errmsg = "unknown"
      self.log = IO.popen("tail -n80 #{RAILS_ROOT}/log/debianize.log").read
      self.save
      meta.deb_error = true
      meta.save
      f=File.open("#{RAILS_ROOT}/log/debianize.log","a")
      f.puts
      f.puts "Debianizing #{name} failed! (id = #{id})"
      f.puts
      f.close<commit_msg>fixed bug caused by commented out code<commit_after>class Deb < ActiveRecord::Base
  belongs_to :metapackage
  belongs_to :distribution
  belongs_to :derivative

  require 'utils'

  # command for adding keys
  APT_KEY_COMMAND = "apt-key adv --recv-keys --keyserver"
  KEYSERVER = "wwwkeys.eu.pgp.net"
  # communtu repository
  COMMUNTU_REPO = "http://packages.communtu.de"
  COMMUNTU_KEY = "<KEY>"
  # command for uploading debs to repository
  REPREPRO = "reprepro -v -b #{RAILS_ROOT} --outdir public/debs --confdir debs --logdir log --dbdir debs/db --listdir debs/list"

  def codename
    Metapackage.codename(self.distribution,self.derivative,self.license_type,self.security_type)
  end

  def name
    self.metapackage.debian_name
  end
  
  # generate debian package
  def generate
    # create a lock in order to avoid concurrent debianizations
    safe_system "dotlockfile #{RAILS_ROOT}/debs/lock"
    begin
      meta = self.metapackage
      dist = self.distribution
      der = self.derivative
      lic = self.license_type
      sec = self.security_type
      name = self.name
      codename = self.codename
      mlic = meta.compute_license_type
      msec = meta.compute_security_type
      version = "#{meta.version}-#{self.codename}1"
      f=File.open("#{RAILS_ROOT}/log/debianize.log","a")
      f.puts
      f.puts
      f.puts "++++++++++++++++++++++ Processing version #{name}-#{version}"
      f.puts
      # compute list of packages contained in metapackage (todo: delegate this to an own method, preferably using more :includes)
      mcs = Metacontent.find(:all,:conditions => 
             ["metapackage_id = ? and metacontents_distrs.distribution_id = ? and metacontents_derivatives.derivative_id = ?",
              meta.id,dist.id,der.id],:include => [:metacontents_distrs, :metacontents_derivatives])
      packages = mcs.map{|mc| mc.base_package}.select{|p| p.is_present(dist,lic,sec)}.map{|p| p.debian_name}
      f.puts "Included packages:"
      f.puts packages.join(", ")
      f.close
      
      begin
        # build metapackage
        debfile = Metapackage.makedeb(name,version,packages,meta.description,codename,Derivative.find(:first),[])
  
        # make name of .deb unique by adding the codename
        # newfile = debfile.gsub("_all.deb","~"+codename+"_all.deb")
        # safe_system "mv #{debfile} #{newfile}"
        newfile = debfile

        # what license types and security types are actually used in the bundle?
        # use this info to determine the component
        component = Metapackage.components[[lic,mlic].min][[sec,msec].min]
        # upload metapackage
        # todo: make name of .deb unique
        puts "Uploading #{newfile}"
        safe_system "#{REPREPRO} -C #{component} includedeb #{codename} #{newfile} >> #{RAILS_ROOT}/log/debianize.log 2>&1"
        # remove package files, but not folder
        safe_system "rm #{RAILS_ROOT}/debs/#{name}/#{name}* >/dev/null 2>&1 || true"
        # mark this deb as susccessfully generated
        self.generated = true
        self.errmsg = nil
        self.log = IO.popen("tail -n80 #{RAILS_ROOT}/log/debianize.log").read
        self.save
        # was this the last deb to be generated for the bundle? Then mark bundle as updated
        if Deb.find(:first,:conditions => ["metapackage_id = ? and generated = ?",meta.id,false]).nil?
          meta.modified = false
          meta.debianizing = false
          meta.deb_error = false
          meta.save
        end
      rescue StandardError => err
        self.generated = false
        self.errmsg = err
        self.log = IO.popen("tail -n80 #{RAILS_ROOT}/log/debianize.log").read
        self.save
        meta.deb_error = true
        meta.save
      end
    rescue 
      self.generated = false
      self.errmsg = "unknown"
      self.log = IO.popen("tail -n80 #{RAILS_ROOT}/log/debianize.log").read
      self.save
      meta.deb_error = true
      meta.save
      f=File.open("#{RAILS_ROOT}/log/debianize.log","a")
      f.puts
      f.puts "Debianizing #{name} failed! (id = #{id})"
      f.puts
      f.close
{'fraction_non_alphanumeric': 0.12143119715721112, 'fraction_numerical': 0.00269574807008945, 'mean_word_length': 2.6865401987353206, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '183944', 'n_tokens_mistral': 2704, 'n_tokens_neox': 2589, 'n_words': 607}