def main(): # make sure that gloss system is installed. if not is_dir(dst_dir): errL('bad gloss directory: ', dst_dir, '\nfirst run gloss-install-sys.py; if using a custom install directory,' ' it must be the same for both sys and user installations.') exit(1) try: common_path = '~/.bash_profile_and_rc' # path to common bash setup file. profile_path = expand_user('~/.bash_profile') # executed for login shells. rc_path = expand_user('~/.bashrc') # executed for non-login shells. source_env_line = 'source ' + path_join(dst_dir, 'sh/gloss_env.bash') + '\n' # bash_setup sources gloss_env. source_common_line = 'source ' + common_path + '\n' # traditional bash files source bash_setup. errSL('setting up bash to use the gloss environment...') append_line_if_missing(expand_user(common_path), source_env_line) for p in [profile_path, rc_path]: append_line_if_missing(p, source_common_line) install_usercustomize() except OSError as e: # usually permissions. exit(e)
def check_pattern(pattern, default_style, roots, expand_tilde): if ":" in pattern: style, colon, path = pattern.partition(":") prefix = style + colon else: style, path = default_style, pattern prefix = "" if style not in known_styles: raise Error("unknown pattern style.") # accept regular expression without further checking if style == "re" or path[0] == "*": return pattern # process leading ~ in path if path[0] == "~": if expand_tilde: path = expand_user(path) pattern = prefix + path else: raise Error("borg does not interpret leading tilde as user.") # check to see that path corresponds to a root if any(path.startswith(str(root)) for root in roots): return pattern if style in ["fm", "sh"]: if any(str(root).startswith(path.partition("*")[0]) for root in roots): return pattern raise Error("path is not in a known root.")
def check_patterns(patterns, roots, working_dir, src, expand_tilde=True, skip_checks=False): paths = [] default_style = "sh" for pattern in patterns: pattern = pattern.strip() culprit = src codicil = repr(pattern) kind = pattern[0:1] arg = pattern[1:].lstrip() if kind in ["", "#"]: continue # is comment if kind not in known_kinds: error("unknown type", culprit=culprit) continue if kind == "R": if arg[0] == "~" and not expand_tilde: error("borg does not interpret leading tilde as user.", culprit=culprit, codicil=codicil) root = expand_user(arg) if not skip_checks: check_root(root, working_dir) roots.append(to_path(root)) paths.append(kind + " " + root) elif kind == "P": if arg in known_styles: default_style = arg else: error("unknown pattern style.", culprit=culprit, codicil=codicil) paths.append(kind + " " + arg) elif not roots: error("no roots available.", culprit=culprit, codicil=codicil) return [] else: try: paths.append( kind + " " + check_pattern(arg, default_style, roots, expand_tilde)) except Error as e: e.report(culprit=culprit, codicil=codicil) return paths
def __resources(self, data): path = data.get('path', None) content = data.get('content', None) output = {'type': 'resource'} try: fix_path = expand_user(path) with open(fix_path, "w") as file: file.write(content) output.update(path=path, content=content) return output except FileNotFoundError as e: msg = f'Path {path} not found' self.log.exception(msg, e) return Not_Found_Response(msg, e, type='resource', data=data) except Exception as e: msg = f'Path {path} not accessible' self.log.exception(msg, e) return Bad_Request_Response(e, message=msg, type='resource', data=data)
def __resources(self, data): path = data.get('path', None) content = data.get('content', None) output = dict(type='resource') try: fix_path = expand_user(path) with open(fix_path, "w") as file: file.write(content) output.update(path=path, content=content) except FileNotFoundError as e: self.log.exception(e) output.update(error=True, data=data, description=f'Path [path] not found', exception=extract_info(e)) except Exception as e: self.log.exception(e) output.update(error=True, data=data, description=f'Path [path] not accessible', exception=extract_info(e)) return output
def __parameters(self, data): schema = data.get('schema', None) source = data.get('source', None) path = wrap(data.get('path', [])) value = data.get('value', None) output = {'type': 'parameter'} try: source = expand_user(source) output.update( self.parsers.get(schema)(schema, source, path, value)) return output except File_Not_Found_Error as e: msg = f'Source {source} not found' self.log.exception(msg, e) return Not_Found_Response(msg, e, type='parameter', data=data) except Exception as e: msg = f'Source {source} not accessible' self.log.exception(msg, e) return Bad_Request_Response(e, message=msg, type='parameter', data=data)
def __parameters(self, data): schema = data.get('schema', None) source = data.get('source', None) path = wrap(data.get('path', None)) value = data.get('value', None) output = dict(type='parameter') try: source = expand_user(source) output.update( self.parsers.get(schema)(schema, source, path, value)) except File_Not_Found_Error as e: self.log.exception(e) output.update(error=True, data=data, description=f'Source {source} not found', exception=extract_info(e)) except Exception as e: self.log.exception(e) output.update(error=True, data=data, description=f'Source {source} not accessible', exception=extract_info(e)) return output