Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions .github/linters/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[flake8]
Comment thread
jbampton marked this conversation as resolved.
select = W291
31 changes: 31 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Lint Code Base
Comment thread
jbampton marked this conversation as resolved.

on: [pull_request]

jobs:
build:
name: GitHub Super Linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: github/super-linter@v4
env:
VALIDATE_PYTHON_FLAKE8: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions cloud-cli/cloudapis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.



'''
Created on Aug 2, 2010
Expand Down
22 changes: 11 additions & 11 deletions cloud-cli/cloudtool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.



'''
Created on Aug 2, 2010
Expand All @@ -26,16 +26,16 @@
import cloudapis as apis
import cloudtool.utils as utils


def main(argv=None):

#import ipdb; ipdb.set_trace()
if argv == None:
argv = sys.argv

prelim_args = [ x for x in argv[0:] if not x.startswith('-') ]
parser = utils.get_parser()

api = __import__("cloudapis")
apis = getattr(api, "implementor")
if len(prelim_args) == 1:
Expand All @@ -44,20 +44,20 @@ def main(argv=None):

command = utils.lookup_command_in_api(apis,prelim_args[1])
if not command: parser.error("command %r not supported by the %s API"%(prelim_args[1],prelim_args[0]))
argv = argv[1:]

argv = argv[1:]
if len(argv) == 1:
argv.append("--help")

parser = utils.get_parser(apis.__init__,command)
opts,args,api_optionsdict,cmd_optionsdict = parser.parse_args(argv)


try:
api = apis(**api_optionsdict)
except utils.OptParseError as e:
parser.error(str(e))

command = utils.lookup_command_in_api(api,args[0])

# we now discard the first two arguments as those necessarily are the api and command names
Expand Down
38 changes: 19 additions & 19 deletions cloud-cli/cloudtool/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.



'''
Created on Aug 2, 2010
Expand Down Expand Up @@ -48,28 +48,28 @@ def error(self, msg):
error("%s: %s\n" % (self.get_prog_name(),msg))
self.print_usage(sys.stderr)
self.exit(os.EX_USAGE)

def parse_args(self,*args,**kwargs):
options,arguments = OptionParser.parse_args(self,*args,**kwargs)

def prune_options(options,alist):
"""Given 'options' -- a list of arguments to OptionParser.add_option,
and a set of optparse Values, return a dictionary of only those values
that apply exclusively to 'options'"""
return dict( [ (k,getattr(options,k)) for k in dir(options) if k in alist ] )

api_options = prune_options(options,self.api_dests)
cmd_options = prune_options(options,self.cmd_dests)

return options,arguments,api_options,cmd_options


def get_parser(api_callable=None,cmd_callable=None): # this should probably be the __init__ method of myoptionparser

def getdefaulttag(default):
if default is not None: return " [Default: %default]"
return ''

def get_arguments_and_options(callable):
"""Infers and returns arguments and options based on a callable's signature.
Cooperates with decorator @describe"""
Expand All @@ -96,37 +96,37 @@ def get_arguments_and_options(callable):
return arguments,options

basic_usage = "usage: %prog [options...] "

api_name = "<api>"
cmd_name = "<command>"
description = "%prog is a command-line tool to access several cloud APIs."
arguments = ''
argexp = ""

if api_callable:
api_name = api_callable.__module__.split(".")[-1].replace("_","-")
api_arguments,api_options = get_arguments_and_options(api_callable)
assert len(api_arguments) is 0 # no mandatory arguments for class initializers

if cmd_callable:
cmd_name = cmd_callable.__name__.replace("_","-")
cmd_arguments,cmd_options = get_arguments_and_options(cmd_callable)
if cmd_arguments:
arguments = " " + " ".join( [ s[0].upper() for s in cmd_arguments ] )
argexp = "\n\nArguments:\n" + "\n".join ( " %s\n %s"%(s.upper(),u) for s,u in cmd_arguments )
description = cmd_callable.__doc__

api_command = "%s %s"%(api_name,cmd_name)

if description: description = "\n\n" + description
else: description = ''

usage = basic_usage + api_command + arguments + description + argexp

parser = MyOptionParser(usage=usage, add_help_option=False)

parser.add_option('--help', action="help")

group = parser.add_option_group("General options")
group.add_option('-v', '--verbose', dest="verbose", help="Print extra output")

Expand All @@ -136,14 +136,14 @@ def get_arguments_and_options(callable):
for a in api_options:
group.add_option(a[0][0],**a[1])
parser.api_dests.append(a[1]["dest"])

parser.cmd_dests = []
if cmd_callable and cmd_options:
group = parser.add_option_group("Options for the %s command"%cmd_name)
for a in cmd_options:
group.add_option(a[0][0],**a[1])
parser.cmd_dests.append(a[1]["dest"])

return parser

def lookup_command_in_api(api,command_name):
Expand All @@ -155,7 +155,7 @@ def get_api_list(api):
for cmd_name in dir(api):
cmd = getattr(api,cmd_name)
if callable(cmd) and not cmd_name.startswith("_"):
apilist.append(cmd_name)
apilist.append(cmd_name)
return apilist

def get_command_list(api):
Expand Down
Loading