Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Handle the SIGPIPE signal correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
oldpatricka committed Jan 17, 2013
1 parent 4ab2a9c commit 7c948a4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
5 changes: 3 additions & 2 deletions ceiclient/cli.py
Expand Up @@ -11,6 +11,7 @@
from ceiclient.exception import CeiClientError from ceiclient.exception import CeiClientError
from ceiclient.commands import DASHI_SERVICES, PYON_SERVICES from ceiclient.commands import DASHI_SERVICES, PYON_SERVICES
from ceiclient.connection import DashiCeiConnection, PyonCeiConnection from ceiclient.connection import DashiCeiConnection, PyonCeiConnection
from ceiclient.common import safe_print


DEFAULT_RABBITMQ_USERNAME = 'guest' DEFAULT_RABBITMQ_USERNAME = 'guest'
DEFAULT_RABBITMQ_PASSWORD = 'guest' DEFAULT_RABBITMQ_PASSWORD = 'guest'
Expand Down Expand Up @@ -112,9 +113,9 @@ def main():
raise CeiClientError(e.value) raise CeiClientError(e.value)


if opts.yaml: 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: elif opts.json:
print(json.dumps(result, indent=4)), safe_print(json.dumps(result, indent=4)),
elif opts.details: elif opts.details:
command.details(result) command.details(result)
else: else:
Expand Down
25 changes: 12 additions & 13 deletions ceiclient/commands.py
@@ -1,16 +1,14 @@
import pprint
import re import re
import sys
import yaml import yaml
import time import time
import uuid import uuid


from jinja2 import Template from jinja2 import Template
import yaml


from client import DTRSClient, EPUMClient, HAAgentClient, PDClient, \ from client import DTRSClient, EPUMClient, HAAgentClient, PDClient, \
ProvisionerClient, PyonPDClient, PyonHAAgentClient ProvisionerClient, PyonPDClient, PyonHAAgentClient
from exception import CeiClientError from exception import CeiClientError
from common import safe_print, safe_pprint


# Classes for different kinds of output # Classes for different kinds of output


Expand All @@ -22,35 +20,35 @@ def __init__(self, subparsers):


@staticmethod @staticmethod
def output(result): def output(result):
pprint.pprint(result) safe_pprint(result)


@staticmethod @staticmethod
def details(result): def details(result):
pprint.pprint(result) safe_pprint(result)




class CeiCommandPrintOutput(CeiCommand): class CeiCommandPrintOutput(CeiCommand):


@staticmethod @staticmethod
def output(result): def output(result):
print(result) safe_print(result)


@staticmethod @staticmethod
def details(result): def details(result):
print(result) safe_print(result)




class CeiCommandPrintListOutput(CeiCommand): class CeiCommandPrintListOutput(CeiCommand):


@staticmethod @staticmethod
def output(result): def output(result):
for element in result: for element in result:
print element safe_print(element)


@staticmethod @staticmethod
def details(result): def details(result):
for element in result: for element in result:
print element safe_print(element)




class DTRSAddDT(CeiCommandPrintOutput): class DTRSAddDT(CeiCommandPrintOutput):
Expand Down Expand Up @@ -368,7 +366,7 @@ def execute(client, opts):
@staticmethod @staticmethod
def output(result): def output(result):
template = Template(DescribeDomain.output_template) template = Template(DescribeDomain.output_template)
print template.render(result=result) safe_print(template.render(result=result))




class ListDomains(CeiCommandPrintListOutput): class ListDomains(CeiCommandPrintListOutput):
Expand Down Expand Up @@ -678,15 +676,15 @@ def execute(client, opts):
def output(result): def output(result):
template = Template(PDDescribeProcesses.output_template) template = Template(PDDescribeProcesses.output_template)
for raw_proc in result: for raw_proc in result:
print template.render(result=raw_proc) safe_print(template.render(result=raw_proc))


@staticmethod @staticmethod
def details(result): def details(result):
template = Template(PDDescribeProcesses.details_template) template = Template(PDDescribeProcesses.details_template)
for raw_proc in result: for raw_proc in result:
raw_proc['constraints'] = yaml.safe_dump(raw_proc['constraints']).rstrip('\n') raw_proc['constraints'] = yaml.safe_dump(raw_proc['constraints']).rstrip('\n')
raw_proc['configuration'] = yaml.safe_dump(raw_proc['configuration']).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): class PDTerminateProcess(CeiCommand):
Expand Down Expand Up @@ -744,7 +742,8 @@ def output(result):
template = Template(PDDescribeProcess.output_template) template = Template(PDDescribeProcess.output_template)
result['constraints'] = yaml.safe_dump(result['constraints']).rstrip('\n') result['constraints'] = yaml.safe_dump(result['constraints']).rstrip('\n')
result['configuration'] = yaml.safe_dump(result['configuration']).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): class PDWaitProcess(CeiCommand):
Expand Down
20 changes: 20 additions & 0 deletions ceiclient/common.py
@@ -1,5 +1,25 @@
import os 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): def load_cloudinitd_db(run_name):


Expand Down

0 comments on commit 7c948a4

Please sign in to comment.