Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 79 additions & 75 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
VERSIONS = ['2.7', '3.4', '3.5', '3.6', '3.7']
VERSION = str(sys.version_info[0]) + '.' + str(sys.version_info[1])

# Do we want config directory with host.conf and bash completion.
HOMECFG = True

if '--no-home-cfg' in sys.argv:

HOMECFG = False
sys.argv.pop(sys.argv.index('--no-home-cfg'))

if VERSION not in VERSIONS:

sys.exit('The Python version installed is "{0}.{1}", Longbow does not '
Expand Down Expand Up @@ -89,100 +97,96 @@
scripts=['longbow/longbow'],
)

# Try and create the .Longbow directory and a basic hosts.conf
try:

# Test for the old directory presence (IE updating).
if os.path.isdir(os.path.expanduser('~/.Longbow')):

print("Since version 1.5.0 '~/.Longbow' directory has been all lower"
"case, moving '~/.Longbow' to '~/.longbow'.")
if HOMECFG is True:

os.rename(os.path.expanduser('~/.Longbow'),
os.path.expanduser('~/.longbow'))
# Try and create the .Longbow directory and a basic hosts.conf
try:

# Setting up the .Longbow directory.
elif not os.path.isdir(os.path.expanduser('~/.longbow')):
# Setting up the .Longbow directory.
if not os.path.isdir(os.path.expanduser('~/.longbow')):

print('Longbow will create a hidden directory in your $HOME directory '
'in which it will create the hosts configuration file. You will '
'need to edit this file with your account information on the '
'HPC machines you wish to use. See documentation for more '
'information - www.hecbiosim.ac.uk/longbow-docs')
print('Longbow will create a hidden directory in your $HOME '
'directory in which it will create the hosts configuration '
'file. You will need to edit this file with your account '
'information on the HPC machines you wish to use. See '
'documentation for more information - '
'www.hecbiosim.ac.uk/longbow-docs')

os.mkdir(os.path.expanduser('~/.longbow'))
os.mkdir(os.path.expanduser('~/.longbow'))

HOSTFILE = open(os.path.expanduser('~/.longbow/hosts.conf'), 'w+')
HOSTFILE = open(os.path.expanduser('~/.longbow/hosts.conf'), 'w+')

HOSTFILE.write('[QuickStart]\n')
HOSTFILE.write('host = login.hpc.ac.uk\n')
HOSTFILE.write('user = myusername\n')
HOSTFILE.write('corespernode = 24\n')
HOSTFILE.write('cores = 24\n')
HOSTFILE.write('remoteworkdir = /work/myusername/\n')
HOSTFILE.write('account = myaccount\n')
HOSTFILE.write('modules = mymodules\n')
HOSTFILE.write(
'[QuickStart]\n'
'host = login.hpc.ac.uk\n'
'user = myusername\n'
'corespernode = 24\n'
'cores = 24\n'
'remoteworkdir = /work/myusername/\n'
'account = myaccount\n'
'modules = mymodules\n')

HOSTFILE.close()
HOSTFILE.close()

else:
else:

print("Directory already exists at '~/.longbow, Longbow is skipping "
"creating a new one.")
print('Directory already exists at "~/.longbow" - Longbow is '
'skipping creating a new one.')

except IOError:
except IOError:

print('Longbow failed to create the host configuration file in '
'"~/.longbow/hosts.conf", you will have to do this manually. The '
'user documentation details the information that should be in this '
'file.')
print('Longbow failed to create the host configuration file in '
'"~/.longbow/hosts.conf", you will have to do this manually.\n'
'The user documentation details the information that should be '
'in this file here \n https://longbow.readthedocs.io/en/latest/'
'usr-getting-started.html#adding-a-hpc-machine-to-longbow')

# Try to create the bash autocomplete file.
try:
# Try to create the bash autocomplete file.
try:

print('Longbow will try to setup bash autocomplete on this machine, this '
'will enable the user to use the tab key as part of the longbow '
'command-line to reveal/complete command-line args. This currently '
'only works on some operating systems (mainly Linux based).')
print('Longbow will try to setup bash autocomplete on this machine, '
'this will enable the user to use the tab key as part of the '
'longbow command-line to reveal/complete command-line args.\n'
'This currently only works on some operating systems.')

BASHFILE = open(os.path.expanduser('~/.longbow/bash_completion'), 'w+')
BASHFILE = open(os.path.expanduser('~/.longbow/bash_completion'), 'w+')

BASHFILE.write('_longbow()\n')
BASHFILE.write('{\n')
BASHFILE.write(' local cur prev opts\n')
BASHFILE.write(' COMPREPLY=()\n')
BASHFILE.write(' cur="${COMP_WORDS[COMP_CWORD]}"\n')
BASHFILE.write(' prev="${COMP_WORDS[COMP_CWORD-1]}"\n')
BASHFILE.write(' opts="--about --debug --disconnect --examples --help '
'--hosts --job --jobname --log -- maxtime --nochecks '
'--recover --resource --replicates --verbose '
'--version"\n\n')
BASHFILE.write(' if [[ ${cur} == -* ]]; then\n')
BASHFILE.write(' COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )\n')
BASHFILE.write(' return 0\n')
BASHFILE.write(' elif [[ ${prev} == --hosts ]] || '
'[[ ${prev} == --job ]] || [[ ${prev} == --recover ]]; '
'then\n')
BASHFILE.write(' _filedir\n')
BASHFILE.write(' fi\n')
BASHFILE.write('}\n')
BASHFILE.write('complete -F _longbow longbow\n')
BASHFILE.write(
'_longbow()\n'
'{\n'
' local cur prev opts\n'
' COMPREPLY=()\n'
' cur="${COMP_WORDS[COMP_CWORD]}"\n'
' prev="${COMP_WORDS[COMP_CWORD-1]}"\n'
' opts="--about --debug --disconnect --examples '
'--help --hosts --job --jobname --log -- maxtime '
'--nochecks --recover --resource --replicates '
'--verbose --version"\n\n'
' if [[ ${cur} == -* ]]; then\n'
' COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )\n'
' return 0\n'
' elif [[ ${prev} == --hosts ]] || '
'[[ ${prev} == --job ]] || [[ ${prev} == --recover ]]; then\n'
' _filedir\n'
' fi\n'
'}\n'
'complete -F _longbow longbow\n')

BASHFILE.close()
BASHFILE.close()

# Now add a source entry to the user .bashrc
if os.path.isfile(os.path.expanduser('~/.bashrc')):
# Now add a source entry to the user .bashrc
if os.path.isfile(os.path.expanduser('~/.bashrc')):

BASHFILE = open(os.path.expanduser('~/.bashrc'), 'a+')
BASHFILE = open(os.path.expanduser('~/.bashrc'), 'a+')

if not any('source ~/.longbow/bash_completion'
in bashline for bashline in BASHFILE.readlines()):
if not any('source ~/.longbow/bash_completion'
in bashline for bashline in BASHFILE.readlines()):

BASHFILE.write('source ~/.longbow/bash_completion\n')
BASHFILE.write('source ~/.longbow/bash_completion\n')

except IOError:
except IOError:

print('Longbow failed to create the bash autocomplete file on this '
'machine. Longbow will still continue to function normally, however '
'the bash autocomplete will not be available for longbow '
'command-line parameters.')
print('Longbow failed to create the bash autocomplete file on this '
'machine. Longbow will still continue to function normally, '
'however the bash autocomplete will not be available for '
'longbow command-line parameters.')