1 # Copyright (c) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
10 # The above copyright notice and this permission notice shall be included in all
11 # copies or substantial portions of the Software.
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 import lttng_ivc
.utils
.project
as Project
27 import lttng_ivc
.settings
as Settings
29 from lttng_ivc
.utils
.utils
import sha256_checksum
31 _logger
= logging
.getLogger('project.factory')
32 _project_constructor
= {
33 'babeltrace': Project
.Babeltrace
,
34 'lttng-modules': Project
.Lttng_modules
,
35 'lttng-tools': Project
.Lttng_tools
,
36 'lttng-ust': Project
.Lttng_ust
,
41 _project_py_checksum
= sha256_checksum(Settings
.project_py_file_location
)
44 with
open(Settings
.run_configuration_file
, 'r') as stream
:
45 # This is voluntary static across calls, no need to perform this
47 _markers
= yaml
.load(stream
)
50 def get_fresh(label
, tmpdir
):
51 if label
not in _markers
:
52 # TODO: specialized exception, handle it caller-side so the caller
53 # can decide to skip or fail test.
54 raise Exception('Label is no present')
55 marker
= _markers
[label
]
56 constructor
= _project_constructor
[marker
['project']]
59 return constructor(label
, path
, sha1
, tmpdir
)
62 def _validate_pickle(pickle
, label
):
63 _logger
.debug("Checking validate for {} {}".format(pickle
,
65 if pickle
._py
_file
_checksum
!= _project_py_checksum
:
66 _logger
.warn("Project py file changed".format(pickle
.label
,
70 if pickle
.label
!= label
:
71 _logger
.warn("Label {} and {} are not the same".format(pickle
.label
,
74 if pickle
.sha1
!= _markers
[label
]['sha1']:
75 _logger
.warn("Sha1 {} and {} are not the same".format(pickle
.sha1
,
76 _markers
[label
]['sha1']))
79 deps
= _markers
[label
]['deps']
80 if len(deps
) != len(pickle
.dependencies
):
81 _logger
.warn("Len {} and {} are not the same".format(len(deps
),
82 len(pickle
.dependencies
)))
85 if dep
not in pickle
.dependencies
:
86 _logger
.warn("Dep {} is not in {}".format(dep
,
90 _logger
.debug("Calling validate {} {}".format(pickle
.dependencies
[dep
],
92 valid
= _validate_pickle(pickle
.dependencies
[dep
], dep
)
98 def get_precook(label
):
100 Retrieve a precooked immutable projects from a cache if present
101 otherwise the project is built, installed and cached for future access.
103 if label
not in _markers
:
104 # TODO: specialized exception, handle it caller-side so the caller
105 # can decide to skip or fail test.
106 raise Exception('Label is no present')
107 marker
= _markers
[label
]
108 constructor
= _project_constructor
[marker
['project']]
109 path
= marker
['path']
110 sha1
= marker
['sha1']
111 deps
= marker
['deps']
113 # Cache path for the label
114 cache_path
= os
.path
.join(Settings
.projects_cache_folder
, label
)
115 pickle_path
= os
.path
.join(cache_path
, label
+".pickle")
117 # Check if Pickle Rick is present and valid. If so return it asap.
118 if os
.path
.exists(pickle_path
):
119 with
open(pickle_path
, 'rb') as pickle_file
:
120 pickled
= pickle
.load(pickle_file
)
121 if _validate_pickle(pickled
, label
):
125 _logger
.warn("Pickle for {} is invalid. Rebuilding".format(label
))
127 project
= constructor(label
, path
, sha1
, cache_path
)
130 obj_dep
= get_precook(dep
)
131 project
.dependencies
[dep
] = obj_dep
134 project
._immutable
= True
135 with
open(pickle_path
, 'wb') as pickle_file
:
136 pickle
.dump(project
, pickle_file
)
This page took 0.033569 seconds and 5 git commands to generate.