Created
November 14, 2012 00:04
-
-
Save deadbits/4069274 to your computer and use it in GitHub Desktop.
traverse and populate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# part of the MinusOne project. | |
# methods from minus/lib/environment.rb | |
# traverse a given directory tree to determine | |
# if a path is a file or a directory. | |
# if the file extension of any file matches the | |
# specified language, add that file to the scan queue. | |
def determine_extension | |
puts "[~] determining file extension..." | |
case $options[:language].downcase | |
when "python" | |
ext = ".py" | |
when "ruby" | |
ext = ".rb" | |
when "c" | |
ext = ".c", ".h" | |
when "php" | |
ext = ".php" | |
else | |
puts "[error] #{options[:language]} is not supported." | |
puts " accepted languages: python ruby php c" | |
exit | |
end | |
load_files(ext) | |
end | |
def load_files(extension) | |
puts "[~] adding source files to queue..." | |
app_path = $options[:path] | |
file_queue = [] | |
count = 0 | |
raise ArgumentError unless File.directory?(app_path) | |
Dir.foreach(app_path) do |entry| | |
if File.directory?(entry) | |
dir = Dir.open(entry) | |
dir.entries.each do |f| | |
path = File.join(app_path, f) | |
if File.extname(path) == extension and not File.directory?(path) | |
file_queue << File.join(path) | |
count = count + 1 | |
else | |
next | |
end | |
end | |
elsif File.extname(entry) == extension | |
path = File.join(app_path, entry) | |
file_queue << File.join(path) | |
count = count + 1 | |
end | |
end | |
puts "[+] #{count} files added to queue." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment