def __init__(self, vim, path): self.vim = vim self.rules = [] if not os.path.isfile(path): Shell.cp( '{}/../../../config/rifle.conf'.format( os.path.dirname(__file__)), path) with open(path, 'r') as f: for i, line in enumerate(f): line = line.strip() if len(line) == 0 or line[0] == '#': continue sp = line.split('=') if len(sp) != 2: VimErrorMsg( self.vim, 'invalid rule: rifle.conf line {}'.format(i + 1)) continue tests = [] for test in sp[0].strip().split(','): testSp = [e for e in test.split(' ') if e != ''] tests.append(globals()[testSp[0]](testSp[1])) command = sp[1].strip() self.rules.append((tests, command))
def valid_or_install(cls, vim): import platform import zipfile if Shell.isinPATH('rclone'): return True else: rclone_dir = VimUserInput( 'Rclone not in PATH. Install it at (modify/enter)', os.path.expanduser('~/rclone')) Shell.mkdir(rclone_dir) system = platform.system().lower() processor = 'amd64' if '386' in platform.processor(): processor = '386' else: # Should support arm?? pass url = 'https://downloads.rclone.org/rclone-current-{}-{}.zip'.format( system, processor) zip_fname = os.path.join(rclone_dir, 'rclone.zip') Shell.urldownload(url, zip_fname) zip_ref = zipfile.ZipFile(zip_fname, 'r') zip_ref.extractall(rclone_dir) for entry in zip_ref.NameToInfo: if entry.endswith('rclone'): Shell.cp(os.path.join(rclone_dir, entry), rclone_dir) Shell.chmod(os.path.join(rclone_dir, 'rclone'), 755) zip_ref.close() os.remove(zip_fname) shellrc = VimUserInput( 'Update PATH in (leave blank to set manually later)', Shell.shellrc()) if len(shellrc) > 0: with open(shellrc, 'a') as f: f.write('PATH={}:$PATH\n'.format(rclone_dir)) os.environ['PATH'] += ':' + rclone_dir
def __init__(self, vim, path): self.vim = vim self.rules = [] if not os.path.isfile(path): Shell.cp(os.path.join(config_dir, 'rifle.conf'), path) with open(path, 'r') as f: for i, line in enumerate(f): try: # remove things after the first # (including) line = line[:line.index('#')] except ValueError: pass line = line.strip() if len(line) == 0: continue sp = line.split('=') if len(sp) != 2: VimErrorMsg( 'invalid rule: rifle.conf line {}. There should be one and only one "=" for each line' .format(i + 1)) continue tests = [] for test in sp[0].strip().split(','): testSp = [e for e in test.split(' ') if e != ''] tests.append(globals()[testSp[0]](testSp[1])) command = sp[1].strip() # simple case, used specify only the command # For sophisicated command like bash -c "command {}" # user should add '{}' themselves if '{}' not in command: command = command + ' {}' self.rules.append((tests, command))