24
24
from ci_libs import (
29
from ci_libs.file_handler import (ChangesFileNotFound, ChangesFileException,
30
ChangesParseError, ChangesValidationError,
31
FileToUploadNotFound, NotAChangesFileError,
33
from ci_libs.ticket import new_ticket
34
from ci_utils.data_store import DataStoreException
35
from ci_utils import dump_stack
37
DEF_CFG = os.path.join(os.environ["HOME"], '.ubuntu-ci')
31
from ci_utils import dump_stack, data_store
40
34
def parse_arguments(args=None):
65
59
'in the same directory as their respective '
66
60
'source.changes.', required=True)
68
ticket_parser.set_defaults(func=new_ticket)
62
ticket_parser.set_defaults(func=ticket.new_ticket)
69
63
status_parser = subparsers.add_parser('status',
70
64
help='Get ticket status. Use no '
71
65
'flags for all tickets')
73
67
help='Ticket to display status of. Leave off '
75
69
status_parser.set_defaults(func=status.ticket_status)
70
image_parser = subparsers.add_parser('get_image',
71
help='Retrieve the image produced by '
73
image_parser.add_argument('-t', '--ticket',
74
help='Ticket to display status of. Leave off '
75
'for last successful ticket')
76
image_parser.add_argument('-n', '--name',
77
help='Desired file name (and path) for the '
78
'downloaded image', required=True)
79
image_parser.set_defaults(func=image.get_image)
76
80
return parser.parse_args(args)
105
109
# files are found.
106
110
for source in args.sources:
107
111
if not os.path.exists(source):
108
raise ChangesFileNotFound(source)
112
raise file_handler.ChangesFileNotFound(source)
109
113
if not source.endswith(".changes"):
110
raise NotAChangesFileError(source)
114
raise file_handler.NotAChangesFileError(source)
111
115
# Validating -a option is properly formatted.
112
116
utils.assert_valid_package_list(args.add)
113
117
# Validating -r option is properly formatted.
117
121
# We're not in create_ticket context, moving on.
120
utils.load_config(DEF_CFG)
124
utils.load_config(utils.DEF_CFG)
123
127
except utils.InputError as exc:
125
except ChangesFileNotFound as exc:
129
except file_handler.ChangesFileNotFound as exc:
126
130
log.error("Changes file not found: {}".format(exc))
127
except NotAChangesFileError as exc:
131
except file_handler.NotAChangesFileError as exc:
128
132
log.error("Upload file must be a .changes; you provided "
129
133
"'{}'".format(exc))
130
except (ChangesFileException, ChangesParseError) as exc:
134
except (file_handler.ChangesFileException,
135
file_handler.ChangesParseError) as exc:
131
136
log.error("Problem parsing .changes file, are you sure it's a valid "
132
137
".changes? ({})".format(str(exc)))
133
except ChangesValidationError as exc:
138
except file_handler.ChangesValidationError as exc:
134
139
log.error("Problem validating .changes file: {}".format(exc))
135
except UploadDirNotFound as exc:
140
except file_handler.UploadDirNotFound as exc:
136
141
log.error("Directory with files to upload not found: {}".format(exc))
137
except FileToUploadNotFound as exc:
142
except file_handler.FileToUploadNotFound as exc:
138
143
log.error("File to upload not found: {}. Maybe a wrong or missing "
139
144
"-f?".format(exc))
140
145
except httplib.BadStatusLine as exc:
141
146
log.error("Server at {} replied with an empty response. Is 'ci_url' "
142
147
"pointing to the correct service?".format(utils.CI_URL))
148
except image.ImageObjectNotFound as exc:
149
log.error("Image cannot be downloaded: {} ({})".format(exc.filename,
143
151
except urllib2.URLError as exc:
144
152
if isinstance(exc, urllib2.HTTPError):
145
153
reason = exc.reason
157
165
log.error("Cannot reach the server at {}. Please, check your "
158
166
"configuration file ({}): is 'ci_url' correctly set? "
159
167
"Is the server up and reachable from this machine? "
160
"({}).".format(utils.CI_URL, DEF_CFG, reason))
161
except DataStoreException as exc:
168
"({}).".format(utils.CI_URL, utils.DEF_CFG, reason))
169
except data_store.DataStoreException as exc:
162
170
log.error("Data Store Error: {}".format(exc))
163
171
except Exception:
164
172
log.exception('Unexpected exception')