Skip to content

Commit

Permalink
Merge pull request #43 from CCMS-UCSD/create-or-update-readme
Browse files Browse the repository at this point in the history
Create a readme from Makefile
  • Loading branch information
benpullman authored May 28, 2020
2 parents 303081c + ab8bbc2 commit 460a964
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Makefile.deploytemplate
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ view-dependencies:
update-dependencies:
fab2 -H ${USERNAME}@proteomics2.ucsd.edu --prompt-for-login-password \
read-dependencies ${WORKFLOW_INPUT} --rewrite-string yes

#Create README
deploy-update-readme:
fab2 -H ${USERNAME}@proteomics2.ucsd.edu --prompt-for-login-password \
release-text ${WORKFLOW_INPUT}
63 changes: 61 additions & 2 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,65 @@

workflow_components = ['input.xml', 'binding.xml', 'flow.xml', 'result.xml', 'tool.xml']

@task
def release_text(c, workflow_name):
base_dir = '.'
tools = read_all_tools('..')
dependencies = output_tool_dependencies(workflow_name, base_dir)
makefile = read_makefile(base_dir)
readme = 'README.md'
previous_readme_lines = []
if os.path.isfile(readme):
with open(readme) as f:
for previous_readme_line in f:
previous_readme_lines.append(previous_readme_line)
if "CCMS_DEPLOYMENTS_HEADER_BREAK_ELEMENT_CAUTION_ANYTHING_ABOVE_WILL_BE_AUTOGENERATED" in previous_readme_line:
previous_readme_lines = []

version = makefile["WORKFLOW_VERSION"]
name = makefile.get("WORKFLOW_LABEL")
if name:
name = name[1:-1]
else:
name = workflow_name
description = makefile.get("WORKFLOW_DESCRIPTION")

update_text = "Last updated: {}.".format(makefile['LAST_UPDATED'])

dependency_text = []
seen = {}

for (dependency, dependency_version) in dependencies:

status = "N/V"
if dependency not in seen or (dependency in seen and seen[dependency] != dependency_version):
if dependency in tools:

local_version, workflow = tools[dependency]

if dependency_version == local_version:
status = "({})".format(dependency_version)
else:
status = "({}, latest is {})".format(dependency_version, local_version)

dependency_text.append("* {} {}".format(dependency, status))
else:
dependency_text.append("* {} (untracked)".format(dependency))

seen[dependency] = dependency_version

with open(readme, 'w') as w:
w.write('## {}\n\n'.format(name))
w.write('#### Version: {}\n\n'.format(version))
if description:
w.write('#### Description: \n{}\n\n'.format(description[1:-1]))
if len(dependency_text) > 0:
w.write('#### Dependencies: \n{}\n\n'.format("\n".join(dependency_text)))
w.write('_{}_\n\n'.format(update_text))
w.write('<data id=CCMS_DEPLOYMENTS_HEADER_BREAK_ELEMENT_CAUTION_ANYTHING_ABOVE_WILL_BE_AUTOGENERATED />\n\n')
for previous_readme_line in previous_readme_lines:
w.write(previous_readme_line)

@task
def read_branch(c, workflow_name):
branch_name = None
Expand All @@ -28,8 +87,8 @@ def read_makefile(workflow_name):
with open(makefile_location) as f:
for l in f:
split_line = l.rstrip().split('=')
if len(split_line) == 2:
params[split_line[0]] = split_line[1]
if len(split_line) >= 2:
params[split_line[0]] = '='.join(split_line[1:])
params['LAST_UPDATED'] = time.ctime(os.path.getmtime(makefile_location))
return params

Expand Down

0 comments on commit 460a964

Please sign in to comment.