def read(): response = Response() parameters = addict.Dict(request.get_json()) parameters.path = os.path.abspath(parameters.path) if parameters.path else ABSPATH_STARTDIR if parameters.name and parameters.format: path = os.path.join(parameters.path, parameters.name) if os.path.exists(path): if parameters.format == 'cdata': cdat = cdata.read(path) data = cdat.to_dict() response.set_data(data) elif parameters.format in ['pipeline', 'gist']: try: data = JSON.read(path) except json.decoder.JSONDecodeError as e: data = [ ] response.set_data(data) else: response.set_error(Response.Error.UNPROCESSABLE_ENTITY, 'Here') else: response.set_error(Response.Error.NOT_FOUND, 'File does not exist.') else: response.set_error(Response.Error.UNPROCESSABLE_ENTITY, 'There') dict_ = response.to_dict() json_ = jsonify(dict_) code = response.code return json_, code
def pmethods(): response = Response() path = os.path.join(R.Path.DATA, 'preprocess-methods.json') methods = JSON.read(path) response.set_data(methods) dict_ = response.to_dict() json_ = jsonify(dict_) code = response.code return json_, code
# imports - standard imports import os, csv # imports - module imports from candis.resource import R from candis.ios import json as JSON ATTRIBUTE_TYPES = JSON.read(os.path.join(R.Path.DATA, 'attribute-types.json')) def get_attribute_tag(attr): tag = None if 'type' in attr: for attp in ATTRIBUTE_TYPES: if attr['type'] == attp['name']: tag = attp['tag'] return tag def write(path, dataset, delimiter=','): with open(path, mode='w') as f: writer = csv.writer(f, delimiter=delimiter) cnames = [] for attr in dataset['attributes']: tag = get_attribute_tag(attr) name = attr['name'] cname = (tag + ' ' + name) if tag else name
# imports - standard imports import os, csv # imports - module imports from candis.resource import R from candis.ios import json as JSON ATTRIBUTE_TYPES = JSON.read(os.path.join(R.Path.DATA, 'attribute-types.json')) def get_attribute_tag(attr): tag = None if 'type' in attr: for attp in ATTRIBUTE_TYPES: if attr['type'] == attp['name']: tag = attp['tag'] return tag def write(path, dataset, delimiter = ','): with open(path, mode = 'w') as f: writer = csv.writer(f, delimiter = delimiter) cnames = [ ] for attr in dataset['attributes']: tag = get_attribute_tag(attr) name = attr['name'] cname = (tag + ' ' + name) if tag else name cnames.append(cname)
def get_config(self): path = os.path.join(self.location, self.dirname, 'config.json') para = JSON.read(path) return para
def read(path): pipeline = JSON.read(path) return pipeline
# imports - third-party imports from flask import request, jsonify import addict # imports - module imports from candis.config import CONFIG from candis.util import ( assign_if_none, get_rand_uuid_str, get_timestamp_str, merge_dicts ) from candis.resource import R from candis.ios import cdata, pipeline from candis.ios import json as JSON from candis.app.server.app import app from candis.app.server.response import Response FFORMATS = JSON.read(os.path.join(R.Path.DATA, 'file-formats.json')) ABSPATH_STARTDIR = os.path.abspath(CONFIG.App.STARTDIR) def get_filename_if_exists(filename, count = 1, format_ = ' ({count})'): name, extension = os.path.splitext(filename) if os.path.exists(filename): format_ = '{name}{format_}{extension}'.format( name = name, format_ = format_, extension = extension ) while os.path.exists(format_.format(count = count)): count += 1