6 import lttng_ivc
.utils
.project
as Project
7 import lttng_ivc
.settings
as Settings
9 from lttng_ivc
.utils
.utils
import sha256_checksum
11 _logger
= logging
.getLogger('project.factory')
12 _project_constructor
= {
13 'babeltrace': Project
.Babeltrace
,
14 'lttng-modules': Project
.Lttng_modules
,
15 'lttng-tools': Project
.Lttng_tools
,
16 'lttng-ust': Project
.Lttng_ust
,
21 _project_py_checksum
= sha256_checksum(Settings
.project_py_file_location
)
24 with
open(Settings
.run_configuration_file
, 'r') as stream
:
25 # This is voluntary static across calls, no need to perform this
27 _markers
= yaml
.load(stream
)
30 def get_fresh(label
, tmpdir
):
31 if label
not in _markers
:
32 # TODO: specialized exception, handle it caller-side so the caller
33 # can decide to skip or fail test.
34 raise Exception('Label is no present')
35 marker
= _markers
[label
]
36 constructor
= _project_constructor
[marker
['project']]
39 return constructor(label
, path
, sha1
, tmpdir
)
42 def _validate_pickle(pickle
, label
):
43 _logger
.debug("Checking validate for {} {}".format(pickle
,
45 if pickle
._py
_file
_checksum
!= _project_py_checksum
:
46 _logger
.warn("Project py file changed".format(pickle
.label
,
50 if pickle
.label
!= label
:
51 _logger
.warn("Label {} and {} are not the same".format(pickle
.label
,
54 if pickle
.sha1
!= _markers
[label
]['sha1']:
55 _logger
.warn("Sha1 {} and {} are not the same".format(pickle
.sha1
,
56 _markers
[label
]['sha1']))
59 deps
= _markers
[label
]['deps']
60 if len(deps
) != len(pickle
.dependencies
):
61 _logger
.warn("Len {} and {} are not the same".format(len(deps
),
62 len(pickle
.dependencies
)))
65 if dep
not in pickle
.dependencies
:
66 _logger
.warn("Dep {} is not in {}".format(dep
,
70 _logger
.debug("Calling validate {} {}".format(pickle
.dependencies
[dep
],
72 valid
= _validate_pickle(pickle
.dependencies
[dep
], dep
)
78 def get_precook(label
):
80 Retrieve a precooked immutable projects from a cache if present
81 otherwise the project is built, installed and cached for future access.
83 if label
not in _markers
:
84 # TODO: specialized exception, handle it caller-side so the caller
85 # can decide to skip or fail test.
86 raise Exception('Label is no present')
87 marker
= _markers
[label
]
88 constructor
= _project_constructor
[marker
['project']]
93 # Cache path for the label
94 cache_path
= os
.path
.join(Settings
.projects_cache_folder
, label
)
95 pickle_path
= os
.path
.join(cache_path
, label
+".pickle")
97 # Check if Pickle Rick is present and valid. If so return it asap.
98 if os
.path
.exists(pickle_path
):
99 with
open(pickle_path
, 'rb') as pickle_file
:
100 pickled
= pickle
.load(pickle_file
)
101 if _validate_pickle(pickled
, label
):
105 _logger
.warn("Pickle for {} is invalid. Rebuilding".format(label
))
107 project
= constructor(label
, path
, sha1
, cache_path
)
110 obj_dep
= get_precook(dep
)
111 project
.dependencies
[dep
] = obj_dep
114 project
._immutable
= True
115 with
open(pickle_path
, 'wb') as pickle_file
:
116 pickle
.dump(project
, pickle_file
)
This page took 0.033858 seconds and 5 git commands to generate.