Skip to content

Commit

Permalink
Merge pull request #49 from grrtrr/CAM_13224
Browse files Browse the repository at this point in the history
[CAM-13224]: use pylint and futurize to make code Python3-ready
  • Loading branch information
EfrenRey authored Apr 9, 2020
2 parents f4dba40 + a0e1825 commit 707e8b1
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This repository contains a *Python SDK* and a command line interface *CLI* (base
## Installing

### Via Python's pip
Cross-platform installation is available via pypi. Requires *Python 2.7* - this is not currently compatible with Python 3.
Cross-platform installation is available via pypi.
If you have pip already installed the following command will get you running:
```
> pip install clc-sdk
Expand Down
241 changes: 241 additions & 0 deletions src/.pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
[MASTER]

# Profiled execution.
profile=no

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=


# Pickle collected data for later comparisons.
persistent=no

[MESSAGES CONTROL]

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time.
#enable=

# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
# FIXME: I had to silence many more things than necessary. Everything after
# 'too-many-arguments' should be removed, and code re-checked.
disable=missing-docstring, no-name-in-module, locally-disabled, no-self-use, too-many-ancestors, too-many-public-methods, protected-access, arguments-differ, no-init, global-statement, logging-format-interpolation, bare-except, broad-except, no-member, too-many-nested-blocks, redefined-variable-type, len-as-condition, bad-continuation, bad-whitespace, invalid-name, too-many-arguments, mixed-indentation,multiple-statements,trailing-newlines,fixme,dangerous-default-value,redefined-builtin,attribute-defined-outside-init, superfluous-parens,

[REPORTS]

# Set the output format. Available formats are text, parseable, colorized, msvs
# (visual studio) and html. You can also give a reporter class, eg
# mypackage.mymodule.MyReporterClass.
output-format=text

# Include message's id in output
include-ids=yes

# Include symbolic ids of messages in output
symbols=yes

# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no

# Tells whether to display a full report or only the messages
reports=no

# Python expression which should return a note less than 10 (10 is the highest
# note). You have access to the variables errors warning, statement which
# respectively contain the number of errors / warnings messages and the total
# number of statements analyzed. This is used by the global evaluation report
# (RP0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)

# Add a comment according to your evaluation note. This is used by the global
# evaluation report (RP0004).
comment=no


[BASIC]
# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter,apply,input

# Regular expression which should only match correct module names
module-rgx=(([0-9\-]+)|([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Regular expression which should only match correct module level names
const-rgx=(([a-z_][a-z0-9_]*)|([A-Z_][A-Z0-9_]*)|(__.*__))$

# Regular expression which should only match correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$

# Regular expression which should only match correct function names
function-rgx=[a-z_][a-z0-9_]{2,80}$

# Regular expression which should only match correct method names
method-rgx=[a-z_][a-z0-9_]{2,80}$

# Regular expression which should only match correct instance attribute names
attr-rgx=(([A-Z_][A-Z0-9_]{2,40})|([a-z_][a-z0-9_]{2,40}))$

# Regular expression which should only match correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,40}$

# Regular expression which should only match correct variable names
variable-rgx=[a-z_][a-z0-9_]{2,40}$

# Regular expression which should only match correct list comprehension /
# generator expression variable names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$

# Good variable names which should always be accepted, separated by a comma
good-names=a,b,c,e,f,i,j,k,m,n,p,q,v,x,y,_,cn,db,dc,dn,es,ex,fd,fn,ns,os,rc,id,ip,iv,vm,tz,hi,lo,cc,ws,pg

# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata

# Regular expression which should only match functions or classes name which do
# not require a docstring
no-docstring-rgx=__.*__


[FORMAT]

# Maximum number of characters on a single line.
max-line-length=210

# Maximum number of lines in a module
max-module-lines=1800

# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
# tab).
indent-string=' '


[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
notes=TODO


[SIMILARITIES]

# Minimum lines number of a similarity.
min-similarity-lines=1000

# Ignore comments when computing similarities.
ignore-comments=yes

# Ignore docstrings when computing similarities.
ignore-docstrings=yes

# Ignore imports when computing similarities.
ignore-imports=yes


[TYPECHECK]

# Tells whether missing members accessed in mixin class should be ignored. A
# mixin class is detected if its name ends with "mixin" (case insensitive).
ignore-mixin-members=yes

# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set).
ignored-classes=

# When zope mode is activated, add a predefined set of Zope acquired attributes
# to generated-members.
zope=no

# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed. Python regular
# expressions are accepted.
generated-members=


[VARIABLES]

# Tells whether we should check for unused import in __init__ files.
init-import=no

# A regular expression matching the beginning of the name of dummy variables
# (i.e. not used).
dummy-variables-rgx=_|dummy

# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
additional-builtins=


[CLASSES]

# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,setUp

# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls

# List of valid names for the first argument in a metaclass class method.
valid-metaclass-classmethod-first-arg=mcs


[DESIGN]

# Maximum number of arguments for function / method
max-args=7

# Argument names that match this expression will be ignored. Default to name
# with leading underscore
ignored-argument-names=_.*

# Maximum number of locals for function / method body
max-locals=15

# Maximum number of return / yield for function / method body
max-returns=6

# Maximum number of branch for function / method body
max-branchs=12

# Maximum number of statements in function / method body
max-statements=50

# Maximum number of parents for a class (see R0901).
max-parents=7

# Maximum number of attributes for a class (see R0902).
max-attributes=7

# Minimum number of public methods for a class (see R0903).
min-public-methods=1

# Maximum number of public methods for a class (see R0904).
max-public-methods=20


[IMPORTS]

# Deprecated modules which should not be used, separated by a comma
deprecated-modules=regsub,string,TERMIOS,Bastion,rexec

# Create a graph of every (i.e. internal and external) dependencies in the
# given file (report RP0402 must not be disabled)
import-graph=

# Create a graph of external dependencies in the given file (report RP0402 must
# not be disabled)
ext-import-graph=

# Create a graph of internal dependencies in the given file (report RP0402 must
# not be disabled)
int-import-graph=


[EXCEPTIONS]

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
1 change: 1 addition & 0 deletions src/clc/APIv2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
API Documentaton v2: https://t3n.zendesk.com/categories/20067994-API-v2-0-Beta-
"""
from __future__ import print_function, absolute_import, unicode_literals
import requests

import clc.defaults
Expand Down
3 changes: 2 additions & 1 deletion src/clc/APIv2/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
account.is_managed
"""
from __future__ import print_function, absolute_import, unicode_literals

# TODO - change account
# TODO - delete account
Expand All @@ -29,7 +30,7 @@
import re
import clc

class Account:
class Account(object):

@staticmethod
def GetAlias(session=None):
Expand Down
6 changes: 2 additions & 4 deletions src/clc/APIv2/alert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Alert related functions.
Alert related functions.
Alerts object variables:
Expand All @@ -10,15 +10,13 @@
alert.server (optional server name already mapped to policy)
"""
from __future__ import print_function, absolute_import, unicode_literals

# TODO - Alerts filter by server, type (RAM, Disk, etc.)
# TODO - Alert map/unmap
# TODO - Alert delete
# TODO - Alert create - missing API spec

import clc


class Alerts(object):

def __init__(self,alerts_lst,server=None):
Expand Down
7 changes: 4 additions & 3 deletions src/clc/APIv2/anti_affinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
antiaffinity.servers
"""
from __future__ import print_function, absolute_import, unicode_literals

# TODO - Update Anti-Affinity Policy - returning 500 error
# TODO - Create Anti-Affinity Policy - returning 400 error
# TODO - Return servers object


import clc
import json
import clc

class AntiAffinity(object):

Expand Down Expand Up @@ -121,7 +122,7 @@ def Update(self,name):
"""

r = clc.v2.API.Call('PUT','antiAffinityPolicies/%s/%s' % (self.alias,self.id),{'name': name},session=self.session)
_ = clc.v2.API.Call('PUT','antiAffinityPolicies/%s/%s' % (self.alias,self.id),{'name': name},session=self.session)
self.name = name


Expand All @@ -133,7 +134,7 @@ def Delete(self):
>>> a = clc.v2.AntiAffinity.GetLocation("WA1")[0]
>>> a.Delete()
"""
r = clc.v2.API.Call('DELETE','antiAffinityPolicies/%s/%s' % (self.alias,self.id),{},session=self.session)
_ = clc.v2.API.Call('DELETE','antiAffinityPolicies/%s/%s' % (self.alias,self.id),{},session=self.session)


def __str__(self):
Expand Down
12 changes: 6 additions & 6 deletions src/clc/APIv2/api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
"""Private class that executes API calls."""
from __future__ import print_function, absolute_import, unicode_literals

import requests
import xml.etree.ElementTree
import clc
import os
import sys
import clc
import requests


class API():
class API(object):

# requests module includes cacert.pem which is visible when run as installed module.
# pyinstall single-file deployment needs cacert.pem packaged along and referenced.
Expand Down Expand Up @@ -84,7 +84,7 @@ def _Login():


@staticmethod
def Call(method,url,payload=None,session=None,debug=False):
def Call(method,url,payload=None,session=None,debug=False): # pylint: disable=too-many-branches
"""Execute v2 API call.
:param url: URL paths associated with the API call
Expand Down Expand Up @@ -112,7 +112,7 @@ def Call(method,url,payload=None,session=None,debug=False):

http_session.headers.update({'Authorization': "Bearer %s" % token})

if isinstance(payload, basestring): http_session.headers['content-type'] = "Application/json" # added for server ops with str payload
if isinstance(payload, str): http_session.headers['content-type'] = "Application/json" # added for server ops with str payload
else: http_session.headers['content-type'] = "application/x-www-form-urlencoded"

if method=="GET":
Expand Down
5 changes: 3 additions & 2 deletions src/clc/APIv2/datacenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
datacenter.supports_shared_load_balancer
"""
from __future__ import print_function, absolute_import, unicode_literals

# TODO - init link to billing, statistics, scheduled activities
# TODO - accounts link?

import re
import clc

class Datacenter:
class Datacenter(object): # pylint: disable=too-many-instance-attributes

@staticmethod
def Datacenters(alias=None, session=None):
Expand Down Expand Up @@ -64,7 +65,7 @@ def __init__(self,location=None,name=None,alias=None,session=None):
else:
self.location = clc.v2.Account.GetLocation(session=self.session)

if False:
if False: # pylint: disable=using-constant-test
# prepopulated info
self.name = name
self.location = location
Expand Down
Loading

0 comments on commit 707e8b1

Please sign in to comment.