Skip to content

Instantly share code, notes, and snippets.

@ChadyG
Last active December 19, 2015 16:59
Show Gist options
  • Save ChadyG/5988138 to your computer and use it in GitHub Desktop.
Save ChadyG/5988138 to your computer and use it in GitHub Desktop.
Qt Pri file generator, pass in a folder and this will generate a pri file including all c(pp) and h files. Other options left to the user to fill in.
#!/usr/bin/ruby
# lol a ruby Pri generator
#
# Because who has time to add all these files?
#
module QTPriGenerator
def writePri(filename, headers, sources)
file = File.new(filename, File::CREAT|File::TRUNC|File::RDWR)
file.puts "# ----------------------------------------------------
# This file is generated by the Ruby Pri generator.
# ----------------------------------------------------\n\n"
file.puts "HEADERS += " + headers.join(" \\\n ")
file.puts "SOURCES += " + sources.join(" \\\n ")
end
def scanDir(path, skipfolders, headers, sources)
Dir.foreach(path) do |item|
next if item == '.' or item == '..'
# do work on real items
puts "looking at " + item
if File.file?(path + '/' + item)
puts "IT'S A FILE"
if item =~ /\.c(pp)?$/
sources << '$$PWD/' + path + '/' + item
end
if item =~ /\.h$/
headers << '$$PWD/' + path + '/' + item
end
elsif File.directory?(path + '/' + item)
next if skipfolders.include?(item)
puts "IT'S A DIRECTORY"
scanDir(path + '/' + item, skipfolders, headers, sources)
else
puts "I DON'T FUCKING KNOW"
end
end
end
end
# MAKE IT WORK FROM THE COMMAND-LINE!
# USAGE
# PriFromFolder.rb path prifile "folders to skip"
if __FILE__ == $0
include QTPriGenerator
path = ARGV[0] ? ARGV[0] : '.'
outfile = ARGV[1] ? ARGV[1] : 'lolapri.pri'
skipfolders = ARGV[2] ? ARGV[2].split(' ') : []
headers = []
sources = []
scanDir(path, skipfolders, headers, sources)
writePri(outfile, headers, sources)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment