Skip to content

Commit

Permalink
Worker reference
Browse files Browse the repository at this point in the history
  • Loading branch information
garanj committed Oct 11, 2018
1 parent 07594ad commit 9750c00
Show file tree
Hide file tree
Showing 71 changed files with 10,295 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -39,5 +39,6 @@ backends/lib_dev
docs/_build

# Jekyll documentation
**/_site
# Generate _site locally now owing to custom plugins
# **/_site
**/.sass-cache
123 changes: 123 additions & 0 deletions docs/_plugins/crmint-workers.rb
@@ -0,0 +1,123 @@
module Workers
class Generator < Jekyll::Generator
WORKER_PATH = "../backends/core/workers.py"

def generate(site)
workers = get_worker_details()

worker_page = site.pages.detect {|page| page.name == 'worker_spec.md'}
worker_page.data['workers'] = workers
end

def get_worker_details()
pycode = get_file_as_string(WORKER_PATH)

available = Set[]
workers = []
worker_name = nil
worker_description = nil
in_param = false
in_available = false
params = ''

pycode.each { |line|
matches = /^\s*class\s+([^(\n]+).*:$/.match(line)
if matches
if worker_name && worker_description
worker = {
"name" => worker_name,
"description" => worker_description
}
if params.length > 0
worker["parameters"] = parse_params(params)
end
if available.include?(worker_name)
workers.push(worker)
end
worker_name = nil
worker_description = nil
params = ''
end
worker_name = matches[1]
elsif worker_name
if !worker_description
matches = /^\s*\"\"\"(.*)\"\"\".*/.match(line)
if matches
worker_description = matches[1]
end
elsif worker_description && !in_param
matches = /^\s*PARAMS\s=\s(.*)/.match(line)
if matches
in_param = true
params += matches[1]
end
elsif in_param
matches = /^\s*$/.match(line)
if matches
in_param = false
else
params += line
end
end
elsif in_available
matches = /^\s*\)\s*$/.match(line)
if matches
in_available = false
else
matches = /^\s*'(.*)',\s*$/.match(line)
if matches
available.add(matches[1])
end
end
else
if line =~ /^\s*AVAILABLE\s*=\s*.*/
in_available = true
end
end
}

if worker_name && worker_description
worker = {
"name" => worker_name,
"description" => worker_description
}
if params.length > 0
worker["parameters"] = parse_params(params)
end
workers.push(worker)
end
return workers.sort_by { |h| h["name"] }
end

def parse_params(params)
x = []
r = params.gsub(/\n\s*/, '')
r = r.gsub(/^\[\s+\(/, '')
r = r.gsub(/\)\s*,\s*\]\s*$/, '')
p = r.split("),(")
if p.length > 0
p.each { |c|
rows = CSV.parse(c, {:quote_char => "\01", :converters => [
-> field, info {
field = field.strip
if /^'(.*)'$/.match(field)
field[1..-2]
elsif /^\('(.*)'\)$/.match(field)
field = field[2..-4]
field.gsub(/''/, "")
else
field
end
}
]})
x.push(rows[0])
}
end
return x
end

def get_file_as_string(filename)
return File.readlines(filename)
end
end
end

0 comments on commit 9750c00

Please sign in to comment.