Skip to content

Commit

Permalink
Merge pull request koalaman#4 from egalpin/port_vim_settings
Browse files Browse the repository at this point in the history
Port vim settings
  • Loading branch information
egalpin committed Jun 30, 2015
2 parents f420543 + 850af11 commit 00fff41
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions apt-vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ class PkgItem(object):
recipe = self.recipe[HOST_OS]
elif 'all' in self.recipe:
recipe = self.recipe['all']
if self.recipe and not recipe:
if not report_fail('No recipe for your OS'):
sys.exit(1)
if self.recipe and HOST_OS not in self.recipe and not recipe:
report_fail('No recipe for `' + self.name + '` for your OS')
return recipe

class Dependency(PkgItem):
Expand Down Expand Up @@ -137,6 +136,8 @@ def add_pkg(pkg_name, git_url):
return vimpkg

def clone_pkg(git_url, pkg_name=None):
if not git_url:
return
if not pkg_name:
pkg_name = get_pkg_name_from_url(git_url)
try:
Expand All @@ -148,6 +149,8 @@ def __install_pkg(pkg_name, git_url, install_target, commands=[]):
# Change to directory with vim plugins
os.chdir(install_target)
clone_pkg(git_url, pkg_name)
if not os.path.exists(pkg_name):
os.makedirs(pkg_name)
os.chdir(pkg_name)
if not exe_shell_commands(commands):
report_fail('Failed to intall ' + pkg_name)
Expand All @@ -161,9 +164,12 @@ def install_dependencies(pkg_name, dependencies=[]):
os.chdir(pkg_name)

for dep in dependencies:
commands = dep.get_recipe()
if not exe_shell_commands(commands):
report_fail('Failed to intall ' + pkg_name)
if not check_requirements([dep.name]):
commands = dep.get_recipe()
if not exe_shell_commands(commands):
report_fail('Failed to intall ' + pkg_name)
else:
print '`' + dep.name + '` already in PATH'

def user_confirm(msg=None):
if msg is None:
Expand All @@ -186,7 +192,9 @@ def report_fail(fail_msg=None, confirm_msg=None, confirm_continue=True):
fail_msg = 'Something went wrong...\n'
print fail_msg
if confirm_continue:
return user_confirm(confirm_msg)
if user_confirm(confirm_msg):
return True
sys.exit(1)

def add_overwrite(pkg_name, git_url):
install_target = get_install_target()
Expand Down Expand Up @@ -333,9 +341,11 @@ def exe_shell_commands(commands=None):
return report_fail('Command `' + com + '` failed.')
return True

def init():
if not os.path.exists(VIM_ROOT_DIR):
os.makedirs(VIM_ROOT_DIR)
def first_run():
if os.path.exists(VIM_ROOT_DIR):
shutil.copytree(VIM_ROOT_DIR, os.path.join(os.path.expanduser('~'), '.vim.bak'))
shutil.rmtree(VIM_ROOT_DIR)
os.makedirs(VIM_ROOT_DIR)

if not os.path.exists(SCRIPT_ROOT_DIR):
os.makedirs(SCRIPT_ROOT_DIR)
Expand All @@ -351,19 +361,19 @@ def init():
if not os.path.exists(install_target):
os.makedirs(install_target)
os.symlink(install_target, bundle_path)


#if not os.path.exists(BIN_DIR):
#os.makedirs(BIN_DIR)
if not os.path.exists(SRC_DIR):
os.makedirs(SRC_DIR)

def init():
load_vim_config()
missing_deps = []
deps = VIM_CONFIG[GBL][DPND]
for dep in deps:
dep = Dependency.dict_to_dep(dep)
if not check_requirements([dep.name]):
if not dep.get_recipe() or \
if (HOST_OS not in dep.recipe and not dep.get_recipe()) or \
not exe_shell_commands(dep.get_recipe()):
missing_deps.append(dep.name)
return missing_deps
Expand Down Expand Up @@ -412,7 +422,6 @@ def __handle_remove(argv, options, git_urls):
install_target = get_install_target()
if not git_urls:
report_fail('No package URL specified. Exiting', confirm_continue=False)
sys.exit(1)
#TODO process cmd options
for git_url in git_urls:
pkg_name = get_pkg_name_from_url(git_url)
Expand All @@ -432,7 +441,6 @@ def __handle_update(argv, options, git_urls):
git_urls = [ p[PKG_URL] for p in VIM_CONFIG[PKGS] ]
if not git_urls:
report_fail('No package URL specified. Exiting', confirm_continue=False)
sys.exit(1)
for git_url in git_urls:
vimpkg = get_vimpkg(git_url)
pkg_name = vimpkg.name
Expand All @@ -453,9 +461,19 @@ def process_cmd_args():
argv = sys.argv[1:]
mode = argv[0].lower()
if mode not in MODES:
if mode == 'init':
first_run()
return
usage()
sys.exit()
else:
missing_dependencies = init()
if missing_dependencies:
print 'Cannot proceed. Missing the following dependencies that could' \
+ ' not be automatically insatlled:\n' \
+ str(missing_dependencies)
sys.exit(1)

options, remainder = getopt.getopt(argv[1:], 'y', ['assume-yes'])
for opt,arg in options:
if opt in ('-y, --assume-yes'):
Expand All @@ -468,13 +486,6 @@ def usage():
print 'Valid modes: ', str(MODES.keys().sort()), '\n'

def main():
missing_dependencies = init()
if missing_dependencies:
print 'Cannot proceed. Missing the following dependencies that could' \
+ ' not be automatically insatlled:\n' \
+ str(missing_dependencies)
sys.exit(1)
load_vim_config()
process_cmd_args()
print 'Completed successfully!'

Expand Down

0 comments on commit 00fff41

Please sign in to comment.