Skip to content

Commit

Permalink
Tidy up (#28)
Browse files Browse the repository at this point in the history
* Some tidying up for import

* Some tidying up

* More tidying-up

* Fixing issue #27

* More tidying ....
  • Loading branch information
cofinoa authored Dec 30, 2021
1 parent 4f644e4 commit 6d2634c
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 314 deletions.
1 change: 1 addition & 0 deletions .gitattributtes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drm4g/_static_version.py export-subst
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ gridway-5.8/src/gwd/gwd
gridway-5.8/src/scheduler/gw_flood_scheduler
gridway-5.8/src/scheduler/gw_sched
.ignore
gridway-5.8/build
gridway-5.8/build_nodebug
7 changes: 0 additions & 7 deletions .pydevproject

This file was deleted.

29 changes: 10 additions & 19 deletions bin/drm4g
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ drm4g commands are:
See 'drm4g <command> --help' for more information on a specific command.
"""

from docopt import docopt
import sys
from difflib import get_close_matches
import logging
import drm4g
from docopt import docopt

commands_list = [
'start',
Expand All @@ -67,38 +67,29 @@ commands_list = [

def get_similar_commands(name):
"""Command name auto-correct."""

name = name.lower()

close_commands = get_close_matches(name, commands_list)

if close_commands:
return close_commands[0]
else:
return False

return None
class CommandError(Exception):
"""Raised when there is an error in command-line arguments"""
pass

if __name__ == "__main__":
args = docopt( __doc__, version = drm4g.__version__ , options_first = True )
argv = [ args[ '<command>' ] ] + args[ '<args>' ]
#if args['<command>'] in "start stop status restart clear conf id resource host job".split() :
if args['<command>'] in commands_list :
command = getattr( __import__( "drm4g.commands.%s" % args['<command>'] ).commands, args['<command>'] )
cmd_name = args['<command>']
argv = [ cmd_name ] + args[ '<args>' ]
if cmd_name in commands_list :
command = getattr( __import__( "drm4g.commands.%s" % cmd_name ).commands, cmd_name )
arg = docopt( command.__doc__ , argv = argv )
if arg[ '--debug' ] :
command.console_logger.setLevel(logging.DEBUG)
command.run( arg )
else:
cmd_name=args['<command>']
guess = get_similar_commands(cmd_name)

msg = "%r is not a drm4g command" % cmd_name
if guess:
msg = msg+" - maybe you meant '%s'" % guess
msg = msg + " - maybe you meant '%s'" % guess
else:
msg = msg+" - see 'drm4g --help'"

exit(msg)
msg = msg + " - see 'drm4g --help'"
sys.exit(msg)
29 changes: 17 additions & 12 deletions bin/gw_em_mad_drm4g.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@
# permissions and limitations under the Licence.
#

import sys
import traceback
from argparse import ArgumentParser,SUPPRESS

from drm4g.core.em_mad import GwEmMad
from optparse import OptionParser
import sys, traceback

def main():
parser = OptionParser(description = 'Execution manager MAD',
prog = 'gw_em_mad_drm4g.py', version = '0.1',
usage = 'Usage: %prog')
options, args = parser.parse_args()
parser = ArgumentParser(
description = 'Execution manager MAD',
)
parser.add_argument('-v', '--version', action='version', version='0.1')
#workaround for issue
# https://github.com/SantanderMetGroup/DRM4G/issues/27
parser.add_argument('null', nargs="*", type=str, help=SUPPRESS)
parser.parse_args()
try:
GwEmMad().processLine()
except KeyboardInterrupt as e:
sys.exit(-1)
except KeyboardInterrupt:
return -1
except Exception as e:
traceback.print_exc(file=sys.stdout)
exit( 'Caught exception: %s: %s' % (e.__class__, str(e)) )

traceback.print_exc(file=sys.stderr)
return 'Caught exception: %s: %s' % (e.__class__, str(e))

if __name__ == '__main__':
main()
sys.exit(main())
30 changes: 17 additions & 13 deletions bin/gw_im_mad_drm4g.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,28 @@
# permissions and limitations under the Licence.
#

import sys
import traceback
from argparse import ArgumentParser,SUPPRESS

from drm4g.core.im_mad import GwImMad
from optparse import OptionParser
import sys, traceback

def main():
parser = OptionParser(description = 'Information manager MAD',
prog = 'gw_im_mad_drm4g.py', version = '0.1',
usage = 'Usage: %prog')
options, args = parser.parse_args()
parser = ArgumentParser(
description = 'Information manager MAD',
)
parser.add_argument('-v', '--version', action='version', version='0.1')
#workaround for issue
# https://github.com/SantanderMetGroup/DRM4G/issues/27
parser.add_argument('null', nargs="*", type=str, help=SUPPRESS)
parser.parse_args()
try:
GwImMad().processLine()
except KeyboardInterrupt as e:
sys.exit(-1)
except KeyboardInterrupt:
return -1
except Exception as e:
traceback.print_exc(file=sys.stdout)
exit('Caught exception: %s: %s' % (e.__class__, str(e)))

traceback.print_exc(file=sys.stderr)
return 'Caught exception: %s: %s' % (e.__class__, str(e))

if __name__ == '__main__':
main()

sys.exit(main())
29 changes: 17 additions & 12 deletions bin/gw_tm_mad_drm4g.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,28 @@
# permissions and limitations under the Licence.
#

import sys
import traceback
from argparse import ArgumentParser,SUPPRESS

from drm4g.core.tm_mad import GwTmMad
from optparse import OptionParser
import sys, traceback

def main():
parser = OptionParser(description = 'Transfer manager MAD',
prog = 'gw_tm_mad_drm4g.py', version = '0.1',
usage = 'Usage: %prog')
options, args = parser.parse_args()
parser = ArgumentParser(
description = 'Transfer manager MAD',
)
parser.add_argument('-v', '--version', action='version', version='0.1')
#workaround for issue
# https://github.com/SantanderMetGroup/DRM4G/issues/27
parser.add_argument('null', nargs="*", type=str, help=SUPPRESS)
parser.parse_args()
try:
GwTmMad().processLine()
except KeyboardInterrupt as e:
sys.exit(-1)
except KeyboardInterrupt:
return -1
except Exception as e:
traceback.print_exc(file=sys.stdout)
exit( 'Caught exception: %s: %s' % (e.__class__, str(e)) )

traceback.print_exc(file=sys.stderr)
return 'Caught exception: %s: %s' % (e.__class__, str(e))

if __name__ == '__main__':
main()
sys.exit(main())
37 changes: 16 additions & 21 deletions drm4g/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,42 @@

__all__ = ["communicators", "core", "managers", "utils", "commands", "api"]

from ._version import __version__
del _version

#__version__ = '2.6.15'
__author__ = 'Valvanuz Fernández-Quiruelas, Markel Garcia, Carlos Blanco, Antonio Minondo and Antonio S. Cofino (@cofinoa)'

import sys
import os
import logging.config
import logging
from os.path import dirname , join , expanduser , exists , abspath
from shutil import copytree

if sys.version_info<(3,5):
exit( 'The version number of Python has to be >= 3.5' )
from ._version import __version__

__author__ = 'Valvanuz Fernández-Quiruelas, Markel Garcia, Carlos Blanco, Antonio Minondo and Antonio S. Cofino (@cofinoa)'

assert sys.version_info >= (3, 5), "The version number of Python has to be >= 3.5"

##############################################
# Default values used in DRM4G ENV variables #
##############################################
HOME = expanduser(os.environ.get( 'HOME', '~' ))
DRM4G_DIR = expanduser(os.environ.get( 'DRM4G_DIR' , join( HOME , '.drm4g' )))
DRM4G_DIR_VAR = expanduser(os.environ.get( 'DRM4G_DIR_VAR' , join( DRM4G_DIR, 'var' )))
DRM4G_DIR_ETC = expanduser(os.environ.get( 'DRM4G_DIR_ETC' , join( DRM4G_DIR, 'etc' )))
DRM4G_RESOURCES_CONF = expanduser(os.environ.get( 'DRM4G_RESOURCES_CONF', join( DRM4G_DIR_ETC, 'resources.conf' )))
DRM4G_LOGGER_CONF = expanduser(os.environ.get( 'DRM4G_LOGGER_CONF' , join( DRM4G_DIR_ETC, 'logger.conf')))
DRM4G_GWD_CONF = expanduser(os.environ.get( 'DRM4G_GWD_CONF' , join( DRM4G_DIR_ETC, 'gwd.conf')))
DRM4G_SCHED_CONF = expanduser(os.environ.get( 'DRM4G_SCHED_CONF' , join( DRM4G_DIR_ETC, 'sched.conf')))
HOME = expanduser(os.environ.get( 'HOME' , '~' ))
DRM4G_DIR = expanduser(os.environ.get( 'DRM4G_DIR' , join( HOME , '.drm4g' )))
DRM4G_DIR_VAR = expanduser(os.environ.get( 'DRM4G_DIR_VAR' , join( DRM4G_DIR , 'var' )))
DRM4G_DIR_ETC = expanduser(os.environ.get( 'DRM4G_DIR_ETC' , join( DRM4G_DIR , 'etc' )))
DRM4G_RESOURCES_CONF = expanduser(os.environ.get( 'DRM4G_RESOURCES_CONF' , join( DRM4G_DIR_ETC , 'resources.conf' )))
DRM4G_LOGGER_CONF = expanduser(os.environ.get( 'DRM4G_LOGGER_CONF' , join( DRM4G_DIR_ETC , 'logger.conf' )))
DRM4G_GWD_CONF = expanduser(os.environ.get( 'DRM4G_GWD_CONF' , join( DRM4G_DIR_ETC , 'gwd.conf' )))
DRM4G_SCHED_CONF = expanduser(os.environ.get( 'DRM4G_SCHED_CONF' , join( DRM4G_DIR_ETC , 'sched.conf' )))

#ENV variable shouldn't be used outside of GWD and its components.
os.environ[ 'GW_LOCATION' ] = DRM4G_DIR

#Populate and prepare DRM4G_DIR
if exists( DRM4G_DIR ) is False :
logging.warning( "Creating a DRM4G local configuration in '%s'" % DRM4G_DIR )
logging.warning( "Creating a DRM4G local configuration in '%s'", DRM4G_DIR )
acct_dir = join ( DRM4G_DIR_VAR, 'acct' )
logging.warning( "Creating '%s' directory" % acct_dir )
logging.warning( "Creating '%s' directory", acct_dir )
os.makedirs( acct_dir )
src_dir = join ( abspath( dirname( __file__ ) ), 'conf' )
logging.warning( "Copying from '%s' to '%s'" % ( src_dir , DRM4G_DIR_ETC ) )
logging.warning( "Copying from '%s' to '%s'", src_dir , DRM4G_DIR_ETC )
copytree( src_dir , DRM4G_DIR_ETC )

##
Expand Down Expand Up @@ -90,5 +87,3 @@
"neptuno" : "drm4g.managers.neptuno",
#"rocci" : "drm4g.managers.rocci",
}


Loading

0 comments on commit 6d2634c

Please sign in to comment.