mirror of https://github.com/berriedale/ae
Add support for git:// URLs when referring to schematics
This commit is contained in:
parent
e89e595cd9
commit
3d156e48bf
67
bin/ae
67
bin/ae
|
@ -16,6 +16,15 @@ os.putenv('SCHEMATIC_PARALLELISM', '1')
|
||||||
# schematic installed binaries
|
# schematic installed binaries
|
||||||
os.environ['PATH'] = os.pathsep.join([os.path.join(ROOT_DIR, 'bin'), os.environ['PATH']])
|
os.environ['PATH'] = os.pathsep.join([os.path.join(ROOT_DIR, 'bin'), os.environ['PATH']])
|
||||||
|
|
||||||
|
def read_pipe(name, pipe):
|
||||||
|
while True:
|
||||||
|
line = pipe.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
sys.stdout.write("[%s] %s" % (name, line))
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
class SchematicHandler:
|
class SchematicHandler:
|
||||||
def __init__(self, schematic):
|
def __init__(self, schematic):
|
||||||
self.schematic = schematic
|
self.schematic = schematic
|
||||||
|
@ -41,8 +50,8 @@ class SchematicHandler:
|
||||||
else:
|
else:
|
||||||
command = "cd %s && git fetch" % (self.checkout_dir)
|
command = "cd %s && git fetch" % (self.checkout_dir)
|
||||||
|
|
||||||
self.__readpipe__(os.popen(command))
|
read_pipe(self.name, os.popen(command))
|
||||||
self.__readpipe__(os.popen("cd %s && git checkout origin/%s" % (self.checkout_dir, branch)))
|
read_pipe(self.name, os.popen("cd %s && git checkout origin/%s" % (self.checkout_dir, branch)))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
|
@ -65,15 +74,8 @@ class SchematicHandler:
|
||||||
|
|
||||||
def __run_steps__(self, steps):
|
def __run_steps__(self, steps):
|
||||||
for s in steps:
|
for s in steps:
|
||||||
self.__readpipe__(os.popen("cd %s && %s" % (self.checkout_dir, s)))
|
read_pipe(self.name,
|
||||||
|
os.popen("cd %s && %s" % (self.checkout_dir, s)))
|
||||||
def __readpipe__(self, pipe):
|
|
||||||
while True:
|
|
||||||
line = pipe.readline()
|
|
||||||
if not line:
|
|
||||||
break
|
|
||||||
sys.stdout.write("[%s] %s" % (self.name, line))
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
|
|
||||||
def traverse_schematic_graph(graph, key=None):
|
def traverse_schematic_graph(graph, key=None):
|
||||||
|
@ -90,13 +92,18 @@ def traverse_schematic_graph(graph, key=None):
|
||||||
for key in graph[key]:
|
for key in graph[key]:
|
||||||
return traverse_schematic_graph(graph, key)
|
return traverse_schematic_graph(graph, key)
|
||||||
|
|
||||||
|
class Catalog(object):
|
||||||
|
|
||||||
class FileCatalog:
|
|
||||||
def __init__(self, uri):
|
def __init__(self, uri):
|
||||||
self.uri = uri
|
self.uri = uri
|
||||||
self.schematics = {}
|
self.schematics = {}
|
||||||
|
|
||||||
|
def has_schematic(self, schematic):
|
||||||
|
if self.schematics.has_key(schematic):
|
||||||
|
return self.schematics[schematic]
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class FileCatalog(Catalog):
|
||||||
def load(self):
|
def load(self):
|
||||||
path = re.split('file:\/\/', self.uri)[1]
|
path = re.split('file:\/\/', self.uri)[1]
|
||||||
catalog_dir = os.path.join(path, 'catalog')
|
catalog_dir = os.path.join(path, 'catalog')
|
||||||
|
@ -114,14 +121,24 @@ class FileCatalog:
|
||||||
self.schematics[qualified_name] = yaml.load(file(os.path.join(root, f)))
|
self.schematics[qualified_name] = yaml.load(file(os.path.join(root, f)))
|
||||||
|
|
||||||
|
|
||||||
def has_schematic(self, schematic):
|
|
||||||
if self.schematics.has_key(schematic):
|
|
||||||
return self.schematics[schematic]
|
|
||||||
return None
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "FileCatalog(%s)" % self.uri
|
return "FileCatalog(%s)" % self.uri
|
||||||
|
|
||||||
|
|
||||||
|
class GitCatalog(FileCatalog):
|
||||||
|
def load(self):
|
||||||
|
repo_dir = os.path.join(CACHE_DIR, 'repos')
|
||||||
|
repo = re.match('git:\/\/(.*)\/(.*)\.git', self.uri).group(2)
|
||||||
|
full_path = os.path.join(repo_dir, repo)
|
||||||
|
if os.path.isdir(full_path):
|
||||||
|
read_pipe('git', os.popen('cd %s && git pull --rebase' % full_path))
|
||||||
|
else:
|
||||||
|
read_pipe('git',
|
||||||
|
os.popen('cd %s && git clone --depth 1 %s' % (repo_dir, self.uri)))
|
||||||
|
self.uri = ''.join(['file://', full_path])
|
||||||
|
return super(GitCatalog, self).load()
|
||||||
|
|
||||||
|
|
||||||
def install():
|
def install():
|
||||||
if not os.path.isfile('schematics.yaml'):
|
if not os.path.isfile('schematics.yaml'):
|
||||||
return 1
|
return 1
|
||||||
|
@ -129,7 +146,11 @@ def install():
|
||||||
|
|
||||||
catalogs = []
|
catalogs = []
|
||||||
for catalog in schematics['catalogs']:
|
for catalog in schematics['catalogs']:
|
||||||
c = FileCatalog(catalog)
|
c = None
|
||||||
|
if re.match('file:\/\/', catalog):
|
||||||
|
c = FileCatalog(catalog)
|
||||||
|
elif re.match('git:\/\/', catalog):
|
||||||
|
c = GitCatalog(catalog)
|
||||||
c.load()
|
c.load()
|
||||||
catalogs.append(c)
|
catalogs.append(c)
|
||||||
|
|
||||||
|
@ -137,6 +158,12 @@ def install():
|
||||||
todo = {}
|
todo = {}
|
||||||
dependencies = []
|
dependencies = []
|
||||||
for schematic in schematics['schematics']:
|
for schematic in schematics['schematics']:
|
||||||
|
components = schematic.split('@')
|
||||||
|
version = None
|
||||||
|
schematic = components[0]
|
||||||
|
if len(components) == 2:
|
||||||
|
version = components[1]
|
||||||
|
|
||||||
for catalog in catalogs:
|
for catalog in catalogs:
|
||||||
graph[schematic] = []
|
graph[schematic] = []
|
||||||
s = catalog.has_schematic(schematic)
|
s = catalog.has_schematic(schematic)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
catalogs:
|
catalogs:
|
||||||
- file:///home/tyler/source/github/berriedale/schematics
|
- git://github.com/berriedale/schematics.git
|
||||||
schematics:
|
schematics:
|
||||||
- adacore/aws
|
- adacore/aws
|
||||||
- adacore/gtkada
|
- adacore/gtkada
|
||||||
|
|
Loading…
Reference in New Issue