def excenturyrc(): """Create the excenturyrc file. """ rc_path = pth.expandvars('$HOME/.excentury/excenturyrc') disp('writing %s ... ' % rc_path) with open(rc_path, 'w') as rcfile: rcfile.write(excenturyrc_str()) disp('done\n')
def display(): """Display the excentury projects. """ data = get_entries() current = get_current() if current == '': disp('No project is currently selected\n') else: disp(' [0]: Select this entry for excenturys default use \n') for num, entry in enumerate(data): if current == entry[1]: disp('->[%d]: %s --> %s\n' % (num+1, entry[0], entry[1])) else: disp(' [%d]: %s --> %s\n' % (num+1, entry[0], entry[1]))
def set_project(name): """Sets a project. """ rc_path = pth.expandvars('$HOME/.excentury/excenturyrc') if name == '0': with open(rc_path, 'w') as rcfile: rcfile.write(excenturyrc_str()) set_current('') disp("Restart bash to clear previous project settings.\n") return data = get_entries() found = False for num, entry in enumerate(data): if name in [entry[0], str(num+1)]: set_current(entry[1]) with open(rc_path, 'w') as rcfile: rcfile.write(excenturyrc_str()) rcfile.write('source %s/.xcpprc\n' % entry[1]) disp('Project %r has been set. Restart bash.\n' % name) found = True break if not found: error("ERROR: not a valid entry\n")
def make_config_file(arg): """Creates a configuration file. """ if pth.exists('xcpp.config'): disp('xcpp.config already exists ...\n') return disp('creating xcpp.config ... ') with open('xcpp.config', 'w') as _fp: _fp.write(XCPP_CONFIG.format(name=arg.name)) disp('done\n')
def make_bashrc(arg): """Create the bashrc file for the project. """ if pth.exists('.xcpprc'): disp('.xcpprc already exists ...\n') return disp('creating .xcpprc ... ') with open('.xcpprc', 'w') as rcf: rcf.write("# %s bash configuration file\n" % arg.name) rcf.write('ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"\n') rcf.write('export XCPP_CONFIG_PATH=$ROOT\n') rcf.write(append_variable('PATH', '$ROOT/bin')) rcf.write(append_variable('LD_LIBRARY_PATH', '$ROOT/lib')) rcf.write(append_variable('MATLABPATH', '$ROOT/matlab')) rcf.write(append_variable('PYTHONPATH', '$ROOT/python')) disp('done\n')
def make_directories(): """Creates the project directories. """ dirs = [ 'xcpp', 'bin', 'lib', 'cpp', 'matlab', 'python', ] disp('Creating directories ... \n') for path in dirs: if make_dir(path): disp(' creating %r\n' % path) else: disp(' %r already exists\n' % path)
def source_excenturyrc(): """Source the .excenturyrc file in the .bashrc file. """ make_dir(pth.expandvars('$HOME/.excentury')) if sys.platform in ['Darwin', 'darwin']: bashrc_path = pth.expandvars('$HOME/.bash_profile') else: bashrc_path = pth.expandvars('$HOME/.bashrc') disp('checking %s ... ' % bashrc_path) if pth.exists(bashrc_path): expr = [ 'source ~/.excentury/excenturyrc\n', 'source $HOME/.excentury/excenturyrc\n', pth.expandvars('source $HOME/.excentury/excenturyrc\n'), ] for content_line in open(bashrc_path, 'r'): for line in expr: if line == content_line: disp('ok\n') return with open(bashrc_path, 'a') as content_file: disp('\n including excenturyrc\n') content_file.write('source ~/.excentury/excenturyrc\n')