ec44f2b4f69a4e419faac55af1dc1147c07d642c
9 dir_path
= os
.path
.dirname(os
.path
.realpath(__file__
))
10 sys
.path
.insert(0, os
.path
.join(dir_path
, ".."))
12 import settings
as Settings
13 import utils
.ProjectFactory
as ProjectFactory
15 def is_ref_branch(repo
, ref
):
17 repo
.remote().refs
[ref
]
25 def is_ref_tag(repo
, ref
):
35 def is_ref_commit(repo
, ref
):
37 Repo
.rev_parse(repo
, ref
)
46 logger_format
= '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
47 logging
.basicConfig(level
=logging
.DEBUG
,
49 datefmt
='%m-%d %H:%M',
50 filename
='./debug.log',
52 # define a Handler which writes INFO messages or higher to the sys.stderr
53 console
= logging
.StreamHandler()
54 console
.setLevel(logging
.DEBUG
)
55 # set a format which is simpler for console use
56 formatter
= logging
.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
57 # tell the handler to use this format
58 console
.setFormatter(formatter
)
59 # add the handler to the root logger
60 logging
.getLogger('').addHandler(console
)
66 logger_git
= logging
.getLogger('setup.git')
68 # Fetch local base repository
69 with
open(Settings
.configuration_file
, 'r') as stream
:
70 config
= yaml
.load(stream
)
72 # Validate that all default dependancy are present.
73 # TODO: move to function
74 projects_markers
= set()
75 for project
, markers
in config
.items():
78 for marker
in markers
:
79 projects_markers
.add(marker
['marker'])
81 for project
, markers
in config
.items():
84 for marker
in markers
:
85 if 'precook_deps' in marker
:
86 for dep
in marker
['precook_deps']:
87 if dep
not in projects_markers
:
88 raise Exception("{} is not defined".format(dep
))
91 # Retrieve all possibles remotes and clean url for path
93 for project
, markers
in config
.items():
96 for marker
in markers
:
98 url2path
= hashlib
.sha1(url
.encode('utf8')).hexdigest()
99 path
= os
.path
.abspath(Settings
.git_remote_folder
+ '/' + url2path
)
102 logger_git
.info('Remotes to be fetched {}'.format(remotes
))
104 if not os
.path
.isdir(Settings
.git_remote_folder
):
105 os
.makedirs(Settings
.git_remote_folder
)
108 for url
, path
in remotes
.items():
109 if os
.path
.exists(path
):
110 if not os
.path
.isdir(path
):
111 logger_git
.error('Remote path {} exists and is not a folder'.format(path
))
115 repo
= Repo
.clone_from(url
, path
)
117 # TODO: might be necessary to actually update the base branch, to validate
118 repo
.remote().fetch()
120 # Create marker definition for test runners
121 runnable_markers
= {}
122 for project
, markers
in config
.items():
125 for marker
in markers
:
126 name
= marker
['marker']
129 if 'precook_deps' in marker
:
130 deps
= marker
['precook_deps']
138 if is_ref_branch(repo
, ref
):
139 git_object
= Repo
.rev_parse(repo
, repo
.remote().refs
[ref
].name
)
140 elif is_ref_tag(repo
, ref
):
141 git_object
= repo
.tags
[ref
].commit
142 elif is_ref_commit(repo
, ref
):
143 git_object
= repo
.commit(ref
)
145 if git_object
is None:
146 logger_git
.error('Invalid git reference for marker "{}"'.format(name
))
149 logger_git
.info('Marker:{: <30} Sha1 {: <20}'.format(name
, git_object
.hexsha
))
151 if name
in runnable_markers
:
152 logger_git
.error('Duplicate for entry for marker "{}"'.format(name
))
155 runnable_markers
[name
] = {
157 'sha1': git_object
.hexsha
,
163 with
open(Settings
.run_configuration_file
, 'w') as run_configuration
:
164 yaml
.dump(runnable_markers
, run_configuration
, default_flow_style
=False)
166 # Prebuild all projects
167 for key
in runnable_markers
:
168 logger_git
.info('Preparing and building {}'.format(key
))
169 ProjectFactory
.get_precook(key
)
This page took 0.034893 seconds and 5 git commands to generate.