Last active
February 24, 2017 07:38
-
-
Save reorx/2c20b6b4cf1abf67aa0b to your computer and use it in GitHub Desktop.
Utils for porting linux man page to dash.app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import os | |
import sys | |
from rename import get_new | |
if __name__ == '__main__': | |
origin = sys.argv[1] | |
dir = os.path.dirname(origin) | |
target = os.readlink(origin) | |
#sys.exit() | |
if target.startswith('/'): | |
print 'Delete {} -> {}'.format(origin, target) | |
os.remove(origin) | |
else: | |
new_target = get_new(target) | |
linkname = get_new(origin) | |
if os.path.exists(os.path.join(dir, new_target)): | |
print 'Create new link {} -> {}'.format(linkname, new_target) | |
os.symlink(new_target, linkname) | |
#sys.exit() | |
os.remove(origin) | |
else: | |
print 'Just delete {}'.format(origin) | |
#sys.exit() | |
os.remove(origin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import sys | |
import shutil | |
def get_new(origin): | |
origin_splited = origin.split('/') | |
filename = origin_splited[-1] | |
fn_splited = filename.split('.') | |
fn_splited[0] = fn_splited[0] + '-linux' | |
origin_splited[-1] = '.'.join(fn_splited) | |
new = '/'.join(origin_splited) | |
return new | |
if __name__ == '__main__': | |
origin = sys.argv[1] | |
new = get_new(origin) | |
print new | |
shutil.move(origin, new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment