Skip to content

Commit

Permalink
git repositories as templates & code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Sep 28, 2012
1 parent 16e0c66 commit d35e034
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 91 deletions.
47 changes: 29 additions & 18 deletions bin/moa_template_setup
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@ def process_dir():
template = Yaco.Yaco()
template.load(template_file)

if (not os.path.exists('.gitignore')) or args.force:
with open('.gitignore', 'w') as F:
F.write('*\n')

if (not os.path.exists('COPYING')) or args.force:
os.system('wget %s -O COPYING' % LICENSES[args.license])

j = jinja2.Template(JTEMPLATE)
if (not os.path.exists('README.md')) or args.force:
if (not os.path.exists('README.md')) or args.force or True:
print
with open('README.md', 'w') as F:
F.write(j.render(
{'t': template,
Expand All @@ -60,18 +65,19 @@ def process_dir():
os.system('git add README.md COPYING')

print "possible commands that might need to be executed"
print
print "writing README.md"
print "hub create"
print 'git commit -m "autogenerated license & readme"'
print 'git push origin master'


## Jinja template
JTEMPLATE = """
Moa template "{{ t.moa_id }}"
JTEMPLATE = """# Moa template "{{ t.moa_id }}"
Copyright {{ year }}, {{ t.author }}
Copyright {{ year }} {{ t.author }}
This software is under the {{ license }} license, please see "COPYING" for details
This software is under the {{ license }} license, please see "COPYING"
for details
{% macro printpar(p) -%}
{{ p }}
Expand All @@ -81,15 +87,15 @@ This software is under the {{ license }} license, please see "COPYING" for detai
*(no help provided)*
{%- endif %}
*type: *
- *type:*
{%- if t.parameters[p]['type'] -%}
{{ t.parameters[p].type }}
{%- else -%}
String
{%- endif %}<br>
optional: {%- if t.parameters[p]['optional'] == True %}yes{% else %}no{% endif %}
- optional: {%- if t.parameters[p]['optional'] == True %}yes{% else %}no{% endif %}
{% endmacro -%}
{%- macro printfs(f) -%}
{{ f }}
: {% if t.filesets[f].help -%}
Expand All @@ -98,40 +104,45 @@ This software is under the {{ license }} license, please see "COPYING" for detai
*(no help provided)*
{%- endif %}
*type:* {{ t.filesets[f].type }}<br>
*category:* {{ t.filesets[f].category }}<br>
*optional:* {% if t.filesets[f].optional %}yes{% else %}no{% endif %}
- *type:* {{ t.filesets[f].type }}<br>
- *category:* {{ t.filesets[f].category }}<br>
- *optional:* {% if t.filesets[f].optional %}yes{% else %}no{% endif %}
{% endmacro %}
### Description
{% if t.description %}
## Description
{{ t.description }}
{% endif %}
### Filesets
## Filesets
{% for p in t.filesets -%}
{{ printfs(p) }}
{%- endfor %}
### Parameters
## Parameters
{% for p in t.parameters -%}
{%- if p[0] != "_" and p[:4] != "moa" %}{{printpar(p)}}{% endif %}
{%- endfor %}
### Private parameters
## Private parameters
{% for p in t.parameters -%}
{%- if p[0] == "_" or p[:4] != "moa" %}{{printpar(p)}}{% endif %}
{%- endfor %}
### General
## General information
* Author: {{ t.author }}
* Backend: {{ t.backend }}
*This file is automatically generated by "moa_template_setup"*
*This file is automatically generated by "moa_template_setup", part of
the moa software (see: http://mfiers.github.com/Moa/)
"""

if __name__ == "__main__":
Expand Down
30 changes: 26 additions & 4 deletions etc/config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,29 @@ plugins:
enabled: true
system:
moaGit:
module: moa.plugin.system.moaGit
enabled: false
commit:
- '.moa/template'
- '.gitignore'
- '.gitmodules'
- '.moa/template.d/*'
- '.moa/config'
- '.moa/doc'
- '.moa/history'
- '.moa/local_bash_history'
- 'moa.*'
- 'Moa.*'
- 'src/*'
- '*.md'
- 'Readme'
- 'README'
- 'Readme.*'
- 'Changelog'
- 'CHANGELOG'
- 'Changelog.*'
ignore:
- '*'
project:
module: moa.plugin.system.project
enable: true
Expand Down Expand Up @@ -54,14 +76,14 @@ plugins:
module: moa.plugin.system.status
template:
module: moa.plugin.system.template
info:
info:
module: moa.plugin.system.info
enabled: true
moautil:
moautil:
module: moa.plugin.system.moautil
enabled: true
dir: ~/.config/moa/archive
moaGit:
moaGit:
module: moa.plugin.system.moaGit
enabled: false
warn: true
Expand Down Expand Up @@ -100,7 +122,7 @@ ansi:
bmagenta: '48;5;165'
bcyan: '48;5;32'
bgray: '48;5;240'
bwhite: '48;5;255'
bwhite: '48;5;255'
template:
providers:
core:
Expand Down
50 changes: 19 additions & 31 deletions lib/python/moa/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ def __init__(self, wd):
l.debug('Instantiating job in %s' % self.wd)

self.confDir = os.path.join(self.wd, '.moa')
self.templateFile = os.path.join(self.confDir, 'template')
self.templateMetaFile = os.path.join(
self.confDir, 'template.d', 'meta')

self.backend = None
self.args = []
Expand All @@ -123,11 +120,6 @@ def __init__(self, wd):
#used by the backends to store specific data
self.data = Yaco.Yaco()

self.confDir = os.path.join(self.wd, '.moa')
self.templateFile = os.path.join(self.confDir, 'template')
self.templateMetaFile = os.path.join(
self.confDir, 'template.d', 'meta')

# a list of globs that defines what is crucial to a Moa job
# and what is not.
self.data.moaFiles = [
Expand All @@ -143,20 +135,25 @@ def __init__(self, wd):
'blog.*', 'blog'
]

if wd.split(os.path.sep)[-1] == '.moa':
#this is a .moa dir = cannot be a job
pass
else:
self.run_hook('prepare')
self.init2()

def init2(self):
"""
Continue initialization
"""
if self.wd.split(os.path.sep)[-1] == '.moa':
#this is a .moa dir = cannot be a job
return

self.run_hook('prepare')

self.loadTemplate()
self.loadTemplateMeta()
self.loadTemplate()

self.load_config()
#prepare filesets (if need be)o
self.run_hook('pre_filesets')
self.prepareFilesets()
self.renderFilesets()
self.load_config()
#prepare filesets (if need be)
self.run_hook('pre_filesets')
self.prepareFilesets()
self.renderFilesets()

def load_config(self):
# then load the job configuration
Expand Down Expand Up @@ -480,25 +477,16 @@ def loadTemplate(self):
Load the template for this job, based on what configuration
can be found
"""

self.template = moa.template.Template(self.templateFile)
self.template = moa.template.Template(self.wd)
l.debug("Job loaded template %s" % self.template.name)
self.loadBackend()

def loadTemplateMeta(self):
"""
Load the template meta data for this job, based on what configuration
can be found
"""
self.templateMeta = Yaco.Yaco()
if os.path.exists(self.templateMetaFile):
self.templateMeta.load(self.templateMetaFile)

def loadBackend(self):
"""
load the backend
"""
backendName = self.template.backend

l.debug("attempt to load backend %s" % backendName)
try:
moduleName = 'moa.backend.%s' % backendName
Expand Down
8 changes: 4 additions & 4 deletions lib/python/moa/template/provider/archive.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright 2009-2011 Mark Fiers
# The New Zealand Institute for Plant & Food Research
#
#
# This file is part of Moa - http://github.com/mfiers/Moa
#
#
# Licensed under the GPL license (see 'COPYING')
#
#
"""
moa.provider.core
-----------------
Expand Down Expand Up @@ -71,7 +71,7 @@ def templateList(self):
for f in os.listdir(self.directory):
if f[-7:] != '.tar.gz':
continue
if f[0] == '.':
if f[0] == '.':
continue
name = f.replace(".moa", "")
r.append(f[:-7])
Expand Down
33 changes: 17 additions & 16 deletions lib/python/moa/template/provider/core.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright 2009-2011 Mark Fiers
# The New Zealand Institute for Plant & Food Research
#
#
# This file is part of Moa - http://github.com/mfiers/Moa
#
#
# Licensed under the GPL license (see 'COPYING')
#
#
"""
moa.provider.core
-----------------
Expand All @@ -15,19 +15,17 @@
import os
import shutil

import pkg_resources

import Yaco

import moa.logger as l
import moa.logger
import moa.resources

from moa.sysConf import sysConf
from moa.template import provider


l = moa.logger.getLogger(__name__)


class Core(provider.ProviderBase):

TEMPLATEBASE = 'template2'

def hasTemplate(self, tName):
Expand All @@ -52,10 +50,10 @@ def templateList(self):
for f in moa.resources.listResource(self.TEMPLATEBASE):
if f[-4:] != '.moa':
continue
if f[0] == '.':
if f[0] == '.':
continue
name = f.replace(".moa", "")
r.append(f[:-4])
r.append(name)
return r

def installTemplate(self, wd, tName):
Expand All @@ -73,9 +71,12 @@ def installTemplate(self, wd, tName):
moaFile.save(os.path.join(wd, '.moa', 'template'))

for f in moa.resources.listResource(self.TEMPLATEBASE):
if not f.find(tName) == 0: continue
if f[-1] in ['~', '#']: continue
if not f.find(tName) == 0:
continue
if f[-1] in ['~', '#']:
continue

if f[-4:] == '.moa': continue
with open(os.path.join(wd, '.moa', 'template.d', f), 'w') as F:
F.write(moa.resources.getResource(os.path.join(self.TEMPLATEBASE, f)))

F.write(moa.resources.getResource(
os.path.join(self.TEMPLATEBASE, f)))

0 comments on commit d35e034

Please sign in to comment.