Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle the SIGPIPE signal correctly

  • Loading branch information...
commit 7c948a4ef134ac2299935bb1578d4a5ba2dca57b 1 parent 4ab2a9c
@oldpatricka oldpatricka authored
Showing with 35 additions and 15 deletions.
  1. +3 −2 ceiclient/cli.py
  2. +12 −13 ceiclient/commands.py
  3. +20 −0 ceiclient/common.py
View
5 ceiclient/cli.py
@@ -11,6 +11,7 @@
from ceiclient.exception import CeiClientError
from ceiclient.commands import DASHI_SERVICES, PYON_SERVICES
from ceiclient.connection import DashiCeiConnection, PyonCeiConnection
+from ceiclient.common import safe_print
DEFAULT_RABBITMQ_USERNAME = 'guest'
DEFAULT_RABBITMQ_PASSWORD = 'guest'
@@ -112,9 +113,9 @@ def main():
raise CeiClientError(e.value)
if opts.yaml:
- print(yaml.safe_dump(result, default_flow_style=False)),
+ safe_print(yaml.safe_dump(result, default_flow_style=False)),
elif opts.json:
- print(json.dumps(result, indent=4)),
+ safe_print(json.dumps(result, indent=4)),
elif opts.details:
command.details(result)
else:
View
25 ceiclient/commands.py
@@ -1,16 +1,14 @@
-import pprint
import re
-import sys
import yaml
import time
import uuid
from jinja2 import Template
-import yaml
from client import DTRSClient, EPUMClient, HAAgentClient, PDClient, \
ProvisionerClient, PyonPDClient, PyonHAAgentClient
from exception import CeiClientError
+from common import safe_print, safe_pprint
# Classes for different kinds of output
@@ -22,22 +20,22 @@ def __init__(self, subparsers):
@staticmethod
def output(result):
- pprint.pprint(result)
+ safe_pprint(result)
@staticmethod
def details(result):
- pprint.pprint(result)
+ safe_pprint(result)
class CeiCommandPrintOutput(CeiCommand):
@staticmethod
def output(result):
- print(result)
+ safe_print(result)
@staticmethod
def details(result):
- print(result)
+ safe_print(result)
class CeiCommandPrintListOutput(CeiCommand):
@@ -45,12 +43,12 @@ class CeiCommandPrintListOutput(CeiCommand):
@staticmethod
def output(result):
for element in result:
- print element
+ safe_print(element)
@staticmethod
def details(result):
for element in result:
- print element
+ safe_print(element)
class DTRSAddDT(CeiCommandPrintOutput):
@@ -368,7 +366,7 @@ def execute(client, opts):
@staticmethod
def output(result):
template = Template(DescribeDomain.output_template)
- print template.render(result=result)
+ safe_print(template.render(result=result))
class ListDomains(CeiCommandPrintListOutput):
@@ -678,7 +676,7 @@ def execute(client, opts):
def output(result):
template = Template(PDDescribeProcesses.output_template)
for raw_proc in result:
- print template.render(result=raw_proc)
+ safe_print(template.render(result=raw_proc))
@staticmethod
def details(result):
@@ -686,7 +684,7 @@ def details(result):
for raw_proc in result:
raw_proc['constraints'] = yaml.safe_dump(raw_proc['constraints']).rstrip('\n')
raw_proc['configuration'] = yaml.safe_dump(raw_proc['configuration']).rstrip('\n')
- print template.render(result=raw_proc)
+ safe_print(template.render(result=raw_proc))
class PDTerminateProcess(CeiCommand):
@@ -744,7 +742,8 @@ def output(result):
template = Template(PDDescribeProcess.output_template)
result['constraints'] = yaml.safe_dump(result['constraints']).rstrip('\n')
result['configuration'] = yaml.safe_dump(result['configuration']).rstrip('\n')
- print template.render(result=result)
+ safe_print(template.render(result=result))
+
class PDWaitProcess(CeiCommand):
View
20 ceiclient/common.py
@@ -1,5 +1,25 @@
import os
+import sys
+import errno
+import pprint
+def safe_print(p_str):
+ try:
+ print(p_str)
+ except IOError, e:
+ if e.errno == errno.EPIPE:
+ sys.exit(0)
+ else:
+ raise
+
+def safe_pprint(p_str):
+ try:
+ pprint.pprint(p_str)
+ except IOError, e:
+ if e.errno == errno.EPIPE:
+ sys.exit(0)
+ else:
+ raise
def load_cloudinitd_db(run_name):
Please sign in to comment.
Something went wrong with that request. Please try again.