LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
PolicyUtils.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 import sys
24 import sets
25 import os.path
26 import lsst.pex.policy as pol
27 
28 ## @deprecated policy file utilities
30 
31  ##
32  # @brief given a policy, recursively add all child policies to a policy set
33  #
34 
35  def getAllFilenames(repos, policy, policySet):
36  names = policy.names(True)
37  for name in names:
38  if policy.isArray(name):
39  if policy.isPolicy(name):
40  # name is a policy array
41  policyArray = policy.getPolicyArray(name)
42  for p in policyArray:
43  PolicyUtils.getAllFilenames(repos, p, policySet)
44  else:
45  # name is an array, but not a policy array
46  array = policy.getArray(name)
47  for val in array:
48  if type(val) is pol.PolicyFile:
49  filename = val.getPath()
50  filename = os.path.join(repos, filename)
51  if (filename in policySet) == False:
52  policySet.add(filename)
53  newPolicy = pol.Policy.createPolicy(filename, False)
54  PolicyUtils.getAllFilenames(repos, newPolicy, policySet)
55  else:
56  if policy.isPolicy(name):
57  # name is not an array, but is a Policy
58  p = policy.getPolicy(name)
59  PolicyUtils.getAllFilenames(repos, p, policySet)
60  else:
61  if policy.isFile(name):
62  # name is a File value
63  filename = policy.getFile(name).getPath()
64  filename = os.path.join(repos, filename)
65  if (filename in policySet) == False:
66  policySet.add(filename)
67  newPolicy = pol.Policy.createPolicy(filename, False)
68  PolicyUtils.getAllFilenames(repos, newPolicy, policySet)
69  #else:
70  # name is a regular value
71 
72  ## return all file names from a policy set
73  getAllFilenames = staticmethod(getAllFilenames)
74 
75 if __name__ == "__main__":
76  pset = sets.Set()
77 
78  myPolicy = pol.Policy.createPolicy("main.paf", False)
79  PolicyUtils.getAllFilenames("/home/srp/temp_merge/datarel/trunk/pipeline", myPolicy, pset)
80 
81  for i in pset:
82  print i
tuple getAllFilenames
return all file names from a policy set
Definition: PolicyUtils.py:73