我正在尝试使用Ruby为语言编写流程图生成器.
我想知道是否有任何库可用于为各种流程图元素绘制各种形状并将文本写入这些形状.
如果我能帮助它,我真的不想编写用于绘制基本形状的代码.
有人可以给我一些参考文档,其中包含使用该库的示例吗?
我有以下YAML文件命名input.yaml:
cities:
1: [0,0]
2: [4,0]
3: [0,4]
4: [4,4]
5: [2,2]
6: [6,2]
highways:
- [1,2]
- [1,3]
- [1,5]
- [2,4]
- [3,4]
- [5,4]
start: 1
end: 4
Run Code Online (Sandbox Code Playgroud)
我正在使用PyYAML加载它并打印结果如下:
import yaml
f = open("input.yaml", "r")
data = yaml.load(f)
f.close()
print(data)
Run Code Online (Sandbox Code Playgroud)
结果是以下数据结构:
{ 'cities': { 1: [0, 0]
, 2: [4, 0]
, 3: [0, 4]
, 4: [4, 4]
, 5: [2, 2]
, 6: [6, 2]
}
, 'highways': [ [1, 2]
, [1, …Run Code Online (Sandbox Code Playgroud) 我已经获得了REST API生成的一些JSON文件,这些文件具有大量属性.
我为这个API创建了一个Swagger 2.0定义,需要为它提供相应的响应模式.
主要问题:这个JSON文件有很多属性.这需要花费很多时间,如果我手动编写模式,我会犯很多错误.它不是我需要描述的唯一API.
我知道有一些工具可以将JSON转换为JSON模式但是,如果我没有弄错,Swagger只有$ refs到其他对象定义,因此只有一个级别,而我发现的工具只生成树结构模式.我的问题:是否有任何工具可以将JSON(或JSON Schema)转换为兼容Swagger 2.0的工具?
注意:我在YAML工作,但我不会成为问题,是吗?
例如,我需要的是:
List of Movements:
type: "array"
items:
$ref: "#/definitions/Movement"
Movement:
properties:
dateKey:
type: "string"
movement:
$ref: "#/definitions/Stock"
additionalProperties: false
Stock:
properties:
stkUnitQty:
type: "string"
stkDateTime:
type: "string"
stkUnitType:
type: "string"
stkOpKey:
type: "string"
additionalProperties: false
Run Code Online (Sandbox Code Playgroud)
对于我的JSON文档:
[
{
"dateKey": "20161110",
"stkLvls": [
{
"stkOpKey": "0",
"stkUnitType": "U",
"stkDateTime": "20161110T235010.240+0100",
"stkUnitQty": 30
}
]
},
{
"dateKey": "20161111",
"stkLvls": [
{
"stkOpKey": "0",
"stkUnitType": "U",
"stkDateTime": "20161111T231245.087+0100",
"stkUnitQty": 21
}
] …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个脚本来导入数据库文件.我编写了脚本来导出文件,如下所示:
import sqlite3
con = sqlite3.connect('../sqlite.db')
with open('../dump.sql', 'w') as f:
for line in con.iterdump():
f.write('%s\n' % line)
Run Code Online (Sandbox Code Playgroud)
现在我希望能够导入该数据库.我试过了 :
import sqlite3
con = sqlite3.connect('../sqlite.db')
f = open('../dump.sql','r')
str = f.read()
con.execute(str)
Run Code Online (Sandbox Code Playgroud)
但我不允许执行多个声明.有没有办法让它直接运行SQL脚本?
我刚刚创建了一个新的virtualenv,我想运行我的pip install.但是,我收到此错误:
raise ValueError("Missing distribution spec", line)
ValueError: ('Missing distribution spec', '/path/to/dir/requirements.txt')
Run Code Online (Sandbox Code Playgroud)
我的requirements.txt:
Django==1.3
Jinja2==2.6
MySQL-python==1.2.3
PIL==1.1.7
Pygments==1.5
Sphinx==1.1.3
Werkzeug==0.8.3
django-debug-toolbar==0.9.4
django-excel-response==1.0
django-extensions==0.8
docutils==0.9.1
ipython==0.12
wsgiref==0.1.2
Run Code Online (Sandbox Code Playgroud)
出了什么问题?
我有一个python项目,我想使用YAML(pyYaml 3.11),特别是因为它"非常"且用户可以在必要时在文本编辑器中轻松编辑.但问题是,如果我将YAML带入python应用程序(我将需要)并编辑内容(因为我需要),那么编写新文档通常不如我开始时那么漂亮.
pyyaml文档非常差 - 甚至没有将参数记录到转储函数.我找到了http://dpinte.wordpress.com/2008/10/31/pyaml-dump-option/.但是,我仍然缺少我需要的信息.(我开始查看源代码,但它似乎并不是最吸引人的.如果我没有得到解决方案,那么这是我唯一的办法.)
我从一个看起来像这样的文档开始:
- color green :
inputs :
- port thing :
widget-hint : filename
widget-help : Select a filename
- port target_path :
widget-hint : path
value : 'thing'
outputs:
- port value:
widget-hint : string
text : |
I'm lost and I'm found
and I'm hungry like the wolf.
加载到python(yaml.safe_load(s))后,我尝试了几种方法将其转储出来:
>>> print yaml.dump( d3, default_flow_style=False, default_style='' )
- color green:
inputs:
- port thing:
widget-help: Select a filename
widget-hint: filename
- port target_path: … 借助键路径从嵌套字典中获取值,这里是dict:
json = {
"app": {
"Garden": {
"Flowers": {
"Red flower": "Rose",
"White Flower": "Jasmine",
"Yellow Flower": "Marigold"
}
},
"Fruits": {
"Yellow fruit": "Mango",
"Green fruit": "Guava",
"White Flower": "groovy"
},
"Trees": {
"label": {
"Yellow fruit": "Pumpkin",
"White Flower": "Bogan"
}
}
}
Run Code Online (Sandbox Code Playgroud)
该方法的输入参数是以点分隔的键路径,从键路径="app.Garden.Flowers.white Flower"需要打印'Jasmine'.我的代码到目前为止:
import json
with open('data.json') as data_file:
j = json.load(data_file)
def find(element, JSON):
paths = element.split(".")
# print JSON[paths[0]][paths[1]][paths[2]][paths[3]]
for i in range(0,len(paths)):
data = JSON[paths[i]]
# data = data[paths[i+1]]
print …Run Code Online (Sandbox Code Playgroud) 我正在使用YAML在Swagger编辑器中进行API定义.我试图代表以下响应主体:
{
success: true,
ids: [123456, ...]
}
Run Code Online (Sandbox Code Playgroud)
这就是我的YAML的样子:
definitions:
SuccessfulResponse:
type: object
properties:
success:
type: boolean
description: True if the all operations were successful
ids:
type: array
items:
id:
type: string
Run Code Online (Sandbox Code Playgroud)
香港专业教育学院尝试了几种不同的方式,但是这样看似无效
如何正确描述上面给出的返回对象?
我对Ansible很新.我正在尝试遵循Ansible中角色概念的教程.我有以下主手册:
--- # Master Playbook for Webservers
- hosts: apacheweb
user: test
sudo: yes
connection: ssh
roles:
- webservers
Run Code Online (Sandbox Code Playgroud)
这是指具有以下任务/ main.yml的Web服务器角色:
- name: Install Apache Web Server
yum: pkg=httpd state=latest
notify: Restart HTTPD
Run Code Online (Sandbox Code Playgroud)
还有一个handler/main.yml:
- name: Restart HTTPD
service: name=httpd state=started
Run Code Online (Sandbox Code Playgroud)
当我执行上面提到的Master Playbook时,我收到以下错误:
TASK [webservers : Install Apache Web Server] **********************************
fatal: [test.server.com]: FAILED! => {"changed": false, "failed": true, "msg": "The following packages have pending transactions: httpd-x86_64", "rc": 128, "results": ["The following packages have …Run Code Online (Sandbox Code Playgroud) 在with_items为目标部分执行预处理时,我正在尝试多个连接.
现在它看起来像这样:
- name: create app except+lookup
copy: content="" dest="{{ dir.comp ~ '/config/con2dd/' ~ item.name ~ 'File.txt' }}" force=no group=devops owner=devops mode: 0755
with_items:
...
Run Code Online (Sandbox Code Playgroud)
我明白了:
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
Run Code Online (Sandbox Code Playgroud)
尝试了几种方法,但没有一种方法可以实现.
是否可以用字符串连接变量?
python ×4
yaml ×3
ansible ×2
django ×2
pyyaml ×2
swagger ×2
dictionary ×1
drawing ×1
graphics ×1
json ×1
jsonschema ×1
pip ×1
pretty-print ×1
ruby ×1
sql ×1
sqlite ×1
swagger-2.0 ×1
virtualenv ×1
yum ×1