def _update_path(self, verbose=False): self._copy_path_yaml_from_setting_dir(force=False, verbose=verbose) import yaml path_filename = os.path.join(wasanbon.home_path, 'path.yaml') dir = yaml.load(open(path_filename, 'r')) hints = yaml.load( open(os.path.join(self.setting_path, 'hints.yaml'), 'r')) path_dict = {} for key, value in dir.items(): hints_org = hints[key] hints_ = [ h.replace('$HOME', wasanbon.get_home_path()) for h in hints_org ] new_path = setup.search_command(key, value, hints_, verbose=verbose) path_dict[key] = new_path yaml.dump(path_dict, open(path_filename, 'w'), encoding='utf8', allow_unicode=True, default_flow_style=False)
def setup_bashrc(self, verbose=False): """ Setup bashrc profile. In Ubuntu, $HOME/.bashrc. In OSX, $HOME/.bash_profile. """ if sys.platform == 'darwin': filename = '.bash_profile' elif sys.platform == 'linux2': filename = '.bashrc' else: return -1 start_str = '#-- Starting Setup Script of wasanbon --#' stop_str = '#-- Ending Setup Script of wasanbon --#' target = os.path.join(wasanbon.get_home_path(), filename) script = open( os.path.join(__path__[0], "settings", wasanbon.platform(), "bashrc"), "r").read() if verbose: sys.stdout.write('# Initializing $HOME/%s\n' % filename) if os.path.isfile(target): erase = False file = open(target, "r") fout = open(target + '.bak', "w") for line in file: if line.strip() == start_str: erase = True continue elif line.strip() == stop_str: erase = False continue if not erase: fout.write(line) pass pass file.close() fout.close() os.remove(target) os.rename(target + ".bak", target) fout = open(target, "a") else: fout = open(target, "w") pass fout.write("\n\n" + start_str + "\n") fout.write(script) fout.write("\n" + stop_str + "\n\n") fout.close() return 0
def setup_bashrc(self, verbose=False): """ Setup bashrc profile. In Ubuntu, $HOME/.bashrc. In OSX, $HOME/.bash_profile. """ if sys.platform == 'darwin': filename = '.bash_profile' elif sys.platform == 'linux2': filename = '.bashrc' else: return -1 start_str = '#-- Starting Setup Script of wasanbon --#' stop_str = '#-- Ending Setup Script of wasanbon --#' target = os.path.join(wasanbon.get_home_path(), filename) script = open(os.path.join(__path__[0], "settings", wasanbon.platform(), "bashrc"), "r").read() if verbose: sys.stdout.write('# Initializing $HOME/%s\n' % filename) if os.path.isfile(target): erase = False file = open(target, "r") fout = open(target + '.bak', "w") for line in file: if line.strip() == start_str: erase = True continue elif line.strip() == stop_str: erase = False continue if not erase: fout.write(line) pass pass file.close() fout.close() os.remove(target) os.rename(target + ".bak" , target) fout = open(target, "a") else: fout = open(target, "w") pass fout.write("\n\n" + start_str + "\n") fout.write(script) fout.write("\n" + stop_str + "\n\n") fout.close() return 0
def edit_rtc(self, rtc, verbose=False): editenv = os.environ.copy() if not 'HOME' in editenv.keys(): editenv['HOME'] = wasanbon.get_home_path() cmd = [self.get_editor_path()] if len(cmd[0]) == 0: sys.stdout.write('# Error. Editor can not be found.\n') return -1 if not sys.platform is 'darwin': cmd = cmd + ['-nw'] srcs = find_rtc_srcs(rtc.rtcprofile) cmd = cmd + srcs # rtc_obj.packageprofile.getSourceFiles() if verbose: sys.stdout.write('# Edit RTC command=%s\n' % cmd) signal.signal(signal.SIGINT, signal_action) subprocess.call(cmd, env=editenv) pass
def _update_path(self, verbose=False): self._copy_path_yaml_from_setting_dir(force=False, verbose=verbose) import yaml path_filename = os.path.join(wasanbon.home_path, 'path.yaml') dir = yaml.load(open(path_filename, 'r')) hints = yaml.load(open(os.path.join(self.setting_path, 'hints.yaml'), 'r')) path_dict = {} for key, value in dir.items(): hints_org = hints[key] hints_ = [h.replace('$HOME', wasanbon.get_home_path()) for h in hints_org] new_path = setup.search_command(key, value, hints_, verbose=verbose) path_dict[key] = new_path yaml.dump(path_dict, open(path_filename, 'w'), encoding='utf8', allow_unicode=True, default_flow_style=False)
def git_command(commands, path='.', verbose=False, pipe=False, interactive=False): cur_dir = os.getcwd() os.chdir(path) gitenv = os.environ.copy() import wasanbon if not 'HOME' in gitenv.keys(): gitenv['HOME'] = wasanbon.get_home_path() if verbose: sys.stdout.write( ' - Environmental Variable HOME (%s) is added.\n' % gitenv['HOME']) setting = plugin_obj.admin.environment.path if len(setting['git']) == 0: sys.stdout.write(' @ GIT COMMAND NOT FOUND.....\n') return False cmd = [setting['git']] + commands stdout = None if verbose else subprocess.PIPE stderr = None if verbose else subprocess.PIPE if interactive: stdout = None stderr = None if verbose: sys.stdout.write(' - wasanbon.git command = %s' % setting['git']) for c in cmd: sys.stdout.write(c + ' ') sys.stdout.write('\n') if not pipe: #p = subprocess.call(cmd, env=gitenv, stdout=stdout, stderr=stderr) p = subprocess.Popen(cmd, env=gitenv, stdout=stdout, stderr=stderr) p.wait() else: p = subprocess.Popen(cmd, env=gitenv, stdout=stdout, stderr=stderr) os.chdir(cur_dir) return p
def git_command(commands, path='.', verbose = False, pipe=False, interactive=False): cur_dir = os.getcwd() os.chdir(path) gitenv = os.environ.copy() import wasanbon if not 'HOME' in gitenv.keys(): gitenv['HOME'] = wasanbon.get_home_path() if verbose: sys.stdout.write(' - Environmental Variable HOME (%s) is added.\n' % gitenv['HOME']) setting = admin.environment.path if len(setting['git']) == 0: sys.stdout.write(' @ GIT COMMAND NOT FOUND.....\n') return False cmd = [setting['git']] + commands stdout = None if verbose else subprocess.PIPE stderr = None if verbose else subprocess.PIPE if interactive: stdout = None stderr = None if verbose: sys.stdout.write(' - wasanbon.git command = %s' % setting['git']) for c in cmd: sys.stdout.write(c + ' ') sys.stdout.write('\n') if not pipe: #p = subprocess.call(cmd, env=gitenv, stdout=stdout, stderr=stderr) p = subprocess.Popen(cmd, env=gitenv, stdout=stdout, stderr=stderr) p.wait() else: p = subprocess.Popen(cmd, env=gitenv, stdout=stdout, stderr=stderr) os.chdir(cur_dir) return p