9 import settings
as Settings
11 def is_ref_branch(repo
, ref
):
13 repo
.remote().refs
[ref
]
21 def is_ref_tag(repo
, ref
):
31 def is_ref_commit(repo
, ref
):
33 Repo
.rev_parse(repo
, ref
)
42 logger_format
= '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
43 logging
.basicConfig(level
=logging
.DEBUG
,
45 datefmt
='%m-%d %H:%M',
46 filename
='./debug.log',
48 # define a Handler which writes INFO messages or higher to the sys.stderr
49 console
= logging
.StreamHandler()
50 console
.setLevel(logging
.DEBUG
)
51 # set a format which is simpler for console use
52 formatter
= logging
.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
53 # tell the handler to use this format
54 console
.setFormatter(formatter
)
55 # add the handler to the root logger
56 logging
.getLogger('').addHandler(console
)
62 logger_git
= logging
.getLogger('setup.git')
64 # Fetch local base repository
65 with
open(Settings
.configuration_file
, 'r') as stream
:
66 config
= yaml
.load(stream
)
68 # Validate that all default dependancy are present.
69 # TODO: move to function
70 projects_markers
= set()
71 for project
, markers
in config
.items():
74 for marker
in markers
:
75 projects_markers
.add(marker
['marker'])
77 for project
, markers
in config
.items():
80 for marker
in markers
:
81 if 'precook_deps' in marker
:
82 for dep
in marker
['precook_deps']:
83 if dep
not in projects_markers
:
84 raise Exception("{} is not defined".format(dep
))
87 # Retrieve all possibles remotes and clean url for path
89 for project
, markers
in config
.items():
92 for marker
in markers
:
94 url2path
= hashlib
.sha1(url
.encode('utf8')).hexdigest()
95 path
= os
.path
.abspath(Settings
.git_remote_folder
+ '/' + url2path
)
98 logger_git
.info('Remotes to be fetched {}'.format(remotes
))
100 if not os
.path
.isdir(Settings
.git_remote_folder
):
101 os
.makedirs(Settings
.git_remote_folder
)
104 for url
, path
in remotes
.items():
105 if os
.path
.exists(path
):
106 if not os
.path
.isdir(path
):
107 logger_git
.error('Remote path {} exists and is not a folder'.format(path
))
111 repo
= Repo
.clone_from(url
, path
)
113 # TODO: might be necessary to actually update the base branch, to validate
114 repo
.remote().fetch()
116 # Create marker definition for test runners
117 runnable_markers
= {}
118 for project
, markers
in config
.items():
121 for marker
in markers
:
122 name
= marker
['marker']
125 if 'precook_deps' in marker
:
126 deps
= marker
['precook_deps']
134 if is_ref_branch(repo
, ref
):
135 git_object
= Repo
.rev_parse(repo
, repo
.remote().refs
[ref
].name
)
136 elif is_ref_tag(repo
, ref
):
137 git_object
= repo
.tags
[ref
].commit
138 elif is_ref_commit(repo
, ref
):
139 git_object
= repo
.commit(ref
)
141 if git_object
is None:
142 logger_git
.error('Invalid git reference for marker "{}"'.format(name
))
145 logger_git
.info('Marker:{: <30} Sha1 {: <20}'.format(name
, git_object
.hexsha
))
147 if name
in runnable_markers
:
148 logger_git
.error('Duplicate for entry for marker "{}"'.format(name
))
151 runnable_markers
[name
] = {
153 'sha1': git_object
.hexsha
,
159 with
open(Settings
.run_configuration_file
, 'w') as run_configuration
:
160 yaml
.dump(runnable_markers
, run_configuration
, default_flow_style
=False)
This page took 0.035079 seconds and 5 git commands to generate.