def main(self, args): url = ''.join([self.base_url, self.url_suffix]) try: with open(args.svg, 'r') as f: svg = f.read() except: raise CommandError('SVG file not found') data = { 'svg': svg, 'filename': args.filename, 'format': { 'type': args.format, 'dpi': args.dpi } } r = requests.post(url, headers=self.headers, data=json.dumps(data)) if r.status_code >= 400: raise CommandError('Error while processing command {}: {}'.format( self.name, r.text)) return self.result(r)
def main(self, args): def __input_and_check(label): while True: x = input('Enter {}: '.format(label)) check = input('Confim {}: '.format(label)) if x == check: return x print('Mismatched ! Please reenter {}'.format(label)) user = __input_and_check('user name') email = __input_and_check('email') while True: role = input('Enter role: ') if role in ( 'read', 'write', 'admin', ): break print('Bad value ! Only read, write and admin are supported') url = ''.join([self.auth_url, self.url_suffix]) r = requests.post(url, json={ 'user': user, 'email': email, 'role': role }, headers=self.headers) if r.status_code >= 400: raise CommandError('Error while processing command {}: {}'.format( self.name, r.text)) return self.result(r)
def main(self, args): resolved_suffix = self.url_suffix.replace('<id>', args.id) url = ''.join([self.base_url, resolved_suffix]) try: with open(args.file, 'r') as f: data = yaml.load(f.read()) except: raise CommandError('Command configuration file not found') r = requests.post(url, headers=self.headers, data=json.dumps(data)) if r.status_code >= 400: raise CommandError('Error while processing command {}: {}'.format( self.name, r.text)) return self.result(r)
def main(self, args): try: with open(args.file, 'r', encoding='utf-8') as f: svg = f.read() except: raise CommandError('HTML file not found') resolved_suffix = self.url_suffix.replace('<id>', args.id) url = ''.join([self.base_url, resolved_suffix]) r = requests.post(url, data=json.dumps({'svg': svg}), headers=self.headers) if r.status_code >= 400: raise CommandError('Error while processing command {}: {}'.format( self.name, r.text)) return self.result(r)
def main(self, args): try: with open(args.file, encoding='utf-8') as f: data = yaml.load(f.read()) except: raise CommandError('Command configuration file not found') for r in data: resolved_suffix = self.url_suffix.replace('<id>', r['id']) url = ''.join([self.base_url, resolved_suffix]) req = requests.post(url, data=json.dumps(r), headers=self.headers) if req.status_code >= 400: raise CommandError( 'Error while processing command {}: {}'.format( self.name, req.text)) return self.result(req)
def main(self, args): resolved_suffix = self.url_suffix.replace('<id>', args.id) url = ''.join([self.auth_url, resolved_suffix]) r = requests.put(url, headers=self.headers, json={'password': True}) if r.status_code >= 400: raise CommandError('Error while processing command {}: {}'.format( self.name, r.text)) return self.result(r)
def main(self, args): resolved_suffix = self.url_suffix.replace('<template_id>', args.template_id)\ .replace('<query_id>', args.query_id) url = ''.join([self.base_url, resolved_suffix]) r = requests.delete(url, headers=self.headers) if r.status_code >= 400: raise CommandError('Error while processing command {}: {}'.format( self.name, r.text)) return self.result(r)
def main(self, args): resolved_suffix = self.url_suffix.replace('<label_id>', args.label_id)\ .replace('<language>', args.language)\ .replace('<context>', args.context) url = ''.join([self.base_url, resolved_suffix]) r = requests.get(url, headers=self.headers) if r.status_code >= 400: raise CommandError('Error while processing command {}: {}'.format( self.name, r.text)) return self.result(r)
def main(self, args): url = ''.join([self.base_url, self.url_suffix]) params = { 'query': args.query, 'type': args.type, 'provider': args.provider } r = requests.get(url, headers=self.headers, params=params) if r.status_code >= 400: raise CommandError('Error while processing command {}: {}'.format( self.name, r.text)) return self.result(r)
def main(self, args): import base64 with open(args.file, 'rb') as f: picture = base64.b64encode( f.read()) if args.kind == 'bitmap' else f.read() resolved_suffix = self.url_suffix.replace('<id>', args.id) url = ''.join([self.base_url, resolved_suffix]) r = requests.post(url, headers=self.headers, data=json.dumps({ 'id': args.id, 'context': args.context, 'format': args.format, 'kind': args.kind, 'content': picture.decode('utf-8') })) if r.status_code >= 400: raise CommandError('Error while processing command {}: {}'.format( self.name, r.text)) return self.result(r)