Standardize Formatting
[osm/osmclient.git] / osmclient / sol005 / project.py
index ed781fa..3658772 100644 (file)
@@ -30,31 +30,30 @@ class Project(object):
     def __init__(self, http=None, client=None):
         self._http = http
         self._client = client
-        self._logger = logging.getLogger('osmclient')
-        self._apiName = '/admin'
-        self._apiVersion = '/v1'
-        self._apiResource = '/projects'
-        self._apiBase = '{}{}{}'.format(self._apiName,
-                                        self._apiVersion, self._apiResource)
+        self._logger = logging.getLogger("osmclient")
+        self._apiName = "/admin"
+        self._apiVersion = "/v1"
+        self._apiResource = "/projects"
+        self._apiBase = "{}{}{}".format(
+            self._apiName, self._apiVersion, self._apiResource
+        )
 
     def create(self, name, project):
-        """Creates a new OSM project
-        """
+        """Creates a new OSM project"""
         self._logger.debug("")
         self._client.get_token()
-        http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
-                                              postfields_dict=project,
-                                              skip_query_admin=True)
-        #print('HTTP CODE: {}'.format(http_code))
-        #print('RESP: {}'.format(resp))
-        #if http_code in (200, 201, 202, 204):
+        http_code, resp = self._http.post_cmd(
+            endpoint=self._apiBase, postfields_dict=project, skip_query_admin=True
+        )
+        # print('HTTP CODE: {}'.format(http_code))
+        # print('RESP: {}'.format(resp))
+        # if http_code in (200, 201, 202, 204):
         if resp:
             resp = json.loads(resp)
-        if not resp or 'id' not in resp:
-            raise ClientException('unexpected response from server - {}'.format(
-                                  resp))
-        print(resp['id'])
-        #else:
+        if not resp or "id" not in resp:
+            raise ClientException("unexpected response from server - {}".format(resp))
+        print(resp["id"])
+        # else:
         #    msg = ""
         #    if resp:
         #        try:
@@ -64,26 +63,28 @@ class Project(object):
         #    raise ClientException("failed to create project {} - {}".format(name, msg))
 
     def update(self, project, project_changes):
-        """Updates an OSM project identified by name
-        """
+        """Updates an OSM project identified by name"""
         self._logger.debug("")
         self._client.get_token()
         proj = self.get(project)
-        http_code, resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase, proj['_id']),
-                                             postfields_dict=project_changes,
-                                             skip_query_admin=True)
+        http_code, resp = self._http.patch_cmd(
+            endpoint="{}/{}".format(self._apiBase, proj["_id"]),
+            postfields_dict=project_changes,
+            skip_query_admin=True,
+        )
         # print('HTTP CODE: {}'.format(http_code))
         # print('RESP: {}'.format(resp))
         if http_code in (200, 201, 202):
             if resp:
                 resp = json.loads(resp)
-            if not resp or 'id' not in resp:
-                raise ClientException('unexpected response from server - {}'.format(
-                                      resp))
-            print(resp['id'])
+            if not resp or "id" not in resp:
+                raise ClientException(
+                    "unexpected response from server - {}".format(resp)
+                )
+            print(resp["id"])
         elif http_code == 204:
             print("Updated")
-        #else:
+        # else:
         #    msg = ""
         #    if resp:
         #        try:
@@ -93,25 +94,25 @@ class Project(object):
         #    raise ClientException("failed to update project {} - {}".format(project, msg))
 
     def delete(self, name, force=False):
-        """Deletes an OSM project identified by name
-        """
+        """Deletes an OSM project identified by name"""
         self._logger.debug("")
         self._client.get_token()
         project = self.get(name)
-        querystring = ''
+        querystring = ""
         if force:
-            querystring = '?FORCE=True'
-        http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
-                                                project['_id'], querystring),
-                                                skip_query_admin=True)
-        #print('HTTP CODE: {}'.format(http_code))
-        #print('RESP: {}'.format(resp))
+            querystring = "?FORCE=True"
+        http_code, resp = self._http.delete_cmd(
+            "{}/{}{}".format(self._apiBase, project["_id"], querystring),
+            skip_query_admin=True,
+        )
+        # print('HTTP CODE: {}'.format(http_code))
+        # print('RESP: {}'.format(resp))
         if http_code == 202:
-            print('Deletion in progress')
+            print("Deletion in progress")
         elif http_code == 204:
-            print('Deleted')
-        elif resp and 'result' in resp:
-            print('Deleted')
+            print("Deleted")
+        elif resp and "result" in resp:
+            print("Deleted")
         else:
             msg = resp or ""
             # if resp:
@@ -122,32 +123,30 @@ class Project(object):
             raise ClientException("failed to delete project {} - {}".format(name, msg))
 
     def list(self, filter=None):
-        """Returns the list of OSM projects
-        """
+        """Returns the list of OSM projects"""
         self._logger.debug("")
         self._client.get_token()
-        filter_string = ''
+        filter_string = ""
         if filter:
-            filter_string = '?{}'.format(filter)
-        _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string),
-                                                    skip_query_admin=True)
-        #print('RESP: {}'.format(resp))
+            filter_string = "?{}".format(filter)
+        _, resp = self._http.get2_cmd(
+            "{}{}".format(self._apiBase, filter_string), skip_query_admin=True
+        )
+        # print('RESP: {}'.format(resp))
         if resp:
             return json.loads(resp)
         return list()
 
     def get(self, name):
-        """Returns a specific OSM project based on name or id
-        """
+        """Returns a specific OSM project based on name or id"""
         self._logger.debug("")
         self._client.get_token()
         if utils.validate_uuid4(name):
             for proj in self.list():
-                if name == proj['_id']:
+                if name == proj["_id"]:
                     return proj
         else:
             for proj in self.list():
-                if name == proj['name']:
+                if name == proj["name"]:
                     return proj
         raise NotFound("Project {} not found".format(name))
-