def process_script_deps(action, pkg_vars, **kwargs): """Given an action, if the file starts with #! a list containing a ScriptDependency is returned. Further, if the file is of a known type, it is further analyzed and any dependencies found are added to the list returned.""" if action.name != "file": return [], [], {} f = action.data() l = force_str(f.readline()) f.close() deps = [] elist = [] pkg_attrs = {} script_path = None run_paths = kwargs.get("run_paths", []) # add #! dependency if l.startswith("#!"): # Determine whether the file will be delivered executable. ex_bit = int(action.attrs.get("mode", "0"), 8) & \ (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) if ex_bit: p = (l[2:].split()[0]) # first part of string is path (removes options) # we don't handle dependencies through links, so fix up # the common one p = p.strip() if not os.path.isabs(p): elist.append(ScriptNonAbsPath( action.attrs[PD_LOCAL_PATH], p)) else: if p.startswith("/bin"): # Use p[1:] to strip off the leading /. p = os.path.join("/usr", p[1:]) deps.append(ScriptDependency(action, p, pkg_vars, action.attrs[PD_PROTO_DIR])) script_path = l if "python" in l: ds, errs, py_attrs = python.process_python_dependencies( action, pkg_vars, script_path, run_paths) elist.extend(errs) deps.extend(ds) for key in py_attrs: if key in pkg_attrs: pkg_attrs[key].extend(py_attrs[key]) else: pkg_attrs[key] = py_attrs[key] # Ensure that the reported dependencies are # always in the same order. deps.sort() return deps, elist, pkg_attrs
def process_script_deps(action, pkg_vars, **kwargs): """Given an action, if the file starts with #! a list containing a ScriptDependency is returned. Further, if the file is of a known type, it is further analyzed and any dependencies found are added to the list returned.""" if action.name != "file": return [], [], {} f = action.data() l = f.readline() f.close() deps = [] elist = [] pkg_attrs = {} script_path = None run_paths = kwargs.get("run_paths", []) # add #! dependency if l.startswith("#!"): # Determine whether the file will be delivered executable. ex_bit = int(action.attrs.get("mode", "0"), 8) & \ (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) if ex_bit: p = (l[2:].split()[0]) # first part of string is path (removes options) # we don't handle dependencies through links, so fix up # the common one p = p.strip() if not os.path.isabs(p): elist.append(ScriptNonAbsPath( action.attrs[PD_LOCAL_PATH], p)) else: if p.startswith("/bin"): # Use p[1:] to strip off the leading /. p = os.path.join("/usr", p[1:]) deps.append(ScriptDependency(action, p, pkg_vars, action.attrs[PD_PROTO_DIR])) script_path = l if "python" in l: ds, errs, py_attrs = python.process_python_dependencies( action, pkg_vars, script_path, run_paths) elist.extend(errs) deps.extend(ds) for key in py_attrs: if key in pkg_attrs: pkg_attrs[key].extend(py_attrs[key]) else: pkg_attrs[key] = py_attrs[key] return deps, elist, pkg_attrs
def process_script_deps(action, proto_dir, pkg_vars, **kwargs): """Given an action and a place to find the file it references, if the file starts with #! a list containing a ScriptDependency is returned. Further, if the file is of a known type, it is further analyzed and any dependencies found are added to the list returned.""" # localpath is path to actual file # path is path in installed image if action.name != "file": return [] path = action.attrs[action.key_attr] localpath = os.path.join(proto_dir, path) try: f = open(localpath, "rb") except EnvironmentError: raise base.MissingFile(localpath) l = f.readline() f.close() # add #! dependency if l.startswith("#!"): # usedlist omits leading / p = (l[2:].split()[0]) # first part of string is path (removes # options) # we don't handle dependencies through links, so fix up the # common one p = p.strip() if p.startswith("/bin"): p = os.path.join("/usr", p) deps = [ScriptDependency(action, p, pkg_vars, proto_dir)] elist = [] if "python" in l: ds, errs = python.process_python_dependencies(localpath, proto_dir, action, pkg_vars) elist.extend(errs) deps.extend(ds) return deps, elist return [], []