diff options
| -rwxr-xr-x | scripts/combo-layer | 73 |
1 files changed, 65 insertions, 8 deletions
diff --git a/scripts/combo-layer b/scripts/combo-layer index 95653b0c21..516fffbec6 100755 --- a/scripts/combo-layer +++ b/scripts/combo-layer | |||
| @@ -39,6 +39,15 @@ def logger_create(): | |||
| 39 | 39 | ||
| 40 | logger = logger_create() | 40 | logger = logger_create() |
| 41 | 41 | ||
| 42 | def get_current_branch(repodir=None): | ||
| 43 | try: | ||
| 44 | branchname = runcmd("git symbolic-ref HEAD 2>/dev/null", repodir).strip() | ||
| 45 | if branchname.startswith("refs/heads/"): | ||
| 46 | branchname = branchname[11:] | ||
| 47 | return branchname | ||
| 48 | except subprocess.CalledProcessError: | ||
| 49 | return "" | ||
| 50 | |||
| 42 | class Configuration(object): | 51 | class Configuration(object): |
| 43 | """ | 52 | """ |
| 44 | Manages the configuration | 53 | Manages the configuration |
| @@ -49,30 +58,78 @@ class Configuration(object): | |||
| 49 | def __init__(self, options): | 58 | def __init__(self, options): |
| 50 | for key, val in options.__dict__.items(): | 59 | for key, val in options.__dict__.items(): |
| 51 | setattr(self, key, val) | 60 | setattr(self, key, val) |
| 52 | self.parser = ConfigParser.ConfigParser() | 61 | |
| 53 | self.parser.readfp(open(self.conffile)) | 62 | def readsection(parser, section, repo): |
| 54 | self.repos = {} | 63 | for (name, value) in parser.items(section): |
| 55 | for repo in self.parser.sections(): | ||
| 56 | self.repos[repo] = {} | ||
| 57 | for (name, value) in self.parser.items(repo): | ||
| 58 | if value.startswith("@"): | 64 | if value.startswith("@"): |
| 59 | self.repos[repo][name] = eval(value.strip("@")) | 65 | self.repos[repo][name] = eval(value.strip("@")) |
| 60 | else: | 66 | else: |
| 61 | self.repos[repo][name] = value | 67 | self.repos[repo][name] = value |
| 62 | 68 | ||
| 69 | logger.debug("Loading config file %s" % self.conffile) | ||
| 70 | self.parser = ConfigParser.ConfigParser() | ||
| 71 | with open(self.conffile) as f: | ||
| 72 | self.parser.readfp(f) | ||
| 73 | |||
| 74 | self.repos = {} | ||
| 75 | for repo in self.parser.sections(): | ||
| 76 | self.repos[repo] = {} | ||
| 77 | readsection(self.parser, repo, repo) | ||
| 78 | |||
| 79 | # Load local configuration, if available | ||
| 80 | self.localconffile = None | ||
| 81 | self.localparser = None | ||
| 82 | self.combobranch = None | ||
| 83 | if self.conffile.endswith('.conf'): | ||
| 84 | lcfile = self.conffile.replace('.conf', '-local.conf') | ||
| 85 | if os.path.exists(lcfile): | ||
| 86 | # Read combo layer branch | ||
| 87 | self.combobranch = get_current_branch() | ||
| 88 | logger.debug("Combo layer branch is %s" % self.combobranch) | ||
| 89 | |||
| 90 | self.localconffile = lcfile | ||
| 91 | logger.debug("Loading local config file %s" % self.localconffile) | ||
| 92 | self.localparser = ConfigParser.ConfigParser() | ||
| 93 | with open(self.localconffile) as f: | ||
| 94 | self.localparser.readfp(f) | ||
| 95 | |||
| 96 | for section in self.localparser.sections(): | ||
| 97 | if '|' in section: | ||
| 98 | sectionvals = section.split('|') | ||
| 99 | repo = sectionvals[0] | ||
| 100 | if sectionvals[1] != self.combobranch: | ||
| 101 | continue | ||
| 102 | else: | ||
| 103 | repo = section | ||
| 104 | if repo in self.repos: | ||
| 105 | readsection(self.localparser, section, repo) | ||
| 106 | |||
| 63 | def update(self, repo, option, value): | 107 | def update(self, repo, option, value): |
| 64 | self.parser.set(repo, option, value) | 108 | if self.localparser: |
| 65 | self.parser.write(open(self.conffile, "w")) | 109 | parser = self.localparser |
| 110 | section = "%s|%s" % (repo, self.combobranch) | ||
| 111 | conffile = self.localconffile | ||
| 112 | else: | ||
| 113 | parser = self.parser | ||
| 114 | section = repo | ||
| 115 | conffile = self.conffile | ||
| 116 | parser.set(section, option, value) | ||
| 117 | with open(conffile, "w") as f: | ||
| 118 | parser.write(f) | ||
| 66 | 119 | ||
| 67 | def sanity_check(self): | 120 | def sanity_check(self): |
| 68 | required_options=["src_uri", "local_repo_dir", "dest_dir", "last_revision"] | 121 | required_options=["src_uri", "local_repo_dir", "dest_dir", "last_revision"] |
| 69 | msg = "" | 122 | msg = "" |
| 123 | missing_options = [] | ||
| 70 | for name in self.repos: | 124 | for name in self.repos: |
| 71 | for option in required_options: | 125 | for option in required_options: |
| 72 | if option not in self.repos[name]: | 126 | if option not in self.repos[name]: |
| 73 | msg = "%s\nOption %s is not defined for component %s" %(msg, option, name) | 127 | msg = "%s\nOption %s is not defined for component %s" %(msg, option, name) |
| 128 | missing_options.append(option) | ||
| 74 | if msg != "": | 129 | if msg != "": |
| 75 | logger.error("configuration file %s has the following error: %s" % (self.conffile,msg)) | 130 | logger.error("configuration file %s has the following error: %s" % (self.conffile,msg)) |
| 131 | if self.localconffile and 'last_revision' in missing_options: | ||
| 132 | logger.error("local configuration file %s may be missing configuration for combo branch %s" % (self.localconffile, self.combobranch)) | ||
| 76 | sys.exit(1) | 133 | sys.exit(1) |
| 77 | 134 | ||
| 78 | # filterdiff is required by action_splitpatch, so check its availability | 135 | # filterdiff is required by action_splitpatch, so check its availability |
