def build_classes(self,strict=False, named_only=False, standardize_names=True):
        """
        Build all of the classes named in the JSONSchema.

        Class names will be transformed using inflection by default, so names
        with spaces in the schema will be camelcased, while names without
        spaces will have internal capitalization dropped. Thus "Home Address"
        becomes "HomeAddress", while "HomeAddress" becomes "Homeaddress" To
        disable this behavior, pass standardize_names=False, but be aware
        that accessing names with spaces from the namespace can be
        problematic.

        Args:
            strict: (bool) use this to validate required fields while creating the class
            named_only: (bool) If true, only properties with an actual title attribute will
                be included in the resulting namespace (although all will be generated).
            standardize_names: (bool) If true (the default), class names will be tranformed
                by camel casing

        Returns:
            A namespace containing all the generated classes

        """
        kw = {"strict": strict}
        builder = classbuilder.ClassBuilder(self.resolver)
        for nm, defn in iteritems(self.schema.get('definitions', {})):
            uri = python_jsonschema_objects.util.resolve_ref_uri(
                self.resolver.resolution_scope,
                "#/definitions/" + nm)
            builder.construct(uri, defn, **kw)

        if standardize_names:
            name_transform = lambda t: inflection.camelize(inflection.parameterize(six.text_type(t), '_'))
        else:
            name_transform = lambda t: t

        nm = self.schema['title'] if 'title' in self.schema else self.schema['$id']
        nm = inflection.parameterize(six.text_type(nm), '_')

        builder.construct(nm, self.schema,**kw)
        self._resolved = builder.resolved

        classes = {}
        for uri, klass in six.iteritems(builder.resolved):
            title = getattr(klass, '__title__', None)
            if title is not None:
                classes[name_transform(title)] = klass
            elif not named_only:
                classes[name_transform(uri.split('/')[-1])] = klass

        return python_jsonschema_objects.util.Namespace.from_mapping(classes)
示例#2
0
def dashboard_create():
    """Create a new dashboard with an empty definition.

    """
    dashboard = database.DashboardRecord.from_json(request.json)
    if not dashboard.title:
        return {'error_message': "Missing required field 'title'"}, 400
    if 'definition' in request.json:
        dashboard.definition = database.DefinitionRecord(
            dumps(request.json['definition']))
    else:
        dashboard.definition = database.DefinitionRecord(
            dumps(DashboardDefinition()))
    mgr.store_dashboard(dashboard)
    href = url_for('api.dashboard_get', id=dashboard.id)
    return {
        'dashboard_href':
        href,
        'view_href':
        url_for('ui.dashboard_with_slug',
                id=dashboard.id,
                slug=inflection.parameterize(dashboard.title))
    }, 201, {
        'Location': href
    }
示例#3
0
def parameterize(word):
    """Parameterize the word so it can be used as a python or javascript variable name.
    For example:
    >>> word = "Acme® EV-Charger™"
    "acme_ev_chargertm"
    """
    return inflection.parameterize(word).replace("-", "_")
示例#4
0
def key_to_pv(key: str) -> str:
    """
    Take an archiver appliance JSON key and make a PV name out of it.

    Parameters
    ----------
    key : str
        The archiver appliance metrics key name.

    Example
    -------
    >>> key_to_pv("Avg time spent by getETLStreams() in ETL(0»1) (s/run)")
    'AvgTimeSpentByGetetlstreamsInEtl0To1SPerRun'
    """
    # Pre-filter: &raquo -> to
    key = key.replace("»", " to ")
    # Pre-filter: / -> per
    key = key.replace("/", " per ")
    # Pre-filter: ETL -> _ETL_
    key = key.replace("ETL", " ETL ")
    # Pre-filter: .*rate -> Rate
    if key.endswith('rate'):
        key = key[:-4] + 'Rate'

    # Parametrize it for consistency:
    parametrized = inflection.parameterize(key)
    return inflection.camelize(parametrized.replace("-", "_"))
示例#5
0
def load_schema(schema, schemas_store=None):
    _("""
    Load a schema to the schema store.

    if no schema store is provided, only the internal schema store is filled.

    :param schema: schema as dictionary
    :type schema: dict
    :param schemas_store: optional schemas_store to fill
    :type schemas_store: dict
    """)
    from ngoschema.resolvers.uri_resolver import UriResolver
    uri = _id_of(schema).rstrip('#')
    if not uri and "title" in schema:
        uri = inflection.parameterize(six.text_type(schema["title"]), "_")
    if not uri:
        raise SchemaError(
            "Impossible to load schema because `id (or `$id) and `title fields"
            "are missing.\n%s" % schema)
    if schemas_store is not None:
        if schema != schemas_store.get(uri, schema):
            logger.info(
                "Overwriting a different schema '%s' is already registered in schema store."
                % uri)
        schemas_store[uri] = schema
    # add to main registry
    UriResolver.register_doc(schema, uri)
    return uri, schema
示例#6
0
文件: main.py 项目: cthit/info-screen
def fetch_feeds():
	for feed_data in feeds:
		feed = feedparser.parse(feed_data.get('url'))
		items = []
		filename = out_filename(parameterize(feed_data.get('name')))

		for i in range(0, feed_data.get('count')):
			entry = feed['entries'][i]
			item = {
				'title':
				entry['title'],
				'description':
				feed_data.get(
					'parse_description',
					parse_description
				)(entry),
				'alt_text':
				feed_data.get('parse_alt', lambda x: '')(entry)
			}

			items.append(item)

		template = Template(
			filename=template_path(feed_data.get('layout')))

		with open(filename, 'w') as f:
			f.write(template.render(items=items))
示例#7
0
 def on_files(self, files: Files, config: Config):
     json_dir = "api"
     (pathlib.Path(config['docs_dir']).resolve() / json_dir).mkdir(
         parents=True, exist_ok=True)
     (pathlib.Path(config['site_dir']).resolve() / json_dir).mkdir(
         parents=True, exist_ok=True)
     all_json_file = File(f"{json_dir}/codes.json", config["docs_dir"],
                          config["site_dir"], config["use_directory_urls"])
     with open(all_json_file.abs_src_path, "w") as file:
         json.dump(self.codes, file, indent=2)
     with open(all_json_file.abs_dest_path, "w") as file:
         json.dump(self.codes, file, indent=2)
     for category, codes in self.codes_by_category.items():
         dir = parameterize(f"{category}-responses")
         for name, emojicode in codes.items():
             md_file = File(f"{dir}/{name}.md", config["docs_dir"],
                            config["site_dir"],
                            config["use_directory_urls"])
             files.append(md_file)
             json_file = File(f"{json_dir}/{name}.json", config["docs_dir"],
                              config["site_dir"],
                              config["use_directory_urls"])
             with open(json_file.abs_src_path, "w") as file:
                 json.dump(emojicode, file, indent=2)
             files.append(json_file)
示例#8
0
    def from_value(cls, value):
        try:
            actual = value["value"]
        except TypeError:
            actual = value
            alias = inflection.parameterize(str(actual), "-")
        except KeyError:
            raise TypeError(
                "Expected a value or a mapping with a `value` key.")
        else:
            try:
                alias = value["alias"]
            except KeyError:
                alias = inflection.parameterize(str(actual), "-")

        return cls(alias=alias, value=actual)
示例#9
0
def parse_column_name(column_name):
    if column_name == 'ID':
        return 'legacyId'
    if column_name == 'Reference Id':
        return 'referenceId'
    if isinstance(column_name, int):
        key = f"column-{column_name}"
    elif isinstance(column_name, str):
        # key = unidecode(column_name)
        key = column_name.replace('-&-', '-and-')
        key = key.replace('&', ' and ')
        # print(f"key={key} is_camel_case={is_lower_camel_case(key)}")
        if not is_lower_camel_case(key):
            key = inflection.parameterize(key)
            if not is_lower_camel_case(key):
                key = case(key)
    elif isinstance(column_name, Timestamp):
        key = f"column-{Literal(column_name).lower()}"
    else:
        error(f"Encountered unknown type {type(column_name)} for value {column_name}")
        return None
    key = key.replace('  ', ' ')
    key = key.replace('--', '-')
    key = key.replace('--', '-')
    key = strip_end(key, '-')
    return key
    def get_file_context(self, **kwargs):
        get_framework_and_lot(
            kwargs['framework_slug'],
            kwargs['lot_slug'],
            self.data_api_client,
            allowed_statuses=['live', 'expired'],
            must_allow_brief=True,
        )

        brief = self.data_api_client.get_brief(kwargs['brief_id'])["briefs"]

        if not is_brief_correct(brief, kwargs['framework_slug'],
                                kwargs['lot_slug'], current_user.id):
            abort(404)

        if brief['status'] not in CLOSED_PUBLISHED_BRIEF_STATUSES:
            abort(404)

        file_context = {
            'brief':
            brief,
            'responses':
            self.get_responses(brief),
            'filename':
            'supplier-responses-{0}'.format(
                inflection.parameterize(str(brief['title']))),
        }

        return file_context
    def __init__(self, field):
        self.field = field

        # Try to name this XSD type

        # Note: should we use field.context.key ?
        # The problem is that when dealing with List/Dict fields, the value_type
        # field also inherits the parent's context

        name = field.getName() or str(inflection.parameterize(field.title))
        if not name:
            try:
                name = field.getTaggedValue("name")
            except KeyError:
                pass

        assert name, "The field should be named"

        name = inflection.underscore(name)
        self.typename = inflection.camelize(name)
        self.name = inflection.dasherize(name)

        # Compute occurence indicators

        self.min_occurs = 1 if field.required else 0
        self.max_occurs = 1
示例#12
0
def parse_mouse_info(df: pd.DataFrame, study_id: int, ordinal_value: int):
    mouse_schema = Mouse.Schema(unknown=EXCLUDE)

    try:
        df.columns = map(lambda x: underscore(parameterize(x)), df.columns)
    except Exception as e:
        raise HeaderException(df, msg=str(e))

    for col in ['euthanasia_date', 'injection_date']:
        try:
            df[col] = pd.to_datetime(df[col])
        except Exception as e:
            raise ColumnException(df=df, col=col, msg=str(e), hide_index=True)

    for _, row in df.iterrows():
        try:
            row_dict = row.to_dict()
            row_dict = timestamp_to_db_date(row_dict)

            row_dict['ordinal_value'] = ordinal_value
            ordinal_value += 1

            mouse = mouse_schema.load(row_dict)
            mouse.study_id = study_id
            mouse.save()
        except Exception as e:
            raise RowException(df=df, msg=str(e), row=str(_), hide_index=True)

    print("MOUSE INFO PARSED")
    return ordinal_value
示例#13
0
def _add_enums(root_object, target_object):
    """
    Look for enums in the given object to create string constants <ENUM_CLASSNAME>_<ENUM_VALUE>.

    :param dict root_object: the object which may contain enums
    :param object target_object: The target object where to add the string constants to
    """
    for i in root_object.keys():
        enum = None
        propinfo = root_object.propinfo(i)
        if 'enum' in propinfo:
            enum = propinfo
        if propinfo['type'] == 'array':
            if 'enum' in propinfo['items']:
                enum = propinfo['items']
        if not enum:
            continue

        enum_class = str(i).upper()
        if 'title' in enum:
            enum_class = str(inflection.underscore(enum['title'])).upper()
        enum_class += "_"
        for val in enum['enum']:
            enum_value = enum_class + inflection.parameterize(val, '_').upper()
            setattr(target_object, enum_value, val)
示例#14
0
def format_workflow(s):
    s = re.sub(r"[_-]", " ", s)  # convert underscores to spaces
    s = re.sub(r"([A-Z]+)", r" \1", s)  # convert camel case into words

    s = _replace_special(s)

    return underscore(parameterize(s))
示例#15
0
def teams_add():
    if request.mimetype != 'application/json':
        abort(415)
    data = team_schema(request.json)

    name = data['name']
    original_slug = parameterize(name[:20])
    slug = _generate_slug(original_slug)

    while Team.query.filter_by(slug=slug).count() > 0:
        slug = _generate_slug(original_slug)

    team = Team(name=name, slug=slug)
    db.session.add(team)
    TeamMembership(
        team=team,
        user=current_identity,
        is_admin=True
    )

    db.session.add(TabType(name='Beer', price=1, team=team))
    db.session.add(TabType(name='Cider', price=2, team=team))
    db.session.add(Person(name=current_identity.name, team=team))

    db.session.commit()

    response = _get_teams_response()
    response.status_code = 201
    return response
    def __init__(self, form):
        """
        :param self.report_dict: a mapping of form attributes to inputted values
        :type self.report_dict: Dict

        :param form: report being parsed and saved
        :type form: ReportForm
        """
        self.form = form
        self.format_emails()
        self.report_dict["report_title"] = self.form.report_title.data
        self.report_dict["report_title_id"] = parameterize(
            self.form.report_title.data)
        self.report_dict["description"] = self.form.description.data
        self.report_dict["owner_name"] = self.form.owner_name.data
        self.report_dict["owner_email"] = self.form.owner_email.data
        self.report_dict["tests"] = self.form.tests.data
        self.report_dict["schedule_type"] = self.form.schedule_type.data
        self.report_dict[
            "schedule_timezone"] = self.form.schedule_timezone.data
        if self.report_dict["schedule_type"] == "custom":
            self.report_dict["schedule"] = self.form.schedule_custom.data
        elif self.report_dict["schedule_type"] == "manual":
            self.report_dict["schedule"] = None
        else:
            utc_week_day, utc_time = self.get_utc_time_and_week_day()
            self.report_dict["schedule_time"] = utc_time
            if self.report_dict["schedule_type"] == "weekly":
                self.report_dict["schedule_week_day"] = utc_week_day
            self.report_dict["schedule"] = self.get_cron_schedule()
        def parse_stats_table(table):
            """Parses a table of player's statistics."""
            header_elements = [
                underscore(parameterize(header))
                for header in table.css("th::text").getall() +
                table.css("th > span::attr(title)").getall()
            ]
            # for some reason, sometimes transfermarket might call the matchday as spieltag
            # here we make sure that if that's the case we revert it back to matchday
            header_elements = [
                header if header != 'spieltag' else 'matchday'
                for header in header_elements
            ]

            value_elements_matrix = [
                [
                    parse_stats_elem(element) for element in row.xpath('td')
                    if parse_stats_elem(element) is not None
                ] for row in table.css('tr') if len(row.css('td').getall()) >
                9  # TODO: find a way to include 'on the bench' and 'not in squad' occurrences
            ]

            for value_elements in value_elements_matrix:
                header_elements_len = len(header_elements)
                value_elements_len = len(value_elements)
                assert (
                    header_elements_len == value_elements_len
                ), f"Header ({header_elements}) - cell element ({value_elements}) mismatch at {response.url}"
                yield dict(zip(header_elements, value_elements))
示例#18
0
    def process(self):
        soup = BeautifulSoup(unicode(self.input_data), self.setting('html-parser'))

        for tag in soup.find_all(re.compile("^h[0-6]")):
            name = tag.text
            m = re.match("^h([0-6])$", tag.name)

            if not tag.attrs.has_key('id'):
                tag.attrs['id'] = inflection.parameterize(name)

            self.current_section_anchor = tag.attrs['id']
            self.current_section_text = None
            self.current_section_name = name
            self.current_section_level = int(m.groups()[0])

            self.append_current_section()

        self.current_section_text = unicode(soup)
        self.current_section_name = self.setting('initial-section-name')
        self.current_section_level = 1
        self.current_section_anchor = None

        self.append_current_section()

        self.output_data.save()
示例#19
0
def cashiers(cashier_ids=None):
    if not cashier_ids: print USAGE; return

    init_command()

    accounts = AccountService()
    cash = CashPaymentService()

    dates = [ datetime.strptime(d,DATE_FORMAT) for d in config.EVENT_DATES ]
    cashiers = [ accounts.get_one(c,check_ownership=False) for c in cashier_ids.split(",") ]

    for cashier in cashiers:
        filename = "report_{}.ods".format(parameterize(cashier.name))
        with ods.writer(open(filename,"wb")) as odsfile:
            for date in dates:
                sheet = odsfile.new_sheet(date.strftime("dia %d"))
                sheet.writerow(["hora","modo","valor","id","nome","produto"])
                report = cash.for_cashier(cashier, date)

                for payment in report:
                    person = Person(payment.purchase)
                    for transition in payment.transitions:
                        row =  [
                            transition.created.time(), transition.mode, Decimal(payment.amount),
                            person.id, person.name, person.product.description
                        ]
                        sheet.writerow(row)

                summer = lambda f: sum([ x.amount for x in filter(f, report) ])

                sheet.writerow([None, u"total cartão",   summer(lambda p: p.mode == 'card') ])
                sheet.writerow([None, u"total dinheiro", summer(lambda p: p.mode == 'cash') ])
                sheet.writerow([None, u"total geral",    summer(lambda p: True            ) ])
    def build_classes(self,strict=False):
        """

        Args:
            strict: use this to validate required fields while creating the class

        Returns:

        """
        builder = classbuilder.ClassBuilder(self.resolver)
        for nm, defn in iteritems(self.schema.get('definitions', {})):
            uri = util.resolve_ref_uri(
                self.resolver.resolution_scope,
                "#/definitions/" + nm)
            builder.construct(uri, defn)

        nm = self.schema['title'] if 'title' in self.schema else self.schema['id']
        nm = inflection.parameterize(six.text_type(nm), '_')

        kw = {"strict" : strict}
        builder.construct(nm, self.schema,**kw)
        self._resolved = builder.resolved

        return (
            util.Namespace.from_mapping(dict(
                (inflection.camelize(uri.split('/')[-1]),
                 klass) for uri,
                klass in six.iteritems(builder.resolved)))
        )
示例#21
0
def _add_enums(root_object, target_object):
    """
    Look for enums in the given object to create string constants <ENUM_CLASSNAME>_<ENUM_VALUE>.

    :param dict root_object: the object which may contain enums
    :param object target_object: The target object where to add the string constants to
    """
    for i in root_object.keys():
        enum = None
        propinfo = root_object.propinfo(i)
        if 'enum' in propinfo:
            enum = propinfo
        if propinfo['type'] == 'array':
            if 'enum' in propinfo['items']:
                enum = propinfo['items']
        if not enum:
            continue

        enum_class = str(i).upper()
        if 'title' in enum:
            enum_class = str(inflection.underscore(enum['title'])).upper()
        enum_class += "_"
        for val in enum['enum']:
            enum_value = enum_class + inflection.parameterize(val, '_').upper()
            setattr(target_object, enum_value, val)
示例#22
0
 def linkify(text: str):
     """
     Replaces all non alphanum characters with '-' and lowercases
     everything.
         "foo: bar baz st. claire" => "foo-bar-baz-st-claire"
     use: {{ "Foo Bar Baz St. Claire"|linkify }}
     """
     return inflection.parameterize(text)
def format_brand(brand_value):
    "Make universal format"
    try:
        brand = parameterize(brand_value, '_')
    except:
        brand = ''

    return brand
示例#24
0
 def export_dashboard(self, dashboard, directory):
     filepath = '{0}/{1}.json'.format(directory, inflection.parameterize(dashboard.category + ' ' + dashboard.title))
     log.info('Exporting to {0}'.format(filepath))
     f = open(filepath, 'w')
     try:
         json.dump(dashboard, f, indent=2, cls=EntityEncoder)
     finally:
         f.close()
示例#25
0
 def convert_tag(self, tag):
     tag = tag.strip()
     if not self.tags:
         url = urljoin(self.base_url, 'wp/v2/tags?per_page=100')
         r = self.oauth.get(url)
         for item in r.json():
             self.tags[item['slug']] = item['id']
     if parameterize(tag) in self.tags:
         return self.tags[parameterize(tag)]
     else:
         post_url = urljoin(self.base_url, 'wp/v2/tags')
         new_tag = {'name': tag, 'slug': parameterize(tag)}
         r = self.oauth.post(post_url, json=new_tag).json()
         self.tags[r['slug']] = r['id']
         print('*** Make new tag: %s ***' % tag)
         print(r)
         return r['id']
示例#26
0
文件: issues.py 项目: greganswer/mgit
    def branch_name(self) -> str:
        """
        Get the branch name from ID and title.

        >>> Issue(id='jir-123', summary='Update readme.md file').branch_name()
        jir-123-update-readme-file
        """
        return inflection.parameterize(f"{self._id} {self._summary}")
示例#27
0
def test_parameterize_with_multi_character_separator(
    some_string,
    parameterized_string
):
    assert (
        parameterized_string.replace('-', '__sep__') ==
        inflection.parameterize(some_string, '__sep__')
    )
示例#28
0
def process_worksheet(gsheets_loader, sheet_name, worksheet, start_from_row, config):
    if worksheet is None:
        name_with_worksheet = sheet_name
    else:
        name_with_worksheet = sheet_name + "_" + worksheet

    if 'singular_table_name' in config and config['singular_table_name']:
        stream_name = underscore(parameterize(name_with_worksheet))
    else:
        stream_name = tableize(parameterize(name_with_worksheet))

    schema = gsheets_loader.get_schema(sheet_name, worksheet, start_from_row)

    records = gsheets_loader.get_records_as_json(sheet_name, worksheet, start_from_row)

    # additional data transformations
    column_mapping = None
    if 'underscore_columns' in config and config['underscore_columns']:
        column_mapping = {'id': 'id'}
        props = {}
        for k, v in schema['properties'].items():
            kt = underscore(parameterize(k))
            props[kt] = v
            column_mapping[k] = kt
        schema['properties'] = props

    schema['properties']['id'] = {'type': 'integer'}

    for i, record in enumerate(records, start=1):
        record['id'] = i

    # write stuff
    singer.write_schema(
        stream_name=stream_name,
        schema=schema,
        key_properties=['id']
    )

    for record in records:
        if column_mapping is not None:
            record_transformed = {column_mapping[k]: v for k, v in record.items()}
        else:
            record_transformed = record

        singer.write_record(stream_name, record_transformed)
示例#29
0
def to_snake_case(name: str):
    """Make any string into a "snake_cased" string.

    Args:
        name (str): The name to convert.

    Returns:
        str: The converted string.
    """
    return inflection.parameterize(inflection.titleize(name), separator="_").lower()
示例#30
0
文件: json.py 项目: JohnSpeno/tessera
 def export_dashboard(dashboard, directory):
     dash = dashboard.to_json()
     dash['definition'] = json.loads(dashboard.definition.definition)
     filepath = '{0}/{1}.json'.format(directory, inflection.parameterize(dashboard.category + ' ' + dashboard.title))
     log.info('Exporting to {0}'.format(filepath))
     f = open(filepath, 'w')
     try:
         json.dump(dash, f, indent=2, cls=web.EntityEncoder)
     finally:
         f.close()
示例#31
0
def save_author_data(author, data, output_path):
    flip_name = '_'.join(reversed(parameterize(author).split('-')))
    file_name = '{}.json'.format(flip_name)

    file_path = '{output_path}/{file_name}'.format(
        output_path=output_path, file_name=file_name)

    with open(file_path, 'w') as file:
        file.write(json.dumps(data))

    print('Saved {} to disk'.format(author))
示例#32
0
def _set_dashboard_hrefs(dash):
    """Add the various ReSTful hrefs to an outgoing dashboard
representation. dash should be the dictionary for of the dashboard,
not the model object.
    """
    id = dash['id']
    dash['href'] = '/api/dashboard/{0}'.format(id)
    dash['definition_href'] = '/api/dashboard/{0}/definition'.format(id)
    dash['view_href'] = '/dashboards/{0}/{1}'.format(id, inflection.parameterize(dash['title']))
    if 'definition' in dash:
        definition = dash['definition']
        definition['href'] = '/api/dashboard/{0}/definition'.format(id)
    return dash
def run():
  h2 = Helper2()
  owner, repo = h2.owner_and_repo()
  api = GithubAPIGateway(owner, repo, token=os.environ['GITHUB_TOKEN'])
  issue = None
  if len(sys.argv) <= 1:
    issue = api.call('list_issues', org=owner)[0][0]
  else:
    issue = api.call('list_issue', owner=owner, repo=repo, number=sys.argv[1])[0]

  branch_name = str(issue['number']) + '-' + inflection.parameterize(issue['title'])[:30].strip('-')
  result = h2.create_branch(branch_name)
  if result[0] != 0:
    print(result[1])
    sys.exit(result[0])
示例#34
0
def _set_dashboard_hrefs(dash):
    """Add the various ReSTful hrefs to an outgoing dashboard
representation. dash should be the dictionary for of the dashboard,
not the model object.
    """
    id = dash['id']
    dash['href']            = url_for('api_dashboard_get', id=id)
    dash['definition_href'] = url_for('api_dashboard_get_definition', id=id)
    dash['view_href']       = url_for('ui_dashboard_with_slug',
                                      id=id,
                                      slug=inflection.parameterize(dash['title']))
    if 'definition' in dash:
        definition = dash['definition']
        definition['href'] = url_for('api_dashboard_get_definition', id=id)
    return dash
示例#35
0
def api_dashboard_create():
    """Create a new dashboard with an empty definition.

    """
    dashboard = database.DashboardRecord.from_json(request.json)
    if 'definition' in request.json:
        dashboard.definition = database.DefinitionRecord(dumps(request.json['definition']))
    else:
        dashboard.definition = database.DefinitionRecord(dumps(DashboardDefinition()))
    mgr.store_dashboard(dashboard)
    href = '/api/dashboard/{0}'.format(dashboard.id)
    return _jsonify({
        'dashboard_href' : href,
        # TODO: should use normalized method for this
        'view_href' : '/dashboards/{0}/{1}'.format(dashboard.id, inflection.parameterize(dashboard.title))
    }, status=201, headers = { 'Location' : href })
示例#36
0
def api_dashboard_create():
    """Create a new dashboard with an empty definition.

    """
    dashboard = database.DashboardRecord.from_json(request.json)
    if 'definition' in request.json:
        dashboard.definition = database.DefinitionRecord(dumps(request.json['definition']))
    else:
        dashboard.definition = database.DefinitionRecord(dumps(DashboardDefinition()))
    mgr.store_dashboard(dashboard)
    href = url_for('api_dashboard_get', id=dashboard.id)
    return _jsonify({
        'dashboard_href' : href,
        'view_href' : url_for('ui_dashboard_with_slug',
                              id=dashboard.id,
                              slug=inflection.parameterize(dashboard.title))
    }, status=201, headers = { 'Location' : href })
    def build_classes(self):
        builder = classbuilder.ClassBuilder(self.resolver)
        for nm, defn in iteritems(self.schema.get('definitions', {})):
            uri = util.resolve_ref_uri(
                self.resolver.resolution_scope,
                "#/definitions/" + nm)
            builder.construct(uri, defn)

        nm = self.schema['title'] if 'title' in self.schema else self.schema['id']
        nm = inflection.parameterize(six.text_type(nm), '_')

        builder.construct(nm, self.schema)

        return (
            util.Namespace.from_mapping(dict(
                (inflection.camelize(uri.split('/')[-1]),
                 klass) for uri,
                klass in six.iteritems(builder.resolved)))
        )
示例#38
0
def dashboard_create():
    """Create a new dashboard with an empty definition.

    """
    dashboard = database.DashboardRecord.from_json(request.json)
    if not dashboard.title:
        return {
            'error_message': "Missing required field 'title'"
        }, 400
    if 'definition' in request.json:
        dashboard.definition = database.DefinitionRecord(dumps(request.json['definition']))
    else:
        dashboard.definition = database.DefinitionRecord(dumps(DashboardDefinition()))
    mgr.store_dashboard(dashboard)
    href = url_for('api.dashboard_get', id=dashboard.id)
    return {
        'dashboard_href' : href,
        'view_href' : url_for('ui.dashboard_with_slug',
                              id=dashboard.id,
                              slug=inflection.parameterize(dashboard.title))
    }, 201, { 'Location' : href }
示例#39
0
    def __convert(self, graphite_dashboard, dash=None, layout=Section.Layout.FIXED, columns=2, overwrite=False):
        span = 12 / columns
        name = graphite_dashboard['name']
        dashboard = dash
        if dashboard is None:
            dashboard = Dashboard(title=inflection.parameterize(name),
                                  category='Graphite',
                                  tags=['imported'],
                                  imported_from=self.__graphite_href(name))
        definition = DashboardDefinition()
        section = Section(layout=layout)
        definition.items.append(section)

        # if 'defaultGraphParams' in graphite_dashboard:
        #     default_width = graphite_dashboard['defaultGraphParams'].get('width', None)
        #     print graphite_dashboard['defaultGraphParams']
        #     if default_width and default_width > 800:
        #         num_columns = 1
        #         span = 12

        graph_count = 0
        row = Row()
        for graph in graphite_dashboard['graphs']:
            # Graphite's dashboard API is so redundant. Each graph is
            # a 3-element array:
            # [
            #    target string,
            #    options dict (which contains the targets array too),
            #    render URL string
            #  ]
            targets, options, render_url = graph
            presentation = None
            stacked_p = (render_url.find('stacked')) != -1 or (options.get('areaMode', None) == 'stacked')
            query = 'q' + str(len(definition.queries))
            targets = options.get('target', [])
            definition.queries[query] = targets[0] if len(targets) == 1 else targets
            if stacked_p:
                presentation = StackedAreaChart(query=query, title=options.get('title', ''))
            else:
                presentation = StandardTimeSeries(query=query, title=options.get('title', ''))
            presentation.options['yAxisFormat'] = ',.2s'
            presentation.height = 4
            if 'template' in options:
                presentation.options['palette'] = options['template']
            if 'vtitle' in options:
                presentation.options['yAxisLabel'] = options['vtitle']
                presentation.options['yShowMaxMin'] = True
            presentation.options['margin'] = { 'top' : 16, 'left' : 80, 'right' : 0, 'bottom' : 16 }
            presentation.options['y1'] = {'max' : options.get('yMax', ''), 'min' : options.get('yMin', ''), 'label' : options.get('vtitle', '')}
            
            row.items.append(Cell(span=span, items=presentation))
            graph_count += 1
            if len(row.items) == columns:
                section.items.append(row)
                row = Row()

        if len(row.items) > 0:
            section.items.append(row)

        if graph_count == 0:
            log.warn('Failed to convert any graphs for dashboard {0}'.format(name))

        dashboard.definition = definition
        return dashboard
示例#40
0
 def methodize(string):
     return parameterize(string.replace(r'.', '')).replace(r'-', '_')
示例#41
0
文件: utils.py 项目: eReuse/DeviceHub
 def url_word(word: str):
     """
         Normalizes a full word to be inserted to an url. If the word has spaces, etc, is used '_' and not '-'
     """
     return inflection.parameterize(word, "_")
示例#42
0
def test_parameterize_with_no_separator(some_string, parameterized_string):
    assert parameterized_string == inflection.parameterize(some_string, '')
示例#43
0
    def __convert(self, graphite_dashboard, dash=None, layout=Section.Layout.FIXED, columns=2, overwrite=False):
        span = 12 / columns
        name = graphite_dashboard["name"]
        dashboard = dash
        if dashboard is None:
            dashboard = Dashboard(
                title=inflection.parameterize(name),
                category="Graphite",
                tags=["imported"],
                imported_from=self.__graphite_href(name),
            )
        definition = DashboardDefinition()
        section = Section(layout=layout)
        definition.items.append(section)

        # if 'defaultGraphParams' in graphite_dashboard:
        #     default_width = graphite_dashboard['defaultGraphParams'].get('width', None)
        #     print graphite_dashboard['defaultGraphParams']
        #     if default_width and default_width > 800:
        #         num_columns = 1
        #         span = 12

        graph_count = 0
        row = Row()
        for graph in graphite_dashboard["graphs"]:
            # Graphite's dashboard API is so redundant. Each graph is
            # a 3-element array:
            # [
            #    target string,
            #    options dict (which contains the targets array too),
            #    render URL string
            #  ]
            targets, options, render_url = graph
            presentation = None
            stacked_p = (render_url.find("stacked")) != -1 or (options.get("areaMode", None) == "stacked")
            query = "q" + str(len(definition.queries))
            targets = options.get("target", [])
            definition.queries[query] = targets[0] if len(targets) == 1 else targets
            if stacked_p:
                presentation = StackedAreaChart(query=query, title=options.get("title", ""))
            else:
                presentation = StandardTimeSeries(query=query, title=options.get("title", ""))
            presentation.options["yAxisFormat"] = ",.2s"
            presentation.height = 4
            if "template" in options:
                presentation.options["palette"] = options["template"]
            if "vtitle" in options:
                presentation.options["yAxisLabel"] = options["vtitle"]
                presentation.options["yShowMaxMin"] = True
            presentation.options["margin"] = {"top": 16, "left": 80, "right": 0, "bottom": 16}
            presentation.options["y1"] = {
                "max": options.get("yMax", ""),
                "min": options.get("yMin", ""),
                "label": options.get("vtitle", ""),
            }

            row.items.append(Cell(span=span, items=presentation))
            graph_count += 1
            if len(row.items) == columns:
                section.items.append(row)
                row = Row()

        if len(row.items) > 0:
            section.items.append(row)

        if graph_count == 0:
            log.warn("Failed to convert any graphs for dashboard {0}".format(name))

        dashboard.definition = definition
        return dashboard
示例#44
0
def filter_methodize(token):
    if token is None:
        return None
    return underscore(parameterize(underscore(token)))
示例#45
0
 def get_fields(self):
   self.raw_fields = self.make_request(self.url + self.ENDPOINTS['fields'])
   self.fields = [Field(field) for field in self.raw_fields['fields']]
   self.fields = {inflection.parameterize(field.label, "_"): field for field in self.fields}
   return self.fields
示例#46
0
def filter_objectize(token):
    if token is None:
        return None
    return camelize(underscore(parameterize(underscore(token))))
示例#47
0
    def to_url(self, value):
        raw = str(value) if self.attr is None else getattr(value, self.attr, '')
        slug = parameterize(raw)[:self.length].rstrip('-')

        return '{}/{}'.format(value.id, slug).rstrip('/')
示例#48
0
 def parameterize(self, separator='-'):
     return inflection.parameterize(self.__str__(), separator)
示例#49
0
def test_parameterize_and_normalize(some_string, parameterized_string):
    assert parameterized_string == inflection.parameterize(some_string)
示例#50
0
def filter_variablize(token):
    if token is None:
        return None
    return underscore(parameterize(underscore(token)))
示例#51
0
def create_id(name):
    return inflection.parameterize(name)