Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved installation script.

  • Loading branch information...
commit 8ae421f3d03ab7bd805ba4cc56284775d055e5f8 1 parent 40664ee
Enrico Franchi authored
Showing with 59 additions and 10 deletions.
  1. +59 −10 install.py
69 install.py
View
@@ -5,6 +5,18 @@
from os import path
+EMACS_CONF_FILE = 'emacs'
+EMACS_CONF_DIR = 'emacs.d'
+
+def hidden_name(name):
+ return '.%s' % name
+
+def unhidden_name(name):
+ if name.startswith('.'):
+ return name[1:]
+ else:
+ return name
+
def is_windows():
return os.name == 'nt'
@@ -15,11 +27,16 @@ def home_path():
return windows_home() if is_windows() else os.environ['HOME']
def find_base():
- if path.isfile('emacs'):
+ if path.isfile(EMACS_CONF_FILE):
return os.curdir
else:
# here add better diagnostic
- raise RuntimeError("Can't find configuration files.")
+ enclosing_dir = path.dirname(__file__)
+ tentative_emacs = path.join(enclosing_dir, EMACS_CONF_FILE)
+ if path.isfile(tentative_emacs):
+ return enclosing_dir
+ else:
+ raise RuntimeError("Can't find configuration files.")
# everybody nows that explicit logging this way sucks
def overwrite_if_more_recent(command, src, dest, *args, **kw):
@@ -39,13 +56,45 @@ def overwrite_if_more_recent(command, src, dest, *args, **kw):
command(src, dest, *args, **kw)
print '%(src)s -> %(dest)s' % locals()
-HOME = home_path()
-BASE_DIR = find_base()
-overwrite_if_more_recent(shutil.copyfile, 'emacs', path.join(HOME, '.emacs'))
-overwrite_if_more_recent(
- shutil.copytree, 'emacs.d',
- path.join(HOME, '.emacs.d'),
- ignore=shutil.ignore_patterns('*~', '*.elc')
-)
+if __name__ == '__main__':
+ HOME_DIR = home_path()
+ BASE_DIR = find_base()
+
+ EMACS_VERSIONED_FILE = path.join(BASE_DIR, unhidden_name(EMACS_CONF_FILE))
+ EMACS_VERSIONED_DIR = path.join(BASE_DIR, unhidden_name(EMACS_CONF_DIR))
+
+ EMACS_ACTIVE_FILE = path.join(HOME_DIR, hidden_name(EMACS_CONF_FILE))
+ EMACS_ACTIVE_DIR = path.join(HOME_DIR, hidden_name(EMACS_CONF_DIR))
+
+ try:
+ command = sys.argv[1]
+ except KeyError:
+ command = 'activate'
+
+ if command == 'activate':
+ overwrite_if_more_recent(
+ shutil.copyfile,
+ EMACS_VERSIONED_FILE,
+ EMACS_ACTIVE_FILE
+ )
+ overwrite_if_more_recent(
+ shutil.copytree,
+ EMACS_VERSIONED_DIR,
+ EMACS_ACTIVE_DIR,
+ ignore=shutil.ignore_patterns('*~', '*.elc')
+ )
+ elif 'store':
+ overwrite_if_more_recent(
+ shutil.copyfile,
+ EMACS_ACTIVE_FILE,
+ EMACS_VERSIONED_FILE
+ )
+ overwrite_if_more_recent(
+ shutil.copytree,
+ EMACS_ACTIVE_DIR,
+ EMACS_VERSIONED_DIR,
+ ignore=shutil.ignore_patterns('*~', '*.elc')
+ )
+
Please sign in to comment.
Something went wrong with that request. Please try again.