Sergio Slobodrian | 8684370 | 2017-09-05 23:22:39 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
Zack Williams | 41513bf | 2018-07-07 20:08:35 -0700 | [diff] [blame] | 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
Sergio Slobodrian | 8684370 | 2017-09-05 23:22:39 -0400 | [diff] [blame] | 15 | |
| 16 | # Load the deb_info.txt file into a dictionary for further processing. |
| 17 | deps = dict() |
| 18 | pkgList = list() |
| 19 | sort_list = list() |
| 20 | |
| 21 | with open("deb_info.txt") as f: |
| 22 | for line in f: |
| 23 | line = line.rstrip("\n") |
| 24 | linfo=line.split(":") |
| 25 | pkgList.append(linfo[0]) |
| 26 | deps[linfo[0]]={} |
| 27 | deps[linfo[0]]["deb_file"] = linfo[1] |
| 28 | deps[linfo[0]]["deps"] = linfo[2].split(",") |
| 29 | |
| 30 | |
| 31 | # First extract all packages that don't have any dependencies |
| 32 | # at all with the current set of packages |
| 33 | for key in deps: |
| 34 | hasDep=False |
| 35 | #print(key, " has dependencies ", deps[key]["deps"]) |
| 36 | for dep in deps[key]["deps"]: |
| 37 | if dep in pkgList: |
| 38 | hasDep=True |
| 39 | if hasDep == False: |
| 40 | #print(key, " has no dependencies") |
| 41 | sort_list.append(key) |
| 42 | pkgList.remove(key) |
| 43 | |
| 44 | for pkg in sort_list: |
| 45 | print(deps[pkg]["deb_file"]) |
| 46 | |
| 47 | exit(0) |
| 48 | |
| 49 | # The rest is for future layering of updates and |
| 50 | # isn't currently used. |
| 51 | |
| 52 | # Now scan iterate over the remaining items and |
| 53 | # add them to the sort_list if they have their |
| 54 | # dependencies satisfied in the sort list. |
| 55 | # Continue until the pkgList is empty |
| 56 | lastLen = 0 |
| 57 | while len(pkgList) > 0: |
| 58 | p = pkgList |
| 59 | curLen = len(pkgList) |
| 60 | if lastLen == curLen: |
| 61 | for pkg in p: |
| 62 | sort_list.append(pkg) |
| 63 | pkgList.remove(pkg) |
| 64 | else: |
| 65 | lastLen = curLen |
| 66 | for pkg in p: |
| 67 | missingDep=False |
| 68 | for dep in deps[pkg]["deps"]: |
| 69 | if dep not in sort_list and dep in pkgList: |
| 70 | missingDep=True |
| 71 | if missingDep == False: |
| 72 | sort_list.append(pkg) |
| 73 | pkgList.remove(pkg) |
| 74 | |
| 75 | # Now write the packages out in the sorted order |
| 76 | # this should ensure that dependent packages are |
| 77 | # installed first. |
| 78 | for pkg in sort_list: |
| 79 | print(deps[pkg]["deb_file"]) |