Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
10,295 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.