def sed_replace_kv(key, new_val, src): assert_shell_perms('sed') quotes = '([\'\\"])?' #tricky use quote if found pattern = fr's|^\s*(export )?{key}\={quotes}[^=]*$|\1{key}=\2{new_val}\2|' cmd = fr'gsed -r -i.bak "{pattern}" {src}' res = sed_fcmd(cmd, src) info( f' Replacing key[{key}] with value[{new_val}] on {src} {res.decode()}')
def unit_test(): try: factory = TokenizerFactory(filename='../../cli.lex') print(factory.config) print(factory.meta) except KeyboardInterrupt: info('\nDone')
def sed_insert_file_where(where, insert, src): assert_shell_perms('sed') pattern = f'/{where}/r {insert}' cmd = f'gsed -e "{pattern}" -e /{where}/d {src}' res = sed_fcmd(cmd, src) src_new = f'{src}.new' with open(src_new, 'wb') as dest: dest.write(res) info(f' Attempting insert of [{where}] on {src}') rename_file(src_new, src)
def unit_test(): try: assert_shell_perms('mv') file1='../../inf/.testrc' file2='../../inf/.include' dir1='../../inf/' print(path_type(dir1)) print(path_type(file1)) print(path_type('./moo')) return 0 except KeyboardInterrupt: info('\nDone')
def unit_test(): try: file='../../inf/.testrc' file2='../../inf/.include' file3='../../inf/.morerc' file4='../../inf/.saverc' env = source(file) environ.update(env) update_env(file3) print(get_homedir(),test_profile) profile_link('linker',file2,'.profile') profile_unlink('linker','.profile') print_envars(environ) rem_file(file4) save_env(environ,file4) return 0 except KeyboardInterrupt: info('\nDone')
def unit_test(): try: assert_shell_perms('sed') file = '../../inf/.testrc' file2 = '../../inf/.include' sed_delete_block('# ----test:str---- #', '# ----test:end---- #', file) sed_replace_kv('VAL2', 'moop', file) sed_replace_kv('VAL3', 'soop', file) sed_replace_kv('XY', '999', file) print(line_comment('hey girl', 'js')) print(line_marker('hello', 'sh')[0]) print(line_marker('hello', 'sh')[1]) sed_find_block(*line_marker('test', 'sh'), file) date_st = date_comment('sh', 'Last Updated') sed_add_block( *line_marker('hey girl', 'sh'), f'''{date_st}{NL} # you know I like that pussy ''', file, False) sed_insert_file_where('\#include_me', file2, file) sed_add_block(*line_marker('test', 'sh'), f'''{date_st}{NL} # next ''', file, False) sed_find_block(*line_marker('test', 'sh'), file) #sed_delete_line("#happy pussy",file) sed_add_line(f'#include_me', file) return 0 except KeyboardInterrupt: info('\nDone')
def unit_test(): try: print(sys.path) except KeyboardInterrupt: info('\nDone')
def sed_delete_block(open_st, close_st, src, verify=False): assert_shell_perms('sed') pattern = f'/{open_st}/,/{close_st}/d' cmd = f'gsed -i.bak "{pattern}" {src}' res = sed_fcmd(cmd, src) info(f' Deleting block [{open_st}] on {src} {res.decode()}')
def sed_delete_line(line, src): assert_shell_perms('sed') cmd = f'gsed -i.bak "s|{line}||gi" {src}' res = sed_fcmd(cmd, src) info(f' Deleting line [{line}] on {src} {res.decode()}')