Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

# This file is part of verify. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (https://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <https://www.gnu.org/licenses/>. 

"""API for parsing the manifest.txt file for EUPS packages found in lsstsw. 

""" 

 

__all__ = ['Manifest'] 

 

from collections import OrderedDict, namedtuple 

 

 

ManifestItem = namedtuple('ManifestItem', 

['name', 'git_sha', 'version', 'dependencies']) 

 

 

class Manifest(object): 

"""Iterator over packages in lsstsw's manifest.txt dataset. 

 

Parameters 

---------- 

manifest_stream : file handle 

A file handle for `manifest.txt` (from `open`, for example). 

""" 

 

def __init__(self, manifest_stream): 

self._build_id = None 

self._packages = OrderedDict() 

 

self._parse_manifest_stream(manifest_stream) 

 

def _parse_manifest_stream(self, manifest_stream): 

for manifest_line in manifest_stream.readlines(): 

manifest_line = manifest_line.strip() 

if manifest_line.startswith('#'): 

continue 

elif manifest_line.startswith('BUILD'): 

self._build_id = manifest_line.split('=')[-1] 

continue 

parts = manifest_line.split() 

package_name = parts[0] 

git_commit = parts[1] 

eups_version = parts[2] 

if len(parts) == 4: 

deps = parts[3].split(',') 

else: 

deps = list() 

 

package = ManifestItem( 

name=package_name, 

git_sha=git_commit, 

version=eups_version, 

dependencies=deps) 

self._packages[package_name] = package 

 

def __iter__(self): 

"""Iterate over package names. 

 

Yields 

------ 

name : `str` 

Package name. 

""" 

for package in self._packages: 

yield package 

 

def items(self): 

"""Iterate over packages. 

 

Yields 

------ 

item : `tuple` 

Tuple of ``(name, manifest_item)``. ``manifest_item`` is a 

`ManifestItem` (namedtuple) type with fields: 

 

- ``name`` 

- ``git_sha`` 

- ``version`` (EUPS version) 

- ``dependencies`` (list of EUPS package names) 

""" 

for item in self._packages.items(): 

yield item 

 

def __len__(self): 

"""Count number of packages in the manifest (`int`).""" 

return len(self._packages) 

 

def __getitem__(self, package_name): 

"""Get a package item from the manifest by name. 

 

Parameters 

---------- 

package_name : `str` 

EUPS package name. 

 

Returns 

------- 

item : `ManifestItem` 

`ManifestItem` is a `namedtuple` type with fields: 

 

- ``name`` 

- ``git_sha`` 

- ``version`` (EUPS version) 

- ``dependencies`` (list of EUPS package names) 

""" 

return self._packages[package_name] 

 

def __contains__(self, package_name): 

"""Test if a package is in the manifest. 

 

Parameters 

---------- 

package_name : `str` 

EUPS package name. 

 

Returns 

------- 

contained : `bool` 

`True` if package is in the manifest. 

""" 

return package_name in self._packages 

 

@property 

def build(self): 

"""Build number, bNNNN (`str`).""" 

return self._build_id