Skip to content

Commit

Permalink
Improved installation script.
Browse files Browse the repository at this point in the history
  • Loading branch information
rik0 committed May 31, 2011
1 parent 40664ee commit 8ae421f
Showing 1 changed file with 59 additions and 10 deletions.
69 changes: 59 additions & 10 deletions install.py
Expand Up @@ -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'

Expand All @@ -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):
Expand All @@ -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')
)



0 comments on commit 8ae421f

Please sign in to comment.