mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge branch 'master' of https://github.com/LCTT/TranslateProject into new
This commit is contained in:
commit
9d2132178c
@ -1,57 +1,27 @@
|
||||
Docker 指南:Docker 化 Python Django 应用程序
|
||||
如何 Docker 化 Python Django 应用程序
|
||||
======
|
||||
|
||||
### 目录
|
||||
|
||||
1. [我们要做什么?][6]
|
||||
|
||||
2. [步骤 1 - 安装 Docker-ce][7]
|
||||
|
||||
3. [步骤 2 - 安装 Docker-compose][8]
|
||||
|
||||
4. [步骤 3 - 配置项目环境][9]
|
||||
1. [创建一个新的 requirements.txt 文件][1]
|
||||
|
||||
2. [创建 Nginx 虚拟主机文件 django.conf][2]
|
||||
|
||||
3. [创建 Dockerfile][3]
|
||||
|
||||
4. [创建 Docker-compose 脚本][4]
|
||||
|
||||
5. [配置 Django 项目][5]
|
||||
|
||||
5. [步骤 4 - 构建并运行 Docker 镜像][10]
|
||||
|
||||
6. [步骤 5 - 测试][11]
|
||||
|
||||
7. [参考][12]
|
||||
|
||||
|
||||
Docker 是一个开源项目,为开发人员和系统管理员提供了一个开放平台,作为一个轻量级容器,它可以在任何地方构建,打包和运行应用程序。Docker 在软件容器中自动部署应用程序。
|
||||
Docker 是一个开源项目,为开发人员和系统管理员提供了一个开放平台,可以将应用程序构建、打包为一个轻量级容器,并在任何地方运行。Docker 会在软件容器中自动部署应用程序。
|
||||
|
||||
Django 是一个用 Python 编写的 Web 应用程序框架,遵循 MVC(模型-视图-控制器)架构。它是免费的,并在开源许可下发布。它速度很快,旨在帮助开发人员尽快将他们的应用程序上线。
|
||||
|
||||
在本教程中,我将逐步向你展示在 Ubuntu 16.04 如何为现有的 Django 应用程序创建 docker 镜像。我们将学习如何 docker 化一个 Python Django 应用程序,然后使用一个 docker-compose 脚本将应用程序作为容器部署到 docker 环境。
|
||||
在本教程中,我将逐步向你展示在 Ubuntu 16.04 中如何为现有的 Django 应用程序创建 docker 镜像。我们将学习如何 docker 化一个 Python Django 应用程序,然后使用一个 `docker-compose` 脚本将应用程序作为容器部署到 docker 环境。
|
||||
|
||||
为了部署我们的 Python Django 应用程序,我们需要其他 docker 镜像:一个用于 Web 服务器的 nginx docker 镜像和用于数据库的 PostgreSQL 镜像。
|
||||
为了部署我们的 Python Django 应用程序,我们需要其它 docker 镜像:一个用于 Web 服务器的 nginx docker 镜像和用于数据库的 PostgreSQL 镜像。
|
||||
|
||||
### 我们要做什么?
|
||||
|
||||
1. 安装 Docker-ce
|
||||
|
||||
2. 安装 Docker-compose
|
||||
|
||||
3. 配置项目环境
|
||||
|
||||
4. 构建并运行
|
||||
|
||||
5. 测试
|
||||
|
||||
### 步骤 1 - 安装 Docker-ce
|
||||
|
||||
在本教程中,我们将重 docker 仓库安装 docker-ce 社区版。我们将安装 docker-ce 社区版和 docker-compose,其支持 compose 文件版本 3(to 校正者:此处不太明白具体意思)。
|
||||
在本教程中,我们将从 docker 仓库安装 docker-ce 社区版。我们将安装 docker-ce 社区版和 `docker-compose`(其支持 compose 文件版本 3)。
|
||||
|
||||
在安装 docker-ce 之前,先使用 apt 命令安装所需的 docker 依赖项。
|
||||
在安装 docker-ce 之前,先使用 `apt` 命令安装所需的 docker 依赖项。
|
||||
|
||||
```
|
||||
sudo apt install -y \
|
||||
@ -71,7 +41,7 @@ sudo add-apt-repository \
|
||||
stable"
|
||||
```
|
||||
|
||||
[![安装 Docker-ce](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/1.png)][14]
|
||||
[![安装 Docker-ce](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/1.png)][14]
|
||||
|
||||
更新仓库并安装 docker-ce。
|
||||
|
||||
@ -87,16 +57,16 @@ systemctl start docker
|
||||
systemctl enable docker
|
||||
```
|
||||
|
||||
接着,我们将添加一个名为 'omar' 的新用户并将其添加到 docker 组。
|
||||
接着,我们将添加一个名为 `omar` 的新用户并将其添加到 `docker` 组。
|
||||
|
||||
```
|
||||
useradd -m -s /bin/bash omar
|
||||
usermod -a -G docker omar
|
||||
```
|
||||
|
||||
[![启动 Docker](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/2.png)][15]
|
||||
[![启动 Docker](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/2.png)][15]
|
||||
|
||||
以 omar 用户身份登录并运行 docker 命令,如下所示。
|
||||
以 `omar` 用户身份登录并运行 `docker` 命令,如下所示。
|
||||
|
||||
```
|
||||
su - omar
|
||||
@ -107,13 +77,13 @@ docker run hello-world
|
||||
|
||||
[![检查 Docker 安装](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/3.png)][16]
|
||||
|
||||
Docker-ce 安装已经完成。
|
||||
Docker-ce 安装已经完成。
|
||||
|
||||
### 步骤 2 - 安装 Docker-compose
|
||||
### 步骤 2 - 安装 Docker-compose
|
||||
|
||||
在本教程中,我们将使用最新的 docker-compose 支持 compose 文件版本 3。我们将手动安装 docker-compose。
|
||||
在本教程中,我们将使用支持 compose 文件版本 3 的最新 `docker-compose`。我们将手动安装 `docker-compose`。
|
||||
|
||||
使用 curl 命令将最新版本的 docker-compose 下载到 `/usr/local/bin` 目录,并使用 chmod 命令使其有执行权限。
|
||||
使用 `curl` 命令将最新版本的 `docker-compose` 下载到 `/usr/local/bin` 目录,并使用 `chmod` 命令使其有执行权限。
|
||||
|
||||
运行以下命令:
|
||||
|
||||
@ -122,7 +92,7 @@ sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-c
|
||||
sudo chmod +x /usr/local/bin/docker-compose
|
||||
```
|
||||
|
||||
现在检查 docker-compose 版本。
|
||||
现在检查 `docker-compose` 版本。
|
||||
|
||||
```
|
||||
docker-compose version
|
||||
@ -132,26 +102,26 @@ docker-compose version
|
||||
|
||||
[![安装 Docker-compose](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/4.png)][17]
|
||||
|
||||
已安装支持 compose 文件版本 3 的 docker-compose 最新版本。
|
||||
已安装支持 compose 文件版本 3 的 `docker-compose` 最新版本。
|
||||
|
||||
### 步骤 3 - 配置项目环境
|
||||
|
||||
在这一步中,我们将配置 Python Django 项目环境。我们将创建新目录 'guide01',并使其成为我们项目文件的主目录,例如 Dockerfile,Django 项目,nginx 配置文件等。
|
||||
在这一步中,我们将配置 Python Django 项目环境。我们将创建新目录 `guide01`,并使其成为我们项目文件的主目录,例如包括 Dockerfile、Django 项目、nginx 配置文件等。
|
||||
|
||||
登录到 'omar' 用户。
|
||||
登录到 `omar` 用户。
|
||||
|
||||
```
|
||||
su - omar
|
||||
```
|
||||
|
||||
创建一个新目录 'guide01',并进入目录。
|
||||
创建一个新目录 `guide01`,并进入目录。
|
||||
|
||||
```
|
||||
mkdir -p guide01
|
||||
cd guide01/
|
||||
```
|
||||
|
||||
现在在 'guide01' 目录下,创建两个新目录 'project' 和 'config'。
|
||||
现在在 `guide01` 目录下,创建两个新目录 `project` 和 `config`。
|
||||
|
||||
```
|
||||
mkdir project/ config/
|
||||
@ -159,118 +129,151 @@ mkdir project/ config/
|
||||
|
||||
注意:
|
||||
|
||||
* 'project' 目录:我们所有的 python Django 项目文件都将放在该目录中。
|
||||
* `project` 目录:我们所有的 python Django 项目文件都将放在该目录中。
|
||||
* `config` 目录:项目配置文件的目录,包括 nginx 配置文件、python pip 的`requirements.txt` 文件等。
|
||||
|
||||
* 'config' 目录:项目配置文件的目录,包括 nginx 配置文件,python pip requirements 文件等。
|
||||
#### 创建一个新的 requirements.txt 文件
|
||||
|
||||
### 创建一个新的 requirements.txt 文件
|
||||
|
||||
接下来,使用 vim 命令在 'config' 目录中创建一个新的 requirements.txt 文件
|
||||
接下来,使用 `vim` 命令在 `config` 目录中创建一个新的 `requirements.txt` 文件。
|
||||
|
||||
```
|
||||
vim config/requirements.txt
|
||||
```
|
||||
|
||||
粘贴下面的配置。
|
||||
粘贴下面的配置:
|
||||
|
||||
```
|
||||
Django==2.0.4
|
||||
gunicorn==19.7.0
|
||||
psycopg2==2.7.4
|
||||
gunicorn==19.7.0
|
||||
psycopg2==2.7.4
|
||||
```
|
||||
|
||||
保存并退出。
|
||||
|
||||
### 创建 Dockerfile
|
||||
#### 创建 Nginx 虚拟主机文件 django.conf
|
||||
|
||||
在 'guide01' 目录下创建新文件 'Dockerfile'。
|
||||
在 `config` 目录下创建 nginx 配置目录并添加虚拟主机配置文件 `django.conf`。
|
||||
|
||||
运行以下命令。
|
||||
```
|
||||
mkdir -p config/nginx/
|
||||
vim config/nginx/django.conf
|
||||
```
|
||||
|
||||
粘贴下面的配置:
|
||||
|
||||
```
|
||||
upstream web {
|
||||
ip_hash;
|
||||
server web:8000;
|
||||
}
|
||||
|
||||
# portal
|
||||
server {
|
||||
location / {
|
||||
proxy_pass http://web/;
|
||||
}
|
||||
listen 8000;
|
||||
server_name localhost;
|
||||
|
||||
location /static {
|
||||
autoindex on;
|
||||
alias /src/static/;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
保存并退出。
|
||||
|
||||
#### 创建 Dockerfile
|
||||
|
||||
在 `guide01` 目录下创建新文件 `Dockerfile`。
|
||||
|
||||
运行以下命令:
|
||||
|
||||
```
|
||||
vim Dockerfile
|
||||
```
|
||||
|
||||
现在粘贴下面的 Dockerfile 脚本。
|
||||
现在粘贴下面的 Dockerfile 脚本:
|
||||
|
||||
```
|
||||
FROM python:3.5-alpine
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
RUN apk update && \
|
||||
apk add --virtual build-deps gcc python-dev musl-dev && \
|
||||
apk add postgresql-dev bash
|
||||
RUN apk update && \
|
||||
apk add --virtual build-deps gcc python-dev musl-dev && \
|
||||
apk add postgresql-dev bash
|
||||
|
||||
RUN mkdir /config
|
||||
ADD /config/requirements.txt /config/
|
||||
RUN pip install -r /config/requirements.txt
|
||||
RUN mkdir /src
|
||||
WORKDIR /src
|
||||
RUN mkdir /config
|
||||
ADD /config/requirements.txt /config/
|
||||
RUN pip install -r /config/requirements.txt
|
||||
RUN mkdir /src
|
||||
WORKDIR /src
|
||||
```
|
||||
|
||||
保存并退出。
|
||||
|
||||
注意:
|
||||
|
||||
我们想要为我们的 Django 项目构建基于 Alpine Linux 的 Docker 镜像,Alpine 是最小的 Linux 版本。我们的 Django 项目将运行在带有 Python3.5 的 Alpine Linux 上,并添加 postgresql-dev 包以支持 PostgreSQL 数据库。然后,我们将使用 python pip 命令安装在 'requirements.txt' 上列出的所有 Python 包,并为我们的项目创建新目录 '/src'。
|
||||
我们想要为我们的 Django 项目构建基于 Alpine Linux 的 Docker 镜像,Alpine 是最小的 Linux 版本。我们的 Django 项目将运行在带有 Python 3.5 的 Alpine Linux 上,并添加 postgresql-dev 包以支持 PostgreSQL 数据库。然后,我们将使用 python `pip` 命令安装在 `requirements.txt` 上列出的所有 Python 包,并为我们的项目创建新目录 `/src`。
|
||||
|
||||
### 创建 Docker-compose 脚本
|
||||
#### 创建 Docker-compose 脚本
|
||||
|
||||
使用 [vim][18] 命令在 'guide01' 目录下创建 'docker-compose.yml' 文件。
|
||||
使用 [vim][18] 命令在 `guide01` 目录下创建 `docker-compose.yml` 文件。
|
||||
|
||||
```
|
||||
vim docker-compose.yml
|
||||
```
|
||||
|
||||
粘贴以下配置内容。
|
||||
粘贴以下配置内容:
|
||||
|
||||
```
|
||||
version: '3'
|
||||
services:
|
||||
db:
|
||||
image: postgres:10.3-alpine
|
||||
container_name: postgres01
|
||||
nginx:
|
||||
image: nginx:1.13-alpine
|
||||
container_name: nginx01
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- ./project:/src
|
||||
- ./config/nginx:/etc/nginx/conf.d
|
||||
depends_on:
|
||||
- web
|
||||
web:
|
||||
build: .
|
||||
container_name: django01
|
||||
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn hello_django.wsgi -b 0.0.0.0:8000"
|
||||
depends_on:
|
||||
- db
|
||||
volumes:
|
||||
- ./project:/src
|
||||
expose:
|
||||
- "8000"
|
||||
restart: always
|
||||
services:
|
||||
db:
|
||||
image: postgres:10.3-alpine
|
||||
container_name: postgres01
|
||||
nginx:
|
||||
image: nginx:1.13-alpine
|
||||
container_name: nginx01
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- ./project:/src
|
||||
- ./config/nginx:/etc/nginx/conf.d
|
||||
depends_on:
|
||||
- web
|
||||
web:
|
||||
build: .
|
||||
container_name: django01
|
||||
command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput && gunicorn hello_django.wsgi -b 0.0.0.0:8000"
|
||||
depends_on:
|
||||
- db
|
||||
volumes:
|
||||
- ./project:/src
|
||||
expose:
|
||||
- "8000"
|
||||
restart: always
|
||||
```
|
||||
|
||||
保存并退出。
|
||||
|
||||
注意:
|
||||
|
||||
使用这个 docker-compose 文件脚本,我们将创建三个服务。使用 PostgreSQL alpine Linux 创建名为 'db' 的数据库服务,再次使用 Nginx alpine Linux 创建 'nginx' 服务,并使用从 Dockerfile 生成的自定义 docker 镜像创建我们的 python Django 容器。
|
||||
使用这个 `docker-compose` 文件脚本,我们将创建三个服务。使用 alpine Linux 版的 PostgreSQL 创建名为 `db` 的数据库服务,再次使用 alpine Linux 版的 Nginx 创建 `nginx` 服务,并使用从 Dockerfile 生成的自定义 docker 镜像创建我们的 python Django 容器。
|
||||
|
||||
[![配置项目环境](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/5.png)][19]
|
||||
[![配置项目环境](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/5.png)][19]
|
||||
|
||||
### 配置 Django 项目
|
||||
#### 配置 Django 项目
|
||||
|
||||
将 Django 项目文件复制到 'project' 目录。
|
||||
将 Django 项目文件复制到 `project` 目录。
|
||||
|
||||
```
|
||||
cd ~/django
|
||||
cp -r * ~/guide01/project/
|
||||
```
|
||||
|
||||
进入 'project' 目录并编辑应用程序设置 'settings.py'。
|
||||
进入 `project` 目录并编辑应用程序设置 `settings.py`。
|
||||
|
||||
```
|
||||
cd ~/guide01/project/
|
||||
@ -279,29 +282,29 @@ vim hello_django/settings.py
|
||||
|
||||
注意:
|
||||
|
||||
我们将部署名为 'hello_django' 的简单 Django 应用程序。
|
||||
我们将部署名为 “hello_django” 的简单 Django 应用程序。
|
||||
|
||||
在 'ALLOW_HOSTS' 行中,添加服务名称 'web'。
|
||||
在 `ALLOW_HOSTS` 行中,添加服务名称 `web`。
|
||||
|
||||
```
|
||||
ALLOW_HOSTS = ['web']
|
||||
```
|
||||
|
||||
现在更改数据库设置,我们将使用 PostgreSQL 数据库,'db' 数据库作为服务运行,使用默认用户和密码。
|
||||
现在更改数据库设置,我们将使用 PostgreSQL 数据库来运行名为 `db` 的服务,使用默认用户和密码。
|
||||
|
||||
```
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'postgres',
|
||||
'USER': 'postgres',
|
||||
'HOST': 'db',
|
||||
'PORT': 5432,
|
||||
}
|
||||
}
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'postgres',
|
||||
'USER': 'postgres',
|
||||
'HOST': 'db',
|
||||
'PORT': 5432,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
至于 'STATIC_ROOT' 配置目录,将此行添加到文件行的末尾。
|
||||
至于 `STATIC_ROOT` 配置目录,将此行添加到文件行的末尾。
|
||||
|
||||
```
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
|
||||
@ -309,21 +312,21 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
|
||||
|
||||
保存并退出。
|
||||
|
||||
[![配置 Django 项目](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/6.png)][20]
|
||||
[![配置 Django 项目](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/6.png)][20]
|
||||
|
||||
现在我们准备在 docker 容器下构建和运行 Django 项目。
|
||||
|
||||
### 步骤 4 - 构建并运行 Docker 镜像
|
||||
|
||||
在这一步中,我们想要使用 'guide01' 目录中的配置为我们的 Django 项目构建一个 Docker 镜像。
|
||||
在这一步中,我们想要使用 `guide01` 目录中的配置为我们的 Django 项目构建一个 Docker 镜像。
|
||||
|
||||
进入 'guide01' 目录。
|
||||
进入 `guide01` 目录。
|
||||
|
||||
```
|
||||
cd ~/guide01/
|
||||
```
|
||||
|
||||
现在使用 docker-compose 命令构建 docker 镜像。
|
||||
现在使用 `docker-compose` 命令构建 docker 镜像。
|
||||
|
||||
```
|
||||
docker-compose build
|
||||
@ -331,7 +334,7 @@ docker-compose build
|
||||
|
||||
[![运行 docker 镜像](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/7.png)][21]
|
||||
|
||||
启动 docker-compose 脚本中的所有服务。
|
||||
启动 `docker-compose` 脚本中的所有服务。
|
||||
|
||||
```
|
||||
docker-compose up -d
|
||||
@ -348,7 +351,7 @@ docker-compose ps
|
||||
docker-compose images
|
||||
```
|
||||
|
||||
现在,你将在系统上运行三个容器并列出 Docker 镜像,如下所示。
|
||||
现在,你将在系统上运行三个容器,列出 Docker 镜像,如下所示。
|
||||
|
||||
[![docke-compose ps 命令](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/9.png)][23]
|
||||
|
||||
@ -356,17 +359,19 @@ docker-compose images
|
||||
|
||||
### 步骤 5 - 测试
|
||||
|
||||
打开 Web 浏览器并使用端口 8000 键入服务器地址,我的是:http://ovh01:8000/
|
||||
打开 Web 浏览器并使用端口 8000 键入服务器地址,我的是:`http://ovh01:8000/`。
|
||||
|
||||
现在你将获得默认的 Django 主页。
|
||||
现在你将看到默认的 Django 主页。
|
||||
|
||||
[![默认 Django 项目主页](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/10.png)][24]
|
||||
|
||||
接下来,通过在 URL 上添加 “/admin” 路径来测试管理页面。
|
||||
接下来,通过在 URL 上添加 `/admin` 路径来测试管理页面。
|
||||
|
||||
```
|
||||
http://ovh01:8000/admin/
|
||||
```
|
||||
|
||||
然后你将会看到 Django admin 登录页面。
|
||||
然后你将会看到 Django 管理登录页面。
|
||||
|
||||
[![Django administration](https://www.howtoforge.com/images/docker_guide_dockerizing_python_django_application/11.png)][25]
|
||||
|
||||
@ -383,7 +388,7 @@ via: https://www.howtoforge.com/tutorial/docker-guide-dockerizing-python-django-
|
||||
|
||||
作者:[Muhammad Arul][a]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -0,0 +1,107 @@
|
||||
如何在 Ubuntu 或 Linux Mint 启用 Chromium 硬件加速的视频解码
|
||||
======
|
||||
|
||||
你或许已经注意到了,在 Linux 上使用 Google Chrome 或 Chromium 浏览器在 YouTube 或其它类似网站观看高清视频会增加你的 CPU 使用率,如果你用的是笔记本,电脑会发热而且电池会很快用完。这是因为 Chrome/Chromium(Firefox 也是如此,但是 Firefox 的问题没有办法解决)在 Linux 上不支持硬件加速的视频解码。
|
||||
|
||||
这篇文章讲述了如何在 Linux 环境安装带有 VA-API 补丁的 Chromium 开发版,它支持 GPU 加速的视频解码,可以显著减少观看在线高清视频时的 CPU 使用率,这篇教程只适用于 Intel 和 Nvidia 的显卡,我没有 ATI/AMD 的显卡可以试验,也没有使用过这几种显卡。
|
||||
|
||||
这是 Chromium 浏览器在 Ubuntu18.04 中,在没有 GPU 加速视频解码的情况下播放一个 1080p 的 YouTube 视频:
|
||||
|
||||
![](https://4.bp.blogspot.com/-KtUQni2PMvE/W3KlJ62yLLI/AAAAAAAABW4/NrNVFaTAkZ8AmwqWwRvWD6czT51ni-R-gCLcBGAs/s1600/chromium-default-no-accel.png)
|
||||
|
||||
这是带有 VA-API 补丁的 Chromium 浏览器在 Ubuntu18.04 中,在带有 GPU 加速视频解码的情况下播放同样的 1080p 的 YouTube 视频:
|
||||
|
||||
![](https://4.bp.blogspot.com/-0c-wb4UNhW8/W3KlQBfeFnI/AAAAAAAABW8/WVUAYzM6hA8wRTlCcrPXPMpoXoFVR6b1QCLcBGAs/s1600/chromium-hardware-acceleration-enabled.png)
|
||||
|
||||
注意截图中的 CPU 使用率。两张截图都是在我老旧而依然强大的桌面计算机上捕捉的。在我的笔记本电脑上,没有硬件加速的 Chromium 带来更高的 CPU 使用率。
|
||||
|
||||
“只需 VA-API 即可在 Linux 启用 VAVDA、VAVEA 和 VAJDA” 这个[补丁][3]在一年多以前就提交给了 Chromium,但是它还没有合并。
|
||||
|
||||
Chrome 有一个选项可以覆盖软件渲染列表(`#ignore-gpu-blacklist`),但是这个选项不能启用硬件加速的视频解码。启用这个选项以后,你或许会在访问 `chrome://gpu` 时发现这些信息:“_Video Decode: Hardware accelerated_ “,然而这个并不意味着真的可以工作。在 YouTube 打开一个高清视频并用诸如 `htop` 的工具查看 CPU 使用率(这是我在以上截图中用来查看 CPU 使用率的)。因为 GPU 视频解码没有真的被启用,你应该看到较高的 CPU 使用率。下面有一个部分是关于检查你是否真的在使用硬件加速的视频解码的。
|
||||
|
||||
**文中使用的 Chromium 浏览器 Ubuntu 版启用 VA-API 的补丁在[这个地址][1]可以获得**
|
||||
|
||||
### 在 Ubuntu 和 Linux Mint 安装和使用带有 VA-API 支持的 Chromium 浏览器
|
||||
|
||||
每个人都该知道 Chromium 开发版本没有理想中那么稳定。所以你可能发现 bug,它可能会发生崩溃等情况。它现在可能正常运行,但是谁知道几次更新以后会发生什么。
|
||||
|
||||
还有,如果你想启用 Widevine 支持(这样你才能观看 Netflix 视频和 YouTube 付费视频),Chromium dev 分支 PPA 要求你执行一些额外步骤。 如果你想要一些功能,比如同步,也是如此(需要注册 API 密钥还要在你的系统上设置好)。执行这些任务的说明在 [Chromium 开发版本的 PPA][4] 中有详细解释。
|
||||
|
||||
对于 Nvidia 显卡,vdpau 视频驱动程序需要更新以便显示 vaQuerySurfaceAttributes。所以 Nvidia 需要使用打过补丁的 vdpau-va-driver。值得庆幸的是,Chromium-dev PPA 提供了这个打过补丁的包。
|
||||
|
||||
带有 VA-API 补丁的 Chromium 也可用于其它 Linux 发行版,在第三方仓库,比如说 [Arch Linux][5](对于 Nvidia 你需要[这个][6]补丁过的 libva-vdpau-driver)。如果你不使用 Ubuntu 或 Linux Mint,你得自己找那些包。
|
||||
|
||||
#### 1、安装带有 VA-API 补丁的 Chromium
|
||||
|
||||
有一个带 VA-API 补丁的 Chromium Beta PPA,但是它缺少适用于 Ubuntu 18.04 的 vdpau-video。如果你需要,你可以使用这个 [Beta PPA][7],而不是我在下面的步骤中使用 [Dev PPA][8],不过如果你使用 Nvidia 显卡,你需要从这个 Dev PPA 中下载安装 vdpau-va-driver,并确认 Ubuntu/Linux Mint 不更新这个包(有点复杂,如果你准备根据下面步骤使用 Dev PPA 的话,不需要手动做这些)。
|
||||
|
||||
你可以添加 [Chromium 开发分支 PPA][4],并在 Ubuntu 或 Linux Mint(及其它基于 Ubuntu 的发行版,如 elementary,以及 Ubuntu 或 Linux Mint 的风味版,如 Xubuntu、Kubuntu、Ubuntu MATE、Linux Mint MATE 等等)上安装最新的 Chromium 浏览器开发版:
|
||||
|
||||
|
||||
```
|
||||
sudo add-apt-repository ppa:saiarcot895/chromium-dev
|
||||
sudo apt-get update
|
||||
sudo apt install chromium-browser
|
||||
|
||||
```
|
||||
|
||||
#### 2、安装 VA-API 驱动
|
||||
|
||||
对于 Intel 的显卡,你需要安装 `i965-va-driver` 这个包(它可能早就安装好了)
|
||||
|
||||
```
|
||||
sudo apt install i965-va-driver
|
||||
```
|
||||
|
||||
对于 Nvidia 的显卡(在开源的 Nouveau 驱动和闭源的 Nvidia 驱动上,它应该都有效), 安装 `vdpau-va-driver`:
|
||||
|
||||
```
|
||||
sudo apt install vdpau-va-driver
|
||||
```
|
||||
|
||||
#### 3、在 Chromium 启用硬件加速视频选项
|
||||
|
||||
复制这串地址,粘贴进 Chromium 的 URL 栏: `chrome://flags/#enable-accelerated-video` (或者在 `chrome://flags` 搜索 `Hardware-accelerated video` )并启用它,然后重启 Chromium 浏览器。
|
||||
|
||||
在默认的 Google Chrome / Chromium 版本,这个选项不可用,但是你可以在启用了 VP-API 的 Chromium 版本启用它。
|
||||
|
||||
#### 4、安装 [h264ify][2] Chrome 扩展
|
||||
|
||||
YouTube(可能还有其它一些网址也是如此)默认使用 VP8 或 VP9 编码解码器,许多 GPU 不支持这种编码解码器的硬件解码。h264ify 会强制 YouTube 使用大多数 GPU 都支持的 H.264 而不是 VP8/VP9。
|
||||
|
||||
这个扩展还能阻塞 60fps 的视频,对低性能机器有用。
|
||||
|
||||
你可以在视频上右键点击,并且选择 `Stats for nerds` 以查看 Youtube 视频所使用额编码解码器,如果启用了 h264ify 扩展,你可以看到编码解码器是 avc / mp4a。如果没有启用,编码解码器应该是 vp09 / opus。
|
||||
|
||||
### 如何检查 Chromium 是否在使用 GPU 视频解码
|
||||
|
||||
在 YouTube 打开一个视频,然后,在 Chromium 打开一个新的标签页并将以下地址输入 URL 栏:`chrome://media-internals`。
|
||||
|
||||
在 `chrome://media-internals` 标签页中,点击视频的 URL(为了展开它), 往下滚动查看 `Player Properties` 的下面,你应该可以找到 `video_decoder` 属性。如果`video_decoder` 的值是 `GpuVideoDecoder` ,这说明当前在另一个标签页播放的 YouTube 视频正在使用硬件加速的的视频解码。
|
||||
|
||||
![](https://4.bp.blogspot.com/-COBJWVT_Y0Q/W3KnG7AeHsI/AAAAAAAABXM/W2XAJA_S0BIHug4eQKTMOdIfXHhgkXhhQCLcBGAs/s1600/chromium-gpuvideodecoder-linux.png)
|
||||
|
||||
如果它显示的是 `FFmpegVideoDecoder` 或 `VpxVideoDecoder` ,说明加速视频解码无效或者你忘记安装或禁用了 h264ify 这个 Chrome 扩展。
|
||||
|
||||
如果无效,你可以通过在命令行运行 `chromium-browser` ,通过查看是否有 VA-API 相关的错误显示出来以调试。你也可以运行 `vainfo`(在 Ubuntu 或 Linux Mint 上安装:`sudo apt install vainfo`)和 `vdpauinfo` (对于 Nvidia,在 Ubuntu 或 Linux Mint 上安装:`sudo apt install vdpauinfo`)并且查看是否有显示任何错误。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxuprising.com/2018/08/how-to-enable-hardware-accelerated.html
|
||||
|
||||
作者:[Logix][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[GraveAccent](https://github.com/GraveAccent)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://plus.google.com/118280394805678839070
|
||||
[1]:https://github.com/saiarcot895/chromium-ubuntu-build/tree/master/debian/patches
|
||||
[2]:https://chrome.google.com/webstore/detail/h264ify/aleakchihdccplidncghkekgioiakgal
|
||||
[3]:https://chromium-review.googlesource.com/c/chromium/src/+/532294
|
||||
[4]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev
|
||||
[5]:https://aur.archlinux.org/packages/?O=0&SeB=nd&K=chromium+vaapi&outdated=&SB=n&SO=a&PP=50&do_Search=Go
|
||||
[6]:https://aur.archlinux.org/packages/libva-vdpau-driver-chromium/
|
||||
[7]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-beta
|
||||
[8]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev/+packages
|
122
published/20180827 An introduction to diffs and patches.md
Normal file
122
published/20180827 An introduction to diffs and patches.md
Normal file
@ -0,0 +1,122 @@
|
||||
差异文件(diff)和补丁文件(patch)简介
|
||||
======
|
||||
|
||||
> 这篇文章介绍<ruby>差异文件<rt>diff</rt></ruby>和<ruby>补丁文件<rt>patch</rt></ruby>,以及它们如何在开源项目中使用的例子。
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/find-file-linux-code_magnifying_glass_zero.png?itok=E2HoPDg0)
|
||||
|
||||
如果你曾有机会在一个使用分布式开发模型的大型代码库上工作过,你就应该听说过类似下面的话,“Sue 刚发过来一个<ruby>补丁<rt>patch</rt></ruby>”,“Rajiv 正在<ruby>签出<rt>checking out</rt></ruby><ruby>差异<rt>diff</rt></ruby>”, 可能这些词(补丁、差异文件)对你而言很陌生,而你确定很想搞懂他们到底指什么。开源软件对上述提到的名词有很大的贡献,作为大型项目从 Apache web 服务器到 Linux 内核的开发模型,“基于补丁文件的开发” 这一模式贯穿了上述项目的始终。实际上,你可能不知道 Apache 的名字就来自“一系列的代码补丁”(LCTT 译注:Apache 英文发音和补丁的英文 patch 相似),它们被一一收集起来并针对原来的 [NCSA HTTPd server source code][1] 进行了修订。
|
||||
|
||||
你可能认为这只不过是些逸闻,但是一份早期的 [Apache 网站的存档中][2] 声称 Apache 的名字就是来自于最早的“补丁”集合;即“<ruby>打了补丁的<rt>APAtCHy</rt></ruby>”服务器,简化为 Apache。
|
||||
|
||||
好了,言归正传,程序员嘴里说的“差异”和“补丁”到底是什么?
|
||||
|
||||
首先,在这篇文章里,我们可以认为这两个术语都指向同一个概念。“diff” 是 ”difference“ 的简写;Unix 下的同名工具程序 `diff`剖析了一个或多个文件之间的“差异”。下面我们会看到 `diff` 的例子:
|
||||
|
||||
一个“补丁”指的是文件之间一系列差异,这些差异能被 Unix 的 `diff` 程序应用在源代码树上。我们能使用 `diff` 工具来创建“差异”(或“补丁”),然后使用该工具将它们 “打” 在一个没有这个补丁的同样的源代码版本上。此外,(我又要开始跑题说些历史轶事了……),“补丁” 这个词真的指在计算机的早期使用打卡机的时候,用来覆盖在打孔纸带上来对软件进行修改的覆盖纸,那个时代打孔纸带就是在计算机处理器上运行的程序。下面来自 [维基页面][3] 的这张图真切的描绘了最初的“打补丁”这个词的出处:
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/360px-harvard_mark_i_program_tape.agr_.jpg)
|
||||
|
||||
现在你对补丁和差异就了一个基本的概念,让我们来看看软件开发者是怎么使用这些工具的。如果你还没有使用过类似于 [Git][4] 或 [subversion][5] 这样的源代码版本控制工具的话,我将会一步步展示最流行的软件项目是怎么使用它们的。如果你将一个软件的生命周期看成是一条时间线的话,你就能看见这个软件的点滴变化,比如在何时源代码加上了一个功能,在何时源代码修复了一个功能缺陷。我们称这些改变的点为“<ruby>提交<rt>commit</rt></ruby>”,“提交”这个词被当今最流行的源代码版本管理工具 Git 所使用,当你想检查在一个提交前后的代码变化的话,(或者在许多个提交之间的代码变化),你都可以使用工具来观察文件差异。
|
||||
|
||||
如果你同样在使用 Git 开发软件的话,你可以在你的本地开发环境做些希望交给别的开发者的提交,以添加到他们的源代码树中。为了给别的开发者你的提交,一个方法就是创建一个你本地文件的差异文件,然后将这个“补丁”发送给和你工作在同一个源代码树的别的开发者。别的开发者在“打”了你的补丁之后,就能看到在你的代码变树上的变化。
|
||||
|
||||
### Linux、Git 和 GitHub
|
||||
|
||||
这种分享补丁的开发模型正是现今 Linux 内核社区如何处理内核修改提议而采用的模型。如果你有机会浏览任何一个主流的 Linux 内核邮件列表 —— 主要是 [LKML][6],也包括 [linux-containers][7]、[fs-devel][8]、[Netdev][9] 等等,你能看到很多开发者会贴出他们想让其他内核开发者审核、测试或者合入 Linux 官方 Git 代码树某个位置的补丁。当然,讨论 Git 不在这篇文章范围之内(Git 是由 Linus Torvalds 开发的源代码控制系统,它支持分布式开发模型以及允许独立于主要代码仓库的补丁包,这些补丁包能被推送或拉取到不同的源代码树上,并遵守这些代码树各自的开发流程。)
|
||||
|
||||
在继续我们的话题之前,我们当然不能忽略和补丁和差异这个概念相关的最流行的服务:[GitHub][10]。从它的名字就能猜想出 GitHub 是基于 Git 的,而且它还围绕着 Git 对分布式开源代码开发模型提供了基于 Web 和 API 的工作流管理。(LCTT 译注:即<ruby>拉取请求<rt>Pull Request</rt></ruby>)。在 GitHub 上,分享补丁的方式不是像 Linux 内核社区那样通过邮件列表,而是通过创建一个 **拉取请求** 。当你提交你自己的源代码树的改动时,你能通过创建一个针对软件项目的共享仓库的“拉取请求”来分享你的代码改动(LCTT 译注:即核心开发者维护一个主仓库,开发者去“<ruby>复刻<rt>fork</rt></ruby>”这个仓库,待各自的提交后再创建针对这个主仓库的拉取请求,所有的拉取请求由主仓库的核心开发者批准后才能合入主代码库。)GitHub 被当今很多活跃的开源社区所采用,如 [Kubernetes][11]、[Docker][12]、[容器网络接口 (CNI)][13]、[Istio][14] 等等。在 GitHub 的世界里,用户会倾向于使用基于 Web 页面的方式来审核一个拉取请求里的补丁或差异,你也可以直接访问原始的补丁并在命令行上直接使用它们。
|
||||
|
||||
### 该说点干货了
|
||||
|
||||
我们前面已经讲了在流行的开源社区里是怎么应用补丁和差异的,现在看看一些例子。
|
||||
|
||||
第一个例子包括一个源代码树的两个不同副本,其中一个有代码改动,我们想用 `diff` 来看看这些改动是什么。这个例子里,我们想看的是“<ruby>合并格式<rt>unified</rt></ruby>”的补丁,这是现在软件开发世界里最通用的格式。如果想知道更详细参数的用法以及如何生成差异文件,请参考 `diff` 手册。原始的代码在 `sources-orig` 目录,而改动后的代码在 `sources-fixed` 目录。如果要在你的命令行上用“合并格式”来展示补丁,请运行如下命令。(LCTT 译注:参数 `-N` 代表如果比较的文件不存在,则认为是个空文件, `-a` 代表将所有文件都作为文本文件对待,`-u` 代表使用合并格式并输出上下文,`-r` 代表递归比较目录)
|
||||
|
||||
|
||||
```
|
||||
$ diff -Naur sources-orig/ sources-fixed/
|
||||
```
|
||||
|
||||
……下面是 `diff` 命令的输出:
|
||||
|
||||
```
|
||||
diff -Naur sources-orig/officespace/interest.go sources-fixed/officespace/interest.go
|
||||
--- sources-orig/officespace/interest.go 2018-08-10 16:39:11.000000000 -0400
|
||||
+++ sources-fixed/officespace/interest.go 2018-08-10 16:39:40.000000000 -0400
|
||||
@@ -11,15 +11,13 @@
|
||||
InterestRate float64
|
||||
}
|
||||
|
||||
+// compute the rounded interest for a transaction
|
||||
func computeInterest(acct *Account, t Transaction) float64 {
|
||||
|
||||
interest := t.Amount * t.InterestRate
|
||||
roundedInterest := math.Floor(interest*100) / 100.0
|
||||
remainingInterest := interest - roundedInterest
|
||||
|
||||
- // a little extra..
|
||||
- remainingInterest *= 1000
|
||||
-
|
||||
// Save the remaining interest into an account we control:
|
||||
acct.Balance = acct.Balance + remainingInterest
|
||||
```
|
||||
|
||||
最开始几行 `diff` 命令的输出可以这样解释:三个 `---` 显示了原来文件的名字;任何在原文件(LCTT 译注:不是源文件)里存在而在新文件里不存在的行将会用前缀 `-`,用来表示这些行被从源代码里“减去”了。而 `+++` 表示的则相反:在新文件里被加上的行会被放上前缀 `+`,表示这是在新文件里被“加上”的行。补丁文件中的每一个补丁“块”(用 `@@` 作为前缀的的部分)都有上下文的行号,这能帮助补丁工具(或其它处理器)知道在代码的哪里应用这个补丁块。你能看到我们已经修改了“Office Space”这部电影里提到的那个函数(移除了三行并加上了一行代码注释),电影里那个有点贪心的工程师可是偷偷的在计算利息的函数里加了点“料”哦。(LCTT译注:剧情详情请见电影 https://movie.douban.com/subject/1296424/)
|
||||
|
||||
如果你想找人来测试你的代码改动,你可以将差异保存到一个补丁里:
|
||||
|
||||
```
|
||||
$ diff -Naur sources-orig/ sources-fixed/ >myfixes.patch
|
||||
```
|
||||
|
||||
现在你有补丁 `myfixes.patch` 了,你能把它分享给别的开发者,他们可以将这个补丁打在他们自己的源代码树上从而得到和你一样的代码并测试他们。如果一个开发者的当前工作目录就是他的源代码树的根的话,他可以用下面的命令来打补丁:
|
||||
|
||||
```
|
||||
$ patch -p1 < ../myfixes.patch
|
||||
patching file officespace/interest.go
|
||||
```
|
||||
|
||||
现在这个开发者的源代码树已经打好补丁并准备好构建和测试文件的修改了。那么如果这个开发者在打补丁之前已经改动过了怎么办?只要这些改动没有直接冲突(LCTT 译注:比如改在同一行上),补丁工具就能自动的合并代码的改动。例如下面的interest.go 文件,它有其它几处改动,然后它想打上 `myfixes.patch` 这个补丁:
|
||||
|
||||
```
|
||||
$ patch -p1 < ../myfixes.patch
|
||||
patching file officespace/interest.go
|
||||
Hunk #1 succeeded at 26 (offset 15 lines).
|
||||
```
|
||||
|
||||
在这个例子中,补丁警告说代码改动并不在文件原来的地方而是偏移了 15 行。如果你文件改动的很厉害,补丁可能干脆说找不到要应用的地方,还好补丁程序提供了提供了打开“模糊”匹配的选项(这个选项在文档里有预置的警告信息,对其讲解已经超出了本文的范围)。
|
||||
|
||||
如果你使用 Git 或者 GitHub 的话,你可能不会直接使用补丁或差异。Git 已经内置了这些功能,你能使用这些功能和共享一个源代码树的其他开发者交互,拉取或合并代码。Git 一个比较相近的功能是可以使用 `git diff` 来对你的本地代码树生成全局差异,又或者对你的任意两次”引用“(可能是一个代表提交的数字,或一个标记或分支的名字,等等)做全局补丁。你甚至能简单的用管道将 `git diff` 的输出到一个文件里(这个文件必须严格符合将要被使用它的程序的输入要求),然后将这个文件交给一个并不使用 Git 的开发者应用到他的代码上。当然,GitHub 把这些功能放到了 Web 上,你能直接在 Web 页面上查看一个拉取请求的文件变动。在 Web 上你能看到所展示的合并差异,GitHub 还允许你将这些代码改动下载为原始的补丁文件。
|
||||
|
||||
### 总结
|
||||
|
||||
好了,你已经学到了”差异“和”补丁“是什么,以及在 Unix/Linux 上怎么使用命令行工具和它们交互。除非你还在像 Linux 内核开发这样的项目中工作而使用完全基于补丁文件的开发方式,你应该会主要通过你的源代码控制系统(如 Git)来使用补丁。但熟悉像 GitHub 这样的高级别工具的技术背景和技术底层对你的工作也是大有裨益的。谁知道会不会有一天你需要和一个来自 Linux 世界邮件列表的补丁包打交道呢?
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/8/diffs-patches
|
||||
|
||||
作者:[Phil Estes][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[David Chen](https://github.com/DavidChenLiang)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/estesp
|
||||
[1]:https://github.com/TooDumbForAName/ncsa-httpd
|
||||
[2]:https://web.archive.org/web/19970615081902/http:/www.apache.org/info.html
|
||||
[3]:https://en.wikipedia.org/wiki/Patch_(computing)
|
||||
[4]:https://git-scm.com/
|
||||
[5]:https://subversion.apache.org/
|
||||
[6]:https://lkml.org/
|
||||
[7]:https://lists.linuxfoundation.org/pipermail/containers/
|
||||
[8]:https://patchwork.kernel.org/project/linux-fsdevel/list/
|
||||
[9]:https://www.spinics.net/lists/netdev/
|
||||
[10]:https://github.com/
|
||||
[11]:https://kubernetes.io/
|
||||
[12]:https://www.docker.com/
|
||||
[13]:https://github.com/containernetworking/cni
|
||||
[14]:https://istio.io/
|
@ -1,6 +1,8 @@
|
||||
8 个用于<ruby>业余项目<rt>side projects</rt></ruby>的优秀 Python 库
|
||||
8 个用于业余项目的优秀 Python 库
|
||||
======
|
||||
|
||||
> 这些库可以使你更容易构架个人项目。
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/python-programming-code-keyboard.png?itok=fxiSpmnd)
|
||||
|
||||
在 Python/Django 的世界里有这样一个谚语:为语言而来,为社区而留。对绝大多数人来说的确是这样的,但是,还有一件事情使得我们一直停留在 Python 的世界里,不愿离开,那就是我们可以很容易地利用一顿午餐或晚上几个小时的时间,把一个想法快速地实现出来。
|
||||
@ -9,7 +11,7 @@
|
||||
|
||||
### 在数据库中即时保存数据:Dataset
|
||||
|
||||
当我们想要在不知道最终数据库表长什么样的情况下,快速收集数据并保存到数据库中的时候,[Dataset][1] 库将是我们的最佳选择。Dataset 库有一个简单但功能强大的 API,因此我们可以很容易的把数据保存下来,之后再进行排序。
|
||||
当我们想要在不知道最终数据库表长什么样的情况下,快速收集数据并保存到数据库中的时候,[Dataset][1] 库将是我们的最佳选择。Dataset 库有一个简单但功能强大的 API,因此我们可以很容易的把数据保存下来,之后再进行整理。
|
||||
|
||||
Dataset 建立在 SQLAlchemy 之上,所以如果需要对它进行扩展,你会感到非常熟悉。使用 Django 内建的 [inspectdb][2] 管理命令可以很容易地把底层数据库模型导入 Django 中,这使得和现有数据库一同工作不会出现任何障碍。
|
||||
|
||||
@ -35,13 +37,13 @@ Dataset 建立在 SQLAlchemy 之上,所以如果需要对它进行扩展,你
|
||||
|
||||
### 把 CSV 文件转换到 API 中:DataSette
|
||||
|
||||
[DataSette][8] 是一个神奇的工具,它可以很容易地把 CSV 文件转换进全特性只读 REST JSON API,同时,不要把它和 Dataset 库混淆。Datasette 有许多特性,包括创建图表和 geo(用于创建交互式图表),并且很容易通过容器或第三方网络主机进行部署。
|
||||
[DataSette][8] 是一个神奇的工具,它可以很容易地把 CSV 文件转换为全特性的只读 REST JSON API,同时,不要把它和 Dataset 库混淆。Datasette 有许多特性,包括创建图表和 geo(用于创建交互式地图),并且很容易通过容器或第三方网络主机进行部署。
|
||||
|
||||
### 处理环境变量等:Envparse
|
||||
|
||||
如果你不想在源代码中保存 API 密钥、数据库凭证或其他敏感信息,那么你便需要解析环境变量,这时候 [envparse][9] 是最好的选择。Envparse 能够处理环境变量、ENV 文件、变量类型,甚至还可以进行预处理和后处理(例如,你想要确保变量名总是大写或小写的)
|
||||
如果你不想在源代码中保存 API 密钥、数据库凭证或其他敏感信息,那么你便需要解析环境变量,这时候 [envparse][9] 是最好的选择。Envparse 能够处理环境变量、ENV 文件、变量类型,甚至还可以进行预处理和后处理(例如,你想要确保变量名总是大写或小写的)。
|
||||
|
||||
有什么你最喜欢的用于<ruby>业余项目<rt>side projects</rt></ruby>的 Python 库不在这个列表中吗?请在评论中和我们分享。
|
||||
有什么你最喜欢的用于业余项目的 Python 库不在这个列表中吗?请在评论中和我们分享。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -50,7 +52,7 @@ via: https://opensource.com/article/18/9/python-libraries-side-projects
|
||||
作者:[Jeff Triplett][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[ucasFL](https://github.com/ucasFL)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,113 +0,0 @@
|
||||
How To Enable Hardware Accelerated Video Decoding In Chromium On Ubuntu Or Linux Mint
|
||||
======
|
||||
You may have noticed that watching HD videos from Youtube and other similar websites in Google Chrome or Chromium browsers on Linux considerably increases your CPU usage and, if you use a laptop, it gets quite hot and the battery drains very quickly. That's because Chrome / Chromium (Firefox too but there's no way to force this) doesn't support hardware accelerated video decoding on Linux.
|
||||
|
||||
**This article explains how to install a Chromium development build which includes a patch that enables VA-API on Linux, bringing support for GPU accelerated video decoding, which should significantly decrease the CPU usage when watching HD videos online. The instructions cover only Intel and Nvidia graphics cards, as I don't have an ATI/AMD graphics card to try this, nor do I have experience with such graphics cards.**
|
||||
|
||||
This is Chromium from the Ubuntu (18.04) repositories without GPU accelerated video decoding playing a 1080p YouTube video:
|
||||
|
||||
![](https://4.bp.blogspot.com/-KtUQni2PMvE/W3KlJ62yLLI/AAAAAAAABW4/NrNVFaTAkZ8AmwqWwRvWD6czT51ni-R-gCLcBGAs/s1600/chromium-default-no-accel.png)
|
||||
|
||||
The same 1080p YouTube video playing in Chromium with the VA-API patch and hardware accelerated video decode enabled on Ubuntu 18.04:
|
||||
|
||||
![](https://4.bp.blogspot.com/-0c-wb4UNhW8/W3KlQBfeFnI/AAAAAAAABW8/WVUAYzM6hA8wRTlCcrPXPMpoXoFVR6b1QCLcBGAs/s1600/chromium-hardware-acceleration-enabled.png)
|
||||
|
||||
Notice the CPU usage in the screenshots. Both screenshots were taken on my old, but still quite powerful desktop. On my laptop, the Chromium CPU usage without hardware acceleration goes way higher.
|
||||
|
||||
The _Enable VAVDA, VAVEA and VAJDA on linux with VAAPI only_ " was was initially submitted to Chromium more than a year ago, but it has yet to be merged.
|
||||
|
||||
Chrome has an option to override the software rendering list (
|
||||
|
||||
`#ignore-gpu-blacklist`
|
||||
|
||||
), but this option does not enable hardware accelerated video decoding. After enabling this option, you may find the following when visiting
|
||||
|
||||
`chrome://gpu`
|
||||
|
||||
: " _Video Decode: Hardware accelerated_ ", but this does not mean it actually works. Open a HD video on YouTube and check the CPU usage in a tool such as
|
||||
|
||||
`htop`
|
||||
|
||||
(this is what I'm using in the screenshots above to check the CPU usage) - you should see high CPU usage because GPU video decoding is not actually enabled. There's also a section below for how to check if you're actually using hardware accelerated video decoding.
|
||||
|
||||
**The patches used by the Chromium Ubuntu builds with VA-API enabled used in this article are available[here][1].**
|
||||
|
||||
### Installing and using Chromium browser with VA-API support on Ubuntu or Linux Mint
|
||||
|
||||
**It should be clear to everyone reading this that Chromium Dev Branch is not considered stable. So you might find bugs, it may crash, etc. It works fine right now but who knows what may happen after some update.**
|
||||
|
||||
**What's more, the Chromium Dev Branch PPA requires you to perform some extra steps if you want to enable Widevine support** (so you can play Netflix videos and paid YouTube videos, etc.), **or if you need features like Sync** (which needs registering an API key and setting it up on your system). Instructions for performing these tweaks are explained in the
|
||||
|
||||
Chromium with the VA-API patch is also available for some other Linux distributions, in third-party repositories, like
|
||||
|
||||
**1\. Install Chromium Dev Branch with VA-API support.**
|
||||
|
||||
There's a Chromium Beta PPA with the VA-API patch, but it lacks vdpau-video for Ubuntu 18.04. If you want, you can use the `vdpau-va-driver` from the You can add the Chromium
|
||||
```
|
||||
sudo add-apt-repository ppa:saiarcot895/chromium-dev
|
||||
sudo apt-get update
|
||||
sudo apt install chromium-browser
|
||||
|
||||
```
|
||||
|
||||
**2\. Install the VA-API driver**
|
||||
|
||||
For Intel graphics cards, you'll need to install the `i965-va-driver` package (it may already be installed):
|
||||
```
|
||||
sudo apt install i965-va-driver
|
||||
|
||||
```
|
||||
|
||||
For Nvidia graphics cards (it should work with both the open source Nouveau drivers and the proprietary Nvidia drivers), install `vdpau-va-driver` :
|
||||
```
|
||||
sudo apt install vdpau-va-driver
|
||||
|
||||
```
|
||||
|
||||
**3\. Enable the Hardware-accelerated video option in Chromium.**
|
||||
|
||||
Copy and paste the following in the Chrome URL bar: `chrome://flags/#enable-accelerated-video` (or search for the `Hardware-accelerated video` option in `chrome://flags`) and enable it, then restart Chromium browser.
|
||||
|
||||
On a default Google Chrome / Chromium build, this option shows as unavailable, but you'll be able to enable it now because we've used the VA-API enabled Chromium build.
|
||||
|
||||
**4\. Install[h264ify][2] Chrome extension.**
|
||||
|
||||
YouTube (and probably some other websites as well) uses VP8 or VP9 video codecs by default, and many GPUs don't support hardware decoding for this codec. The h264ify extension will force YouTube to use H.264, which should be supported by most GPUs, instead of VP8/VP9.
|
||||
|
||||
This extension can also block 60fps videos, useful on lower end machines.
|
||||
|
||||
You can check the codec used by a YouTube video by right clicking on the video and selecting `Stats for nerds` . With the h264ify extension enabled, you should see avc / mp4a as the codecs. Without this extension, the codec should be something like vp09 / opus.
|
||||
|
||||
### How to check if Chromium is using GPU video decoding
|
||||
|
||||
Open a video on YouTube. Next, open a new tab in Chromium and enter the following in the URL bar: `chrome://media-internals` .
|
||||
|
||||
On the `chrome://media-internals` tab, click on the video url (in order to expand it), scroll down and look under `Player Properties` , and you should find the `video_decoder` property. If the `video_decoder` value is `GpuVideoDecoder` it means that the video that's currently playing on YouTube in the other tab is using hardware-accelerated video decoding.
|
||||
|
||||
![](https://4.bp.blogspot.com/-COBJWVT_Y0Q/W3KnG7AeHsI/AAAAAAAABXM/W2XAJA_S0BIHug4eQKTMOdIfXHhgkXhhQCLcBGAs/s1600/chromium-gpuvideodecoder-linux.png)
|
||||
|
||||
If it says `FFmpegVideoDecoder` or `VpxVideoDecoder` , accelerated video decoding is not working, or maybe you forgot to install or disabled the h264ify Chrome extension.
|
||||
|
||||
If it's not working, you could try to debug it by running `chromium-browser` from the command line and see if it shows any VA-API related errors. You can also run `vainfo` (install it in Ubuntu or Linux Mint: `sudo apt install vainfo`) and `vdpauinfo` (for Nvidia; install it in Ubuntu or Linux Mint: `sudo apt install vdpauinfo`) and see if it shows an error.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxuprising.com/2018/08/how-to-enable-hardware-accelerated.html
|
||||
|
||||
作者:[Logix][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://plus.google.com/118280394805678839070
|
||||
[1]:https://github.com/saiarcot895/chromium-ubuntu-build/tree/master/debian/patches
|
||||
[2]:https://chrome.google.com/webstore/detail/h264ify/aleakchihdccplidncghkekgioiakgal
|
||||
[3]:https://chromium-review.googlesource.com/c/chromium/src/+/532294
|
||||
[4]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev
|
||||
[5]:https://aur.archlinux.org/packages/?O=0&SeB=nd&K=chromium+vaapi&outdated=&SB=n&SO=a&PP=50&do_Search=Go
|
||||
[6]:https://aur.archlinux.org/packages/libva-vdpau-driver-chromium/
|
||||
[7]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-beta
|
||||
[8]:https://launchpad.net/~saiarcot895/+archive/ubuntu/chromium-dev/+packages
|
@ -1,327 +0,0 @@
|
||||
pinewall translating
|
||||
|
||||
Add GUIs to your programs and scripts easily with PySimpleGUI
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/web_browser_desktop_devlopment_design_system_computer.jpg?itok=pfqRrJgh)
|
||||
|
||||
Few people run Python programs by double-clicking the .py file as if it were a .exe file. When a typical user (non-programmer types) double-clicks an .exe file, they expect it to pop open with a window they can interact with. While GUIs, using tkinter, are possible using standard Python installations, it's unlikely many programs do this.
|
||||
|
||||
What if it were so easy to open a Python program into a GUI that complete beginners could do it? Would anyone care? Would anyone use it? It's difficult to answer because to date it's not been easy to build a custom GUI.
|
||||
|
||||
There seems to be a gap in the ability to add a GUI onto a Python program/script. Complete beginners are left using only the command line and many advanced programmers don't want to take the time required to code up a tkinter GUI.
|
||||
|
||||
### GUI frameworks
|
||||
|
||||
There is no shortage of GUI frameworks for Python. Tkinter, WxPython, Qt, and Kivy are a few of the major packages. In addition, there are a good number of dumbed-down GUI packages that "wrap" one of the major packages, including EasyGUI, PyGUI, and Pyforms.
|
||||
|
||||
The problem is that beginners (those with less than six weeks of experience) can't learn even the simplest of the major packages. That leaves the wrapper packages as a potential option, but it will still be difficult or impossible for most new users to build a custom GUI layout. Even if it's possible, the wrappers still require pages of code.
|
||||
|
||||
[PySimpleGUI][1] attempts to address these GUI challenges by providing a super-simple, easy-to-understand interface to GUIs that can be easily customized. Even many complex GUIs require less than 20 lines of code when PySimpleGUI is used.
|
||||
|
||||
### The secret
|
||||
|
||||
What makes PySimpleGUI superior for newcomers is that the package contains the majority of the code that the user is normally expected to write. Button callbacks are handled by PySimpleGUI, not the user's code. Beginners struggle to grasp the concept of a function, and expecting them to understand a call-back function in the first few weeks is a stretch.
|
||||
|
||||
With most GUIs, arranging GUI widgets often requires several lines of code… at least one or two lines per widget. PySimpleGUI uses an "auto-packer" that automatically creates the layout. No pack or grid system is needed to lay out a GUI window.
|
||||
|
||||
Finally, PySimpleGUI leverages the Python language constructs in clever ways that shorten the amount of code and return the GUI data in a straightforward manner. When a widget is created in a form layout, it is configured in place, not several lines of code away.
|
||||
|
||||
### What is a GUI?
|
||||
|
||||
Most GUIs do one thing: collect information from the user and return it. From a programmer's viewpoint, this could be summed up as a function call that looks like this:
|
||||
```
|
||||
button, values = GUI_Display(gui_layout)
|
||||
|
||||
```
|
||||
|
||||
What's expected from most GUIs is the button that was clicked (e.g., OK, cancel, save, yes, no, etc.) and the values input by the user. The essence of a GUI can be boiled down to a single line of code.
|
||||
|
||||
This is exactly how PySimpleGUI works (for simple GUIs). When the call is made to display the GUI, nothing executes until a button is clicked that closes the form.
|
||||
|
||||
There are more complex GUIs, such as those that don't close after a button is clicked. Examples include a remote control interface for a robot and a chat window. These complex forms can also be created with PySimpleGUI.
|
||||
|
||||
### Making a quick GUI
|
||||
|
||||
When is PySimpleGUI useful? Immediately, whenever you need a GUI. It takes less than five minutes to create and try a GUI. The quickest way to make a GUI is to copy one from the [PySimpleGUI Cookbook][2]. Follow these steps:
|
||||
|
||||
* Find a GUI that looks similar to what you want to create
|
||||
* Copy code from the Cookbook
|
||||
* Paste it into your IDE and run it
|
||||
|
||||
|
||||
|
||||
Let's look at the first recipe from the book.
|
||||
```
|
||||
import PySimpleGUI as sg
|
||||
|
||||
# Very basic form. Return values as a list
|
||||
form = sg.FlexForm('Simple data entry form') # begin with a blank form
|
||||
|
||||
layout = [
|
||||
[sg.Text('Please enter your Name, Address, Phone')],
|
||||
[sg.Text('Name', size=(15, 1)), sg.InputText('name')],
|
||||
[sg.Text('Address', size=(15, 1)), sg.InputText('address')],
|
||||
[sg.Text('Phone', size=(15, 1)), sg.InputText('phone')],
|
||||
[sg.Submit(), sg.Cancel()]
|
||||
]
|
||||
|
||||
button, values = form.LayoutAndRead(layout)
|
||||
|
||||
print(button, values[0], values[1], values[2])
|
||||
```
|
||||
It's a reasonably sized form.
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/pysimplegui_cookbook-form.jpg)
|
||||
|
||||
If you just need to collect a few values and they're all basically strings, you could copy this recipe and modify it to suit your needs.
|
||||
|
||||
You can even create a custom GUI layout in just five lines of code.
|
||||
```
|
||||
import PySimpleGUI as sg
|
||||
|
||||
form = sg.FlexForm('My first GUI')
|
||||
|
||||
layout = [ [sg.Text('Enter your name'), sg.InputText()],
|
||||
[sg.OK()] ]
|
||||
|
||||
button, (name,) = form.LayoutAndRead(layout)
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/pysimplegui-5-line-form.jpg)
|
||||
|
||||
### Making a custom GUI in five minutes
|
||||
|
||||
If you have a straightforward layout, you should be able create a custom layout in PySimpleGUI in less than five minutes by modifying code from the Cookbook.
|
||||
|
||||
Widgets are called elements in PySimpleGUI. These elements are spelled exactly as you would type them into your Python code.
|
||||
|
||||
#### Core elements
|
||||
```
|
||||
Text
|
||||
InputText
|
||||
Multiline
|
||||
InputCombo
|
||||
Listbox
|
||||
Radio
|
||||
Checkbox
|
||||
Spin
|
||||
Output
|
||||
SimpleButton
|
||||
RealtimeButton
|
||||
ReadFormButton
|
||||
ProgressBar
|
||||
Image
|
||||
Slider
|
||||
Column
|
||||
```
|
||||
|
||||
#### Shortcut list
|
||||
|
||||
PySimpleGUI also has two types of element shortcuts. One type is simply other names for the exact same element (e.g., `T` instead of `Text`). The second type configures an element with a particular setting, sparing you from specifying all parameters (e.g., `Submit` is a button with the text "Submit" on it)
|
||||
```
|
||||
T = Text
|
||||
Txt = Text
|
||||
In = InputText
|
||||
Input = IntputText
|
||||
Combo = InputCombo
|
||||
DropDown = InputCombo
|
||||
Drop = InputCombo
|
||||
```
|
||||
|
||||
#### Button shortcuts
|
||||
|
||||
A number of common buttons have been implemented as shortcuts. These include:
|
||||
```
|
||||
FolderBrowse
|
||||
FileBrowse
|
||||
FileSaveAs
|
||||
Save
|
||||
Submit
|
||||
OK
|
||||
Ok
|
||||
Cancel
|
||||
Quit
|
||||
Exit
|
||||
Yes
|
||||
No
|
||||
```
|
||||
|
||||
There are also shortcuts for more generic button functions.
|
||||
```
|
||||
SimpleButton
|
||||
ReadFormButton
|
||||
RealtimeButton
|
||||
```
|
||||
|
||||
These are all the GUI widgets you can choose from in PySimpleGUI. If one isn't on these lists, it doesn't go in your form layout.
|
||||
|
||||
#### GUI design pattern
|
||||
|
||||
The stuff that tends not to change in GUIs are the calls that set up and show a window. The layout of the elements is what changes from one program to another.
|
||||
|
||||
Here is the code from the example above with the layout removed:
|
||||
```
|
||||
import PySimpleGUI as sg
|
||||
|
||||
form = sg.FlexForm('Simple data entry form')
|
||||
# Define your form here (it's a list of lists)
|
||||
button, values = form.LayoutAndRead(layout)
|
||||
```
|
||||
|
||||
The flow for most GUIs is:
|
||||
|
||||
* Create the form object
|
||||
* Define the GUI as a list of lists
|
||||
* Show the GUI and get results
|
||||
|
||||
|
||||
|
||||
These are line-for-line what you see in PySimpleGUI's design pattern.
|
||||
|
||||
#### GUI layout
|
||||
|
||||
To create your custom GUI, first break your form down into rows, because forms are defined one row at a time. Then place one element after another, working from left to right.
|
||||
|
||||
The result is a "list of lists" that looks something like this:
|
||||
```
|
||||
layout = [ [Text('Row 1')],
|
||||
[Text('Row 2'), Checkbox('Checkbox 1', OK()), Checkbox('Checkbox 2'), OK()] ]
|
||||
|
||||
```
|
||||
|
||||
This layout produces this window:
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/pysimplegui-custom-form.jpg)
|
||||
|
||||
### Displaying the GUI
|
||||
|
||||
Once you have your layout complete and you've copied the lines of code that set up and show the form, it's time to display the form and get values from the user.
|
||||
|
||||
This is the line of code that displays the form and provides the results:
|
||||
```
|
||||
button, values = form.LayoutAndRead(layout)
|
||||
```
|
||||
|
||||
Forms return two values: the text of the button that is clicked and a list of values the user enters into the form.
|
||||
|
||||
If the example form is displayed and the user does nothing other than clicking the OK button, the results would be:
|
||||
```
|
||||
button == 'OK'
|
||||
values == [False, False]
|
||||
```
|
||||
|
||||
Checkbox elements return a value of True or False. Because the checkboxes defaulted to unchecked, both the values returned were False.
|
||||
|
||||
### Displaying results
|
||||
|
||||
Once you have the values from the GUI, it's nice to check what values are in the variables. Rather than printing them out using a `print` statement, let's stick with the GUI idea and output the data to a window.
|
||||
|
||||
PySimpleGUI has a number of message boxes to choose from. The data passed to the message box is displayed in a window. The function takes any number of arguments. You can simply indicate all the variables you want to see in the call.
|
||||
|
||||
The most commonly used message box in PySimpleGUI is MsgBox. To display the results from the previous example, write:
|
||||
```
|
||||
MsgBox('The GUI returned:', button, values)
|
||||
```
|
||||
|
||||
### Putting it all together
|
||||
|
||||
Now that you know the basics, let's put together a form that contains as many of PySimpleGUI's elements as possible. Also, to give it a nice appearance, we'll change the "look and feel" to a green and tan color scheme.
|
||||
```
|
||||
import PySimpleGUI as sg
|
||||
|
||||
sg.ChangeLookAndFeel('GreenTan')
|
||||
|
||||
form = sg.FlexForm('Everything bagel', default_element_size=(40, 1))
|
||||
|
||||
column1 = [[sg.Text('Column 1', background_color='#d3dfda', justification='center', size=(10,1))],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]]
|
||||
layout = [
|
||||
[sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25))],
|
||||
[sg.Text('Here is some text.... and a place to enter text')],
|
||||
[sg.InputText('This is my text')],
|
||||
[sg.Checkbox('My first checkbox!'), sg.Checkbox('My second checkbox!', default=True)],
|
||||
[sg.Radio('My first Radio! ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
|
||||
[sg.Multiline(default_text='This is the default Text should you decide not to type anything', size=(35, 3)),
|
||||
sg.Multiline(default_text='A second multi-line', size=(35, 3))],
|
||||
[sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 3)),
|
||||
sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
|
||||
[sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
|
||||
sg.Column(column1, background_color='#d3dfda')],
|
||||
[sg.Text('_' * 80)],
|
||||
[sg.Text('Choose A Folder', size=(35, 1))],
|
||||
[sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'),
|
||||
sg.InputText('Default Folder'), sg.FolderBrowse()],
|
||||
[sg.Submit(), sg.Cancel()]
|
||||
]
|
||||
|
||||
button, values = form.LayoutAndRead(layout)
|
||||
sg.MsgBox(button, values)
|
||||
```
|
||||
|
||||
This may seem like a lot of code, but try coding this same GUI layout directly in tkinter and you'll quickly realize how tiny it is.
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/pysimplegui-everything.jpg)
|
||||
|
||||
The last line of code opens a message box. This is how it looks:
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/pysimplegui-message-box.jpg)
|
||||
|
||||
Each parameter to the message box call is displayed on a new line. There are two lines of text in the message box; the second line is very long and wrapped a number of times
|
||||
|
||||
Take a moment and pair up the results values with the GUI to get an understanding of how results are created and returned.
|
||||
|
||||
### Adding a GUI to Your Program or Script
|
||||
|
||||
If you have a script that uses the command line, you don't have to abandon it in order to add a GUI. An easy solution is that if there are zero parameters given on the command line, then the GUI is run. Otherwise, execute the command line as you do today.
|
||||
|
||||
This kind of logic is all that's needed:
|
||||
```
|
||||
if len(sys.argv) == 1:
|
||||
# collect arguments from GUI
|
||||
else:
|
||||
# collect arguements from sys.argv
|
||||
```
|
||||
|
||||
The easiest way to get a GUI up and running quickly is to copy and modify one of the recipes from the [PySimpleGUI Cookbook][2].
|
||||
|
||||
Have some fun! Spice up the scripts you're tired of running by hand. Spend 5 or 10 minutes playing with the demo scripts. You may find one already exists that does exactly what you need. If not, you will find it's simple to create your own. If you really get lost, you've only invested 10 minutes.
|
||||
|
||||
### Resources
|
||||
|
||||
#### Installation
|
||||
|
||||
PySimpleGUI works on all systems that run tkinter, including Raspberry Pi, and it requires Python 3
|
||||
```
|
||||
pip install PySimpleGUI
|
||||
```
|
||||
|
||||
#### Documentation
|
||||
|
||||
+ [Manual][3]
|
||||
+ [Cookbook][4]
|
||||
+ [GitHub repository][5]
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/8/pysimplegui
|
||||
|
||||
作者:[Mike Barnett][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/pysimplegui
|
||||
[1]: https://github.com/MikeTheWatchGuy/PySimpleGUI
|
||||
[2]: https://pysimplegui.readthedocs.io/en/latest/cookbook/
|
||||
[3]: https://pysimplegui.readthedocs.io/en/latest/cookbook/
|
||||
[4]: https://pysimplegui.readthedocs.io/en/latest/cookbook/
|
||||
[5]: https://github.com/MikeTheWatchGuy/PySimpleGUI
|
@ -1,3 +1,5 @@
|
||||
translating---geekpi
|
||||
|
||||
How to Create a Slideshow of Photos in Ubuntu 18.04 and other Linux Distributions
|
||||
======
|
||||
Creating a slideshow of photos is a matter of a few clicks. Here’s how to make a slideshow of pictures in Ubuntu 18.04 and other Linux distributions.
|
||||
|
@ -1,345 +0,0 @@
|
||||
idea2act translating
|
||||
|
||||
Turn your vi editor into a productivity powerhouse
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_hands_team_collaboration.png?itok=u82QepPk)
|
||||
|
||||
A versatile and powerful editor, vi includes a rich set of potent commands that make it a popular choice for many users. This article specifically looks at commands that are not enabled by default in vi but are nevertheless useful. The commands recommended here are expected to be set in a vi configuration file. Though it is possible to enable commands individually from each vi session, the purpose of this article is to create a highly productive environment out of the box.
|
||||
|
||||
### Before you begin
|
||||
|
||||
While "vim" is the technically correct name of the newer version of the vi editor, this article refers to it as "vi." vimrc is the configuration file used by vim.
|
||||
|
||||
The commands or configurations discussed here go into the vi startup configuration file, vimrc, located in the user home directory. Follow the instructions below to set the commands in vimrc:
|
||||
|
||||
(Note: The vimrc file is also used for system-wide configurations in Linux, such as `/etc/vimrc` or `/etc/vim/vimrc`. In this article, we'll consider only user-specific vimrc, present in user home folder.)
|
||||
|
||||
In Linux:
|
||||
|
||||
* Open the file with `vi $HOME/.vimrc`
|
||||
* Type or copy/paste the commands in the cheat sheet at the end of this article
|
||||
* Save and close (`:wq`)
|
||||
|
||||
|
||||
|
||||
In Windows:
|
||||
|
||||
* First, [install gvim][1]
|
||||
* Open gvim
|
||||
* Click Edit --> Startup settings, which opens the _vimrc file
|
||||
* Type or copy/paste the commands in the cheat sheet at the end of this article
|
||||
* Click File --> Save
|
||||
|
||||
|
||||
|
||||
Let's delve into the individual vi productivity commands. These commands are classified into the following categories:
|
||||
|
||||
1. Indentation & Tabs
|
||||
2. Display & Format
|
||||
3. Search
|
||||
4. Browse & Scroll
|
||||
5. Spell
|
||||
6. Miscellaneous
|
||||
|
||||
|
||||
|
||||
### 1\. Indentation & Tabs
|
||||
|
||||
To automatically align the indentation of a line in a file:
|
||||
```
|
||||
set autoindent
|
||||
|
||||
```
|
||||
|
||||
Smart Indent uses the code syntax and style to align:
|
||||
```
|
||||
set smartindent
|
||||
|
||||
```
|
||||
|
||||
Tip: vi is language-aware and provides a default setting that works efficiently based on the programming language used in your file. There are many default configuration commands, including `axs cindent`, `cinoptions`, `indentexpr`, etc., which are not explained here. `syn` is a helpful command that shows or sets the file syntax.
|
||||
|
||||
To set the number of spaces to display for a tab:
|
||||
```
|
||||
set tabstop=4
|
||||
|
||||
```
|
||||
|
||||
To set the number of spaces to display for a “shift operation” (such as ‘>>’ or ‘<<’):
|
||||
```
|
||||
set shiftwidth=4
|
||||
|
||||
```
|
||||
|
||||
If you prefer to use spaces instead of tabs, this option inserts spaces when the Tab key is pressed. This may cause problems for languages such as Python that rely on tabs instead of spaces. In such cases, you may set this option based on the file type (see `autocmd`).
|
||||
```
|
||||
set expandtab
|
||||
|
||||
```
|
||||
|
||||
### 2\. Display & Format
|
||||
|
||||
To show line numbers:
|
||||
```
|
||||
set number
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture01.png)
|
||||
|
||||
To wrap text when it crosses the maximum line width:
|
||||
```
|
||||
set textwidth=80
|
||||
|
||||
```
|
||||
|
||||
To wrap text based on a number of columns from the right side:
|
||||
```
|
||||
set wrapmargin=2
|
||||
|
||||
```
|
||||
|
||||
To identify open and close brace positions when you traverse through the file:
|
||||
```
|
||||
set showmatch
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture02-03.jpg)
|
||||
|
||||
### 3\. Search
|
||||
|
||||
To highlight the searched term in a file:
|
||||
```
|
||||
set hlsearch
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture04.png)
|
||||
|
||||
To perform incremental searches as you type:
|
||||
```
|
||||
set incsearch
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/picture05.png)
|
||||
|
||||
To search ignoring case (many users prefer not to use this command; set it only if you think it will be useful):
|
||||
```
|
||||
set ignorecase
|
||||
|
||||
```
|
||||
|
||||
To search without considering `ignorecase` when both `ignorecase` and `smartcase` are set and the search pattern contains uppercase:
|
||||
```
|
||||
set smartcase
|
||||
|
||||
```
|
||||
|
||||
For example, if the file contains:
|
||||
|
||||
test
|
||||
Test
|
||||
|
||||
When both `ignorecase` and `smartcase` are set, a search for “test” finds and highlights both:
|
||||
|
||||
test
|
||||
Test
|
||||
|
||||
A search for “Test” highlights or finds only the second line:
|
||||
|
||||
test
|
||||
Test
|
||||
|
||||
### 4. Browse & Scroll
|
||||
|
||||
For a better visual experience, you may prefer to have the cursor somewhere in the middle rather than on the first line. The following option sets the cursor position to the 5th row.
|
||||
```
|
||||
set scrolloff=5
|
||||
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
The first image is with scrolloff=0 and the second image is with scrolloff=5.
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture06-07.jpg)
|
||||
|
||||
Tip: `set sidescrolloff` is useful if you also set `nowrap.`
|
||||
|
||||
To display a permanent status bar at the bottom of the vi screen showing the filename, row number, column number, etc.:
|
||||
```
|
||||
set laststatus=2
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/picture08.png)
|
||||
|
||||
### 5. Spell
|
||||
|
||||
vi has a built-in spell-checker that is quite useful for text editing as well as coding. vi recognizes the file type and checks the spelling of comments only in code. Use the following command to turn on spell-check for the English language:
|
||||
```
|
||||
set spell spelllang=en_us
|
||||
|
||||
```
|
||||
|
||||
### 6. Miscellaneous
|
||||
|
||||
Disable creating backup file: When this option is on, vi creates a backup of the previous edit. If you do not want this feature, disable it as shown below. Backup files are named with a tilde (~) at the end of the filename.
|
||||
```
|
||||
set nobackup
|
||||
|
||||
```
|
||||
|
||||
Disable creating a swap file: When this option is on, vi creates a swap file that exists until you start editing the file. Swapfile is used to recover a file in the event of a crash or a use conflict. Swap files are hidden files that begin with `.` and end with `.swp`.
|
||||
```
|
||||
set noswapfile
|
||||
|
||||
```
|
||||
|
||||
Suppose you need to edit multiple files in the same vi session and switch between them. An annoying feature that's not readily apparent is that the working directory is the one from which you opened the first file. Often it is useful to automatically switch the working directory to that of the file being edited. To enable this option:
|
||||
```
|
||||
set autochdir
|
||||
|
||||
```
|
||||
|
||||
vi maintains an undo history that lets you undo changes. By default, this history is active only until the file is closed. vi includes a nifty feature that maintains the undo history even after the file is closed, which means you may undo your changes even after the file is saved, closed, and reopened. The undo file is a hidden file saved with the `.un~` extension.
|
||||
```
|
||||
set undofile
|
||||
|
||||
```
|
||||
|
||||
To set audible alert bells (which sound a warning if you try to scroll beyond the end of a line):
|
||||
```
|
||||
set errorbells
|
||||
|
||||
```
|
||||
|
||||
If you prefer, you may set visual alert bells:
|
||||
```
|
||||
set visualbell
|
||||
|
||||
```
|
||||
|
||||
### Bonus
|
||||
|
||||
vi provides long-format as well as short-format commands. Either format can be used to set or unset the configuration.
|
||||
|
||||
Long format for the `autoindent` command:
|
||||
```
|
||||
set autoindent
|
||||
|
||||
```
|
||||
|
||||
Short format for the `autoindent` command:
|
||||
```
|
||||
set ai
|
||||
|
||||
```
|
||||
|
||||
To see the current configuration setting of a command without changing its current value, use `?` at the end:
|
||||
```
|
||||
set autoindent?
|
||||
|
||||
```
|
||||
|
||||
To unset or turn off a command, most commands take `no` as a prefix:
|
||||
```
|
||||
set noautoindent
|
||||
|
||||
```
|
||||
|
||||
It is possible to set a command for one file but not for the global configuration. To do this, open the file and type `:`, followed by the `set` command. This configuration is effective only for the current file editing session.
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture09.png)
|
||||
|
||||
For help on a command:
|
||||
```
|
||||
:help autoindent
|
||||
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture10-11.jpg)
|
||||
|
||||
Note: The commands listed here were tested on Linux with Vim version 7.4 (2013 Aug 10) and Windows with Vim 8.0 (2016 Sep 12).
|
||||
|
||||
These useful commands are sure to enhance your vi experience. Which other commands do you recommend?
|
||||
|
||||
### Cheat sheet
|
||||
|
||||
Copy/paste this list of commands in your vimrc file:
|
||||
```
|
||||
" Indentation & Tabs
|
||||
|
||||
set autoindent
|
||||
|
||||
set smartindent
|
||||
|
||||
set tabstop=4
|
||||
|
||||
set shiftwidth=4
|
||||
|
||||
set expandtab
|
||||
|
||||
set smarttab
|
||||
|
||||
" Display & format
|
||||
|
||||
set number
|
||||
|
||||
set textwidth=80
|
||||
|
||||
set wrapmargin=2
|
||||
|
||||
set showmatch
|
||||
|
||||
" Search
|
||||
|
||||
set hlsearch
|
||||
|
||||
set incsearch
|
||||
|
||||
set ignorecase
|
||||
|
||||
set smartcase
|
||||
|
||||
" Browse & Scroll
|
||||
|
||||
set scrolloff=5
|
||||
|
||||
set laststatus=2
|
||||
|
||||
" Spell
|
||||
|
||||
set spell spelllang=en_us
|
||||
|
||||
" Miscellaneous
|
||||
|
||||
set nobackup
|
||||
|
||||
set noswapfile
|
||||
|
||||
set autochdir
|
||||
|
||||
set undofile
|
||||
|
||||
set visualbell
|
||||
|
||||
set errorbells
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/9/vi-editor-productivity-powerhouse
|
||||
|
||||
作者:[Girish Managoli][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/gammay
|
||||
[1]: https://www.vim.org/download.php#pc
|
110
sources/tech/20180910 3 open source log aggregation tools.md
Normal file
110
sources/tech/20180910 3 open source log aggregation tools.md
Normal file
@ -0,0 +1,110 @@
|
||||
3 open source log aggregation tools
|
||||
======
|
||||
Log aggregation systems can help with troubleshooting and other tasks. Here are three top options.
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/data_metrics_analytics_desktop_laptop.png?itok=9QXd7AUr)
|
||||
|
||||
How is metrics aggregation different from log aggregation? Can’t logs include metrics? Can’t log aggregation systems do the same things as metrics aggregation systems?
|
||||
|
||||
These are questions I hear often. I’ve also seen vendors pitching their log aggregation system as the solution to all observability problems. Log aggregation is a valuable tool, but it isn’t normally a good tool for time-series data.
|
||||
|
||||
A couple of valuable features in a time-series metrics aggregation system are the regular interval and the storage system customized specifically for time-series data. The regular interval allows a user to derive real mathematical results consistently. If a log aggregation system is collecting metrics in a regular interval, it can potentially work the same way. However, the storage system isn’t optimized for the types of queries that are typical in a metrics aggregation system. These queries will take more resources and time to process using storage systems found in log aggregation tools.
|
||||
|
||||
So, we know a log aggregation system is likely not suitable for time-series data, but what is it good for? A log aggregation system is a great place for collecting event data. These are irregular activities that are significant. An example might be access logs for a web service. These are significant because we want to know what is accessing our systems and when. Another example would be an application error condition—because it is not a normal operating condition, it might be valuable during troubleshooting.
|
||||
|
||||
A handful of rules for logging:
|
||||
|
||||
* DO include a timestamp
|
||||
* DO format in JSON
|
||||
* DON’T log insignificant events
|
||||
* DO log all application errors
|
||||
* MAYBE log warnings
|
||||
* DO turn on logging
|
||||
* DO write messages in a human-readable form
|
||||
* DON’T log informational data in production
|
||||
* DON’T log anything a human can’t read or react to
|
||||
|
||||
|
||||
|
||||
### Cloud costs
|
||||
|
||||
When investigating log aggregation tools, the cloud might seem like an attractive option. However, it can come with significant costs. Logs represent a lot of data when aggregated across hundreds or thousands of hosts and applications. The ingestion, storage, and retrieval of that data are expensive in cloud-based systems.
|
||||
|
||||
As a point of reference from a real system, a collection of around 500 nodes with a few hundred apps results in 200GB of log data per day. There’s probably room for improvement in that system, but even reducing it by half will cost nearly $10,000 per month in many SaaS offerings. This often includes retention of only 30 days, which isn’t very long if you want to look at trending data year-over-year.
|
||||
|
||||
This isn’t to discourage the use of these systems, as they can be very valuable—especially for smaller organizations. The purpose is to point out that there could be significant costs, and it can be discouraging when they are realized. The rest of this article will focus on open source and commercial solutions that are self-hosted.
|
||||
|
||||
### Tool options
|
||||
|
||||
#### ELK
|
||||
|
||||
[ELK][1], short for Elasticsearch, Logstash, and Kibana, is the most popular open source log aggregation tool on the market. It’s used by Netflix, Facebook, Microsoft, LinkedIn, and Cisco. The three components are all developed and maintained by [Elastic][2]. [Elasticsearch][3] is essentially a NoSQL, Lucene search engine implementation. [Logstash][4] is a log pipeline system that can ingest data, transform it, and load it into a store like Elasticsearch. [Kibana][5] is a visualization layer on top of Elasticsearch.
|
||||
|
||||
A few years ago, Beats were introduced. Beats are data collectors. They simplify the process of shipping data to Logstash. Instead of needing to understand the proper syntax of each type of log, a user can install a Beat that will export NGINX logs or Envoy proxy logs properly so they can be used effectively within Elasticsearch.
|
||||
|
||||
When installing a production-level ELK stack, a few other pieces might be included, like [Kafka][6], [Redis][7], and [NGINX][8]. Also, it is common to replace Logstash with Fluentd, which we’ll discuss later. This system can be complex to operate, which in its early days led to a lot of problems and complaints. These have largely been fixed, but it’s still a complex system, so you might not want to try it if you’re a smaller operation.
|
||||
|
||||
That said, there are services available so you don’t have to worry about that. [Logz.io][9] will run it for you, but its list pricing is a little steep if you have a lot of data. Of course, you’re probably smaller and may not have a lot of data. If you can’t afford Logz.io, you could look at something like [AWS Elasticsearch Service][10] (ES). ES is a service Amazon Web Services (AWS) offers that makes it very easy to get Elasticsearch working quickly. It also has tooling to get all AWS logs into ES using Lambda and S3. This is a much cheaper option, but there is some management required and there are a few limitations.
|
||||
|
||||
Elastic, the parent company of the stack, [offers][11] a more robust product that uses the open core model, which provides additional options around analytics tools, and reporting. It can also be hosted on Google Cloud Platform or AWS. This might be the best option, as this combination of tools and hosting platforms offers a cheaper solution than most SaaS options and still provides a lot of value. This system could effectively replace or give you the capability of a [security information and event management][12] (SIEM) system.
|
||||
|
||||
The ELK stack also offers great visualization tools through Kibana, but it lacks an alerting function. Elastic provides alerting functionality within the paid X-Pack add-on, but there is nothing built in for the open source system. Yelp has created a solution to this problem, called [ElastAlert][13], and there are probably others. This additional piece of software is fairly robust, but it increases the complexity of an already complex system.
|
||||
|
||||
#### Graylog
|
||||
|
||||
[Graylog][14] has recently risen in popularity, but it got its start when Lennart Koopmann created it back in 2010. A company was born with the same name two years later. Despite its increasing use, it still lags far behind the ELK stack. This also means it has fewer community-developed features, but it can use the same Beats that the ELK stack uses. Graylog has gained praise in the Go community with the introduction of the Graylog Collector Sidecar written in [Go][15].
|
||||
|
||||
Graylog uses Elasticsearch, [MongoDB][16], and the Graylog Server under the hood. This makes it as complex to run as the ELK stack and maybe a little more. However, Graylog comes with alerting built into the open source version, as well as several other notable features like streaming, message rewriting, and geolocation.
|
||||
|
||||
The streaming feature allows for data to be routed to specific Streams in real time while they are being processed. With this feature, a user can see all database errors in a single Stream and web server errors in a different Stream. Alerts can even be based on these Streams as new items are added or when a threshold is exceeded. Latency is probably one of the biggest issues with log aggregation systems, and Streams eliminate that issue in Graylog. As soon as the log comes in, it can be routed to other systems through a Stream without being processed fully.
|
||||
|
||||
The message rewriting feature uses the open source rules engine [Drools][17]. This allows all incoming messages to be evaluated against a user-defined rules file enabling a message to be dropped (called Blacklisting), a field to be added or removed, or the message to be modified.
|
||||
|
||||
The coolest feature might be Graylog’s geolocation capability, which supports plotting IP addresses on a map. This is a fairly common feature and is available in Kibana as well, but it adds a lot of value—especially if you want to use this as your SIEM system. The geolocation functionality is provided in the open source version of the system.
|
||||
|
||||
Graylog, the company, charges for support on the open source version if you want it. It also offers an open core model for its Enterprise version that offers archiving, audit logging, and additional support. There aren’t many other options for support or hosting, so you’ll likely be on your own if you don’t use Graylog (the company).
|
||||
|
||||
#### Fluentd
|
||||
|
||||
[Fluentd][18] was developed at [Treasure Data][19], and the [CNCF][20] has adopted it as an Incubating project. It was written in C and Ruby and is recommended by [AWS][21] and [Google Cloud][22]. Fluentd has become a common replacement for Logstash in many installations. It acts as a local aggregator to collect all node logs and send them off to central storage systems. It is not a log aggregation system.
|
||||
|
||||
It uses a robust plugin system to provide quick and easy integrations with different data sources and data outputs. Since there are over 500 plugins available, most of your use cases should be covered. If they aren’t, this sounds like an opportunity to contribute back to the open source community.
|
||||
|
||||
Fluentd is a common choice in Kubernetes environments due to its low memory requirements (just tens of megabytes) and its high throughput. In an environment like [Kubernetes][23], where each pod has a Fluentd sidecar, memory consumption will increase linearly with each new pod created. Using Fluentd will drastically reduce your system utilization. This is becoming a common problem with tools developed in Java that are intended to run one per node where the memory overhead hasn’t been a major issue.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/9/open-source-log-aggregation-tools
|
||||
|
||||
作者:[Dan Barker][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/barkerd427
|
||||
[1]: https://www.elastic.co/webinars/introduction-elk-stack
|
||||
[2]: https://www.elastic.co/
|
||||
[3]: https://www.elastic.co/products/elasticsearch
|
||||
[4]: https://www.elastic.co/products/logstash
|
||||
[5]: https://www.elastic.co/products/kibana
|
||||
[6]: http://kafka.apache.org/
|
||||
[7]: https://redis.io/
|
||||
[8]: https://www.nginx.com/
|
||||
[9]: https://logz.io/
|
||||
[10]: https://aws.amazon.com/elasticsearch-service/
|
||||
[11]: https://www.elastic.co/cloud
|
||||
[12]: https://en.wikipedia.org/wiki/Security_information_and_event_management
|
||||
[13]: https://github.com/Yelp/elastalert
|
||||
[14]: https://www.graylog.org/
|
||||
[15]: https://opensource.com/tags/go
|
||||
[16]: https://www.mongodb.com/
|
||||
[17]: https://www.drools.org/
|
||||
[18]: https://www.fluentd.org/
|
||||
[19]: https://www.treasuredata.com/
|
||||
[20]: https://www.cncf.io/
|
||||
[21]: https://aws.amazon.com/blogs/aws/all-your-data-fluentd/
|
||||
[22]: https://cloud.google.com/logging/docs/agent/
|
||||
[23]: https://opensource.com/resources/what-is-kubernetes
|
@ -0,0 +1,644 @@
|
||||
How To List An Available Package Groups In Linux
|
||||
======
|
||||
As we know, if we want to install any packages in Linux we need to use the distribution package manager to get it done.
|
||||
|
||||
Package manager is playing major role in Linux as this used most of the time by admin.
|
||||
|
||||
If you would like to install group of package in one shot what would be the possible option.
|
||||
|
||||
Is it possible in Linux? if so, what would be the command for it.
|
||||
|
||||
Yes, this can be done in Linux by using the package manager. Each package manager has their own option to perform this task, as i know apt or apt-get package manager doesn’t has this option.
|
||||
|
||||
For Debian based system we need to use tasksel command instead of official package managers called apt or apt-get.
|
||||
|
||||
What is the benefit if we install group of package in Linux? Yes, there is lot of benefit is available in Linux when we install group of package because if you want to install LAMP separately we need to include so many packages but that can be done using single package when we use group of package command.
|
||||
|
||||
Say for example, as you get a request from Application team to install LAMP but you don’t know what are the packages needs to be installed, this is where group of package comes into picture.
|
||||
|
||||
Group option is a handy tool for Linux systems which will install Group of Software in a single click on your system without headache.
|
||||
|
||||
A package group is a collection of packages that serve a common purpose, for instance System Tools or Sound and Video. Installing a package group pulls a set of dependent packages, saving time considerably.
|
||||
|
||||
**Suggested Read :**
|
||||
**(#)** [How To List Installed Packages By Size (Largest) On Linux][1]
|
||||
**(#)** [How To View/List The Available Packages Updates In Linux][2]
|
||||
**(#)** [How To View A Particular Package Installed/Updated/Upgraded/Removed/Erased Date On Linux][3]
|
||||
**(#)** [How To View Detailed Information About A Package In Linux][4]
|
||||
**(#)** [How To Search If A Package Is Available On Your Linux Distribution Or Not][5]
|
||||
**(#)** [Newbies corner – A Graphical frontend tool for Linux Package Manager][6]
|
||||
**(#)** [Linux Expert should knows, list of Command line Package Manager & Usage][7]
|
||||
|
||||
### How To List An Available Package Groups In CentOS/RHEL Systems
|
||||
|
||||
RHEL & CentOS systems are using RPM packages hence we can use the `Yum Package Manager` to get this information.
|
||||
|
||||
YUM stands for Yellowdog Updater, Modified is an open-source command-line front-end package-management utility for RPM based systems such as Red Hat Enterprise Linux (RHEL) and CentOS.
|
||||
|
||||
Yum is the primary tool for getting, installing, deleting, querying, and managing RPM packages from distribution repositories, as well as other third-party repositories.
|
||||
|
||||
**Suggested Read :** [YUM Command To Manage Packages on RHEL/CentOS Systems][8]
|
||||
|
||||
```
|
||||
# yum grouplist
|
||||
Loaded plugins: fastestmirror, security
|
||||
Setting up Group Process
|
||||
Loading mirror speeds from cached hostfile
|
||||
* epel: epel.mirror.constant.com
|
||||
Installed Groups:
|
||||
Base
|
||||
E-mail server
|
||||
Graphical Administration Tools
|
||||
Hardware monitoring utilities
|
||||
Legacy UNIX compatibility
|
||||
Milkymist
|
||||
Networking Tools
|
||||
Performance Tools
|
||||
Perl Support
|
||||
Security Tools
|
||||
Available Groups:
|
||||
Additional Development
|
||||
Backup Client
|
||||
Backup Server
|
||||
CIFS file server
|
||||
Client management tools
|
||||
Compatibility libraries
|
||||
Console internet tools
|
||||
Debugging Tools
|
||||
Desktop
|
||||
.
|
||||
.
|
||||
Available Language Groups:
|
||||
Afrikaans Support [af]
|
||||
Albanian Support [sq]
|
||||
Amazigh Support [ber]
|
||||
Arabic Support [ar]
|
||||
Armenian Support [hy]
|
||||
Assamese Support [as]
|
||||
Azerbaijani Support [az]
|
||||
.
|
||||
.
|
||||
Done
|
||||
|
||||
```
|
||||
|
||||
If you would like to list what are the packages is associated on it, run the below command. In this example we are going to list what are the packages is associated with “Performance Tools” group.
|
||||
|
||||
```
|
||||
# yum groupinfo "Performance Tools"
|
||||
Loaded plugins: fastestmirror, security
|
||||
Setting up Group Process
|
||||
Loading mirror speeds from cached hostfile
|
||||
* epel: ewr.edge.kernel.org
|
||||
|
||||
Group: Performance Tools
|
||||
Description: Tools for diagnosing system and application-level performance problems.
|
||||
Mandatory Packages:
|
||||
blktrace
|
||||
sysstat
|
||||
Default Packages:
|
||||
dstat
|
||||
iotop
|
||||
latencytop
|
||||
latencytop-tui
|
||||
oprofile
|
||||
perf
|
||||
powertop
|
||||
seekwatcher
|
||||
Optional Packages:
|
||||
oprofile-jit
|
||||
papi
|
||||
sdparm
|
||||
sg3_utils
|
||||
tiobench
|
||||
tuned
|
||||
tuned-utils
|
||||
|
||||
```
|
||||
|
||||
### How To List An Available Package Groups In Fedora
|
||||
|
||||
Fedora system uses DNF package manager hence we can use the Dnf Package Manager to get this information.
|
||||
|
||||
DNF stands for Dandified yum. We can tell DNF, the next generation of yum package manager (Fork of Yum) using hawkey/libsolv library for backend. Aleš Kozumplík started working on DNF since Fedora 18 and its implemented/launched in Fedora 22 finally.
|
||||
|
||||
Dnf command is used to install, update, search & remove packages on Fedora 22 and later system. It automatically resolve dependencies and make it smooth package installation without any trouble.
|
||||
|
||||
Yum replaced by DNF due to several long-term problems in Yum which was not solved. Asked why ? he did not patches the Yum issues. Aleš Kozumplík explains that patching was technically hard and YUM team wont accept the changes immediately and other major critical, YUM is 56K lines but DNF is 29K lies. So, there is no option for further development, except to fork.
|
||||
|
||||
**Suggested Read :** [DNF (Fork of YUM) Command To Manage Packages on Fedora System][9]
|
||||
|
||||
```
|
||||
# dnf grouplist
|
||||
Last metadata expiration check: 0:00:00 ago on Sun 09 Sep 2018 07:10:36 PM IST.
|
||||
Available Environment Groups:
|
||||
Fedora Custom Operating System
|
||||
Minimal Install
|
||||
Fedora Server Edition
|
||||
Fedora Workstation
|
||||
Fedora Cloud Server
|
||||
KDE Plasma Workspaces
|
||||
Xfce Desktop
|
||||
LXDE Desktop
|
||||
Hawaii Desktop
|
||||
LXQt Desktop
|
||||
Cinnamon Desktop
|
||||
MATE Desktop
|
||||
Sugar Desktop Environment
|
||||
Development and Creative Workstation
|
||||
Web Server
|
||||
Infrastructure Server
|
||||
Basic Desktop
|
||||
Installed Groups:
|
||||
C Development Tools and Libraries
|
||||
Development Tools
|
||||
Available Groups:
|
||||
3D Printing
|
||||
Administration Tools
|
||||
Ansible node
|
||||
Audio Production
|
||||
Authoring and Publishing
|
||||
Books and Guides
|
||||
Cloud Infrastructure
|
||||
Cloud Management Tools
|
||||
Container Management
|
||||
D Development Tools and Libraries
|
||||
.
|
||||
.
|
||||
RPM Development Tools
|
||||
Security Lab
|
||||
Text-based Internet
|
||||
Window Managers
|
||||
GNOME Desktop Environment
|
||||
Graphical Internet
|
||||
KDE (K Desktop Environment)
|
||||
Fonts
|
||||
Games and Entertainment
|
||||
Hardware Support
|
||||
Sound and Video
|
||||
System Tools
|
||||
|
||||
```
|
||||
|
||||
If you would like to list what are the packages is associated on it, run the below command. In this example we are going to list what are the packages is associated with “Editor” group.
|
||||
|
||||
```
|
||||
|
||||
# dnf groupinfo Editors
|
||||
Last metadata expiration check: 0:04:57 ago on Sun 09 Sep 2018 07:10:36 PM IST.
|
||||
|
||||
Group: Editors
|
||||
Description: Sometimes called text editors, these are programs that allow you to create and edit text files. This includes Emacs and Vi.
|
||||
Optional Packages:
|
||||
code-editor
|
||||
cssed
|
||||
emacs
|
||||
emacs-auctex
|
||||
emacs-bbdb
|
||||
emacs-ess
|
||||
emacs-vm
|
||||
geany
|
||||
gobby
|
||||
jed
|
||||
joe
|
||||
leafpad
|
||||
nedit
|
||||
poedit
|
||||
psgml
|
||||
vim-X11
|
||||
vim-enhanced
|
||||
xemacs
|
||||
xemacs-packages-base
|
||||
xemacs-packages-extra
|
||||
xemacs-xft
|
||||
xmlcopyeditor
|
||||
zile
|
||||
```
|
||||
|
||||
### How To List An Available Package Groups In openSUSE System
|
||||
|
||||
openSUSE system uses zypper package manager hence we can use the zypper Package Manager to get this information.
|
||||
|
||||
Zypper is a command line package manager for suse & openSUSE distributions. It’s used to install, update, search & remove packages & manage repositories, perform various queries, and more. Zypper command-line interface to ZYpp system management library (libzypp).
|
||||
|
||||
**Suggested Read :** [Zypper Command To Manage Packages On openSUSE & suse Systems][10]
|
||||
|
||||
```
|
||||
# zypper patterns
|
||||
Loading repository data...
|
||||
Warning: Repository 'Update Repository (Non-Oss)' appears to be outdated. Consider using a different mirror or server.
|
||||
Warning: Repository 'Main Update Repository' appears to be outdated. Consider using a different mirror or server.
|
||||
Reading installed packages...
|
||||
S | Name | Version | Repository | Dependency
|
||||
---|----------------------|---------------|-----------------------|-----------
|
||||
| 64bit | 20150918-25.1 | Main Repository (OSS) |
|
||||
| apparmor | 20150918-25.1 | Main Repository (OSS) |
|
||||
i | apparmor | 20150918-25.1 | @System |
|
||||
| base | 20150918-25.1 | Main Repository (OSS) |
|
||||
i+ | base | 20150918-25.1 | @System |
|
||||
| books | 20150918-25.1 | Main Repository (OSS) |
|
||||
| console | 20150918-25.1 | Main Repository (OSS) |
|
||||
| devel_C_C++ | 20150918-25.1 | Main Repository (OSS) |
|
||||
i | enhanced_base | 20150918-25.1 | @System |
|
||||
| enlightenment | 20150918-25.1 | Main Repository (OSS) |
|
||||
| file_server | 20150918-25.1 | Main Repository (OSS) |
|
||||
| fonts | 20150918-25.1 | Main Repository (OSS) |
|
||||
i | fonts | 20150918-25.1 | @System |
|
||||
| games | 20150918-25.1 | Main Repository (OSS) |
|
||||
i | games | 20150918-25.1 | @System |
|
||||
| gnome | 20150918-25.1 | Main Repository (OSS) |
|
||||
| gnome_basis | 20150918-25.1 | Main Repository (OSS) |
|
||||
i | imaging | 20150918-25.1 | @System |
|
||||
| kde | 20150918-25.1 | Main Repository (OSS) |
|
||||
i+ | kde | 20150918-25.1 | @System |
|
||||
| kde_plasma | 20150918-25.1 | Main Repository (OSS) |
|
||||
i | kde_plasma | 20150918-25.1 | @System |
|
||||
| lamp_server | 20150918-25.1 | Main Repository (OSS) |
|
||||
| laptop | 20150918-25.1 | Main Repository (OSS) |
|
||||
i+ | laptop | 20150918-25.1 | @System |
|
||||
| lxde | 20150918-25.1 | Main Repository (OSS) |
|
||||
| lxqt | 20150918-25.1 | Main Repository (OSS) |
|
||||
i | multimedia | 20150918-25.1 | @System |
|
||||
| network_admin | 20150918-25.1 | Main Repository (OSS) |
|
||||
| non_oss | 20150918-25.1 | Main Repository (OSS) |
|
||||
i | non_oss | 20150918-25.1 | @System |
|
||||
| office | 20150918-25.1 | Main Repository (OSS) |
|
||||
i | office | 20150918-25.1 | @System |
|
||||
| print_server | 20150918-25.1 | Main Repository (OSS) |
|
||||
| remote_desktop | 20150918-25.1 | Main Repository (OSS) |
|
||||
| x11 | 20150918-25.1 | Main Repository (OSS) |
|
||||
i+ | x11 | 20150918-25.1 | @System |
|
||||
| x86 | 20150918-25.1 | Main Repository (OSS) |
|
||||
| xen_server | 20150918-25.1 | Main Repository (OSS) |
|
||||
| xfce | 20150918-25.1 | Main Repository (OSS) |
|
||||
| xfce_basis | 20150918-25.1 | Main Repository (OSS) |
|
||||
| yast2_basis | 20150918-25.1 | Main Repository (OSS) |
|
||||
i | yast2_basis | 20150918-25.1 | @System |
|
||||
| yast2_install_wf | 20150918-25.1 | Main Repository (OSS) |
|
||||
```
|
||||
|
||||
If you would like to list what are the packages is associated on it, run the below command. In this example we are going to list what are the packages is associated with “file_server” group.
|
||||
Additionally zypper command allows a user to perform the same action with different options.
|
||||
|
||||
```
|
||||
# zypper info file_server
|
||||
Loading repository data...
|
||||
Warning: Repository 'Update Repository (Non-Oss)' appears to be outdated. Consider using a different mirror or server.
|
||||
Warning: Repository 'Main Update Repository' appears to be outdated. Consider using a different mirror or server.
|
||||
Reading installed packages...
|
||||
|
||||
Information for pattern file_server:
|
||||
------------------------------------
|
||||
Repository : Main Repository (OSS)
|
||||
Name : file_server
|
||||
Version : 20150918-25.1
|
||||
Arch : x86_64
|
||||
Vendor : openSUSE
|
||||
Installed : No
|
||||
Visible to User : Yes
|
||||
Summary : File Server
|
||||
Description :
|
||||
File services to host files so that they may be accessed or retrieved by other computers on the same network. This includes the FTP, SMB, and NFS protocols.
|
||||
Contents :
|
||||
S | Name | Type | Dependency
|
||||
---|-------------------------------|---------|------------
|
||||
i+ | patterns-openSUSE-base | package | Required
|
||||
| patterns-openSUSE-file_server | package | Required
|
||||
| nfs-kernel-server | package | Recommended
|
||||
i | nfsidmap | package | Recommended
|
||||
i | samba | package | Recommended
|
||||
i | samba-client | package | Recommended
|
||||
i | samba-winbind | package | Recommended
|
||||
| tftp | package | Recommended
|
||||
| vsftpd | package | Recommended
|
||||
| yast2-ftp-server | package | Recommended
|
||||
| yast2-nfs-server | package | Recommended
|
||||
i | yast2-samba-server | package | Recommended
|
||||
| yast2-tftp-server | package | Recommended
|
||||
```
|
||||
|
||||
If you would like to list what are the packages is associated on it, run the below command.
|
||||
|
||||
```
|
||||
# zypper pattern-info file_server
|
||||
Loading repository data...
|
||||
Warning: Repository 'Update Repository (Non-Oss)' appears to be outdated. Consider using a different mirror or server.
|
||||
Warning: Repository 'Main Update Repository' appears to be outdated. Consider using a different mirror or server.
|
||||
Reading installed packages...
|
||||
|
||||
|
||||
Information for pattern file_server:
|
||||
------------------------------------
|
||||
Repository : Main Repository (OSS)
|
||||
Name : file_server
|
||||
Version : 20150918-25.1
|
||||
Arch : x86_64
|
||||
Vendor : openSUSE
|
||||
Installed : No
|
||||
Visible to User : Yes
|
||||
Summary : File Server
|
||||
Description :
|
||||
File services to host files so that they may be accessed or retrieved by other computers on the same network. This includes the FTP, SMB, and NFS protocols.
|
||||
Contents :
|
||||
S | Name | Type | Dependency
|
||||
---|-------------------------------|---------|------------
|
||||
i+ | patterns-openSUSE-base | package | Required
|
||||
| patterns-openSUSE-file_server | package | Required
|
||||
| nfs-kernel-server | package | Recommended
|
||||
i | nfsidmap | package | Recommended
|
||||
i | samba | package | Recommended
|
||||
i | samba-client | package | Recommended
|
||||
i | samba-winbind | package | Recommended
|
||||
| tftp | package | Recommended
|
||||
| vsftpd | package | Recommended
|
||||
| yast2-ftp-server | package | Recommended
|
||||
| yast2-nfs-server | package | Recommended
|
||||
i | yast2-samba-server | package | Recommended
|
||||
| yast2-tftp-server | package | Recommended
|
||||
```
|
||||
|
||||
If you would like to list what are the packages is associated on it, run the below command.
|
||||
|
||||
```
|
||||
# zypper info pattern file_server
|
||||
Loading repository data...
|
||||
Warning: Repository 'Update Repository (Non-Oss)' appears to be outdated. Consider using a different mirror or server.
|
||||
Warning: Repository 'Main Update Repository' appears to be outdated. Consider using a different mirror or server.
|
||||
Reading installed packages...
|
||||
|
||||
Information for pattern file_server:
|
||||
------------------------------------
|
||||
Repository : Main Repository (OSS)
|
||||
Name : file_server
|
||||
Version : 20150918-25.1
|
||||
Arch : x86_64
|
||||
Vendor : openSUSE
|
||||
Installed : No
|
||||
Visible to User : Yes
|
||||
Summary : File Server
|
||||
Description :
|
||||
File services to host files so that they may be accessed or retrieved by other computers on the same network. This includes the FTP, SMB, and NFS protocols.
|
||||
Contents :
|
||||
S | Name | Type | Dependency
|
||||
---|-------------------------------|---------|------------
|
||||
i+ | patterns-openSUSE-base | package | Required
|
||||
| patterns-openSUSE-file_server | package | Required
|
||||
| nfs-kernel-server | package | Recommended
|
||||
i | nfsidmap | package | Recommended
|
||||
i | samba | package | Recommended
|
||||
i | samba-client | package | Recommended
|
||||
i | samba-winbind | package | Recommended
|
||||
| tftp | package | Recommended
|
||||
| vsftpd | package | Recommended
|
||||
| yast2-ftp-server | package | Recommended
|
||||
| yast2-nfs-server | package | Recommended
|
||||
i | yast2-samba-server | package | Recommended
|
||||
| yast2-tftp-server | package | Recommended
|
||||
```
|
||||
|
||||
If you would like to list what are the packages is associated on it, run the below command.
|
||||
|
||||
```
|
||||
# zypper info -t pattern file_server
|
||||
Loading repository data...
|
||||
Warning: Repository 'Update Repository (Non-Oss)' appears to be outdated. Consider using a different mirror or server.
|
||||
Warning: Repository 'Main Update Repository' appears to be outdated. Consider using a different mirror or server.
|
||||
Reading installed packages...
|
||||
|
||||
|
||||
Information for pattern file_server:
|
||||
------------------------------------
|
||||
Repository : Main Repository (OSS)
|
||||
Name : file_server
|
||||
Version : 20150918-25.1
|
||||
Arch : x86_64
|
||||
Vendor : openSUSE
|
||||
Installed : No
|
||||
Visible to User : Yes
|
||||
Summary : File Server
|
||||
Description :
|
||||
File services to host files so that they may be accessed or retrieved by other computers on the same network. This includes the FTP, SMB, and NFS protocols.
|
||||
Contents :
|
||||
S | Name | Type | Dependency
|
||||
---|-------------------------------|---------|------------
|
||||
i+ | patterns-openSUSE-base | package | Required
|
||||
| patterns-openSUSE-file_server | package | Required
|
||||
| nfs-kernel-server | package | Recommended
|
||||
i | nfsidmap | package | Recommended
|
||||
i | samba | package | Recommended
|
||||
i | samba-client | package | Recommended
|
||||
i | samba-winbind | package | Recommended
|
||||
| tftp | package | Recommended
|
||||
| vsftpd | package | Recommended
|
||||
| yast2-ftp-server | package | Recommended
|
||||
| yast2-nfs-server | package | Recommended
|
||||
i | yast2-samba-server | package | Recommended
|
||||
| yast2-tftp-server | package | Recommended
|
||||
```
|
||||
|
||||
### How To List An Available Package Groups In Debian/Ubuntu Systems
|
||||
|
||||
Since APT or APT-GET package manager doesn’t offer this option for Debian/Ubuntu based systems hence, we are using tasksel command to get this information.
|
||||
|
||||
[Tasksel][11] is a handy tool for Debian/Ubuntu systems which will install Group of Software in a single click on your system. Tasks are defined in `.desc` files and located at `/usr/share/tasksel`.
|
||||
|
||||
By default, tasksel tool installed on Debian system as part of Debian installer but it’s not installed on Ubuntu desktop editions. This functionality is similar to that of meta-packages, like how package managers have.
|
||||
|
||||
Tasksel tool offer a simple user interface based on zenity (popup Graphical dialog box in command line).
|
||||
|
||||
**Suggested Read :** [Tasksel – Install Group of Software in A Single Click on Debian/Ubuntu][12]
|
||||
|
||||
```
|
||||
# tasksel --list-task
|
||||
u kubuntu-live Kubuntu live CD
|
||||
u lubuntu-live-gtk Lubuntu live CD (GTK part)
|
||||
u ubuntu-budgie-live Ubuntu Budgie live CD
|
||||
u ubuntu-live Ubuntu live CD
|
||||
u ubuntu-mate-live Ubuntu MATE Live CD
|
||||
u ubuntustudio-dvd-live Ubuntu Studio live DVD
|
||||
u vanilla-gnome-live Ubuntu GNOME live CD
|
||||
u xubuntu-live Xubuntu live CD
|
||||
u cloud-image Ubuntu Cloud Image (instance)
|
||||
u dns-server DNS server
|
||||
u kubuntu-desktop Kubuntu desktop
|
||||
u kubuntu-full Kubuntu full
|
||||
u lamp-server LAMP server
|
||||
u lubuntu-core Lubuntu minimal installation
|
||||
u lubuntu-desktop Lubuntu Desktop
|
||||
u lubuntu-gtk-core Lubuntu minimal installation (GTK part)
|
||||
u lubuntu-gtk-desktop Lubuntu Desktop (GTK part)
|
||||
u lubuntu-qt-core Lubuntu minimal installation (Qt part)
|
||||
u lubuntu-qt-desktop Lubuntu Qt Desktop (Qt part)
|
||||
u mail-server Mail server
|
||||
u postgresql-server PostgreSQL database
|
||||
i print-server Print server
|
||||
u samba-server Samba file server
|
||||
u tomcat-server Tomcat Java server
|
||||
u ubuntu-budgie-desktop Ubuntu Budgie desktop
|
||||
i ubuntu-desktop Ubuntu desktop
|
||||
u ubuntu-mate-core Ubuntu MATE minimal
|
||||
u ubuntu-mate-desktop Ubuntu MATE desktop
|
||||
i ubuntu-usb Ubuntu desktop USB
|
||||
u ubuntustudio-audio Audio recording and editing suite
|
||||
u ubuntustudio-desktop Ubuntu Studio desktop
|
||||
u ubuntustudio-desktop-core Ubuntu Studio minimal DE installation
|
||||
u ubuntustudio-fonts Large selection of font packages
|
||||
u ubuntustudio-graphics 2D/3D creation and editing suite
|
||||
u ubuntustudio-photography Photograph touchup and editing suite
|
||||
u ubuntustudio-publishing Publishing applications
|
||||
u ubuntustudio-video Video creation and editing suite
|
||||
u vanilla-gnome-desktop Vanilla GNOME desktop
|
||||
u xubuntu-core Xubuntu minimal installation
|
||||
u xubuntu-desktop Xubuntu desktop
|
||||
u openssh-server OpenSSH server
|
||||
u server Basic Ubuntu server
|
||||
```
|
||||
|
||||
If you would like to list what are the packages is associated on it, run the below command. In this example we are going to list what are the packages is associated with “file_server” group.
|
||||
|
||||
```
|
||||
# tasksel --task-desc "lamp-server"
|
||||
Selects a ready-made Linux/Apache/MySQL/PHP server.
|
||||
```
|
||||
|
||||
### How To List An Available Package Groups In Arch Linux based Systems
|
||||
|
||||
Arch Linux based systems are using pacman package manager hence we can use the pacman Package Manager to get this information.
|
||||
|
||||
pacman stands for package manager utility (pacman). pacman is a command-line utility to install, build, remove and manage Arch Linux packages. pacman uses libalpm (Arch Linux Package Management (ALPM) library) as a back-end to perform all the actions.
|
||||
|
||||
**Suggested Read :** [Pacman Command To Manage Packages On Arch Linux Based Systems][13]
|
||||
|
||||
```
|
||||
# pacman -Sg
|
||||
base-devel
|
||||
base
|
||||
multilib-devel
|
||||
gnome-extra
|
||||
kde-applications
|
||||
kdepim
|
||||
kdeutils
|
||||
kdeedu
|
||||
kf5
|
||||
kdemultimedia
|
||||
gnome
|
||||
plasma
|
||||
kdegames
|
||||
kdesdk
|
||||
kdebase
|
||||
xfce4
|
||||
fprint
|
||||
kdegraphics
|
||||
kdenetwork
|
||||
kdeadmin
|
||||
kf5-aids
|
||||
kdewebdev
|
||||
.
|
||||
.
|
||||
dlang-ldc
|
||||
libretro
|
||||
ring
|
||||
lxqt
|
||||
non-daw
|
||||
non
|
||||
alsa
|
||||
qtcurve
|
||||
realtime
|
||||
sugar-fructose
|
||||
tesseract-data
|
||||
vim-plugins
|
||||
|
||||
```
|
||||
|
||||
If you would like to list what are the packages is associated on it, run the below command. In this example we are going to list what are the packages is associated with “gnome” group.
|
||||
|
||||
```
|
||||
# pacman -Sg gnome
|
||||
gnome baobab
|
||||
gnome cheese
|
||||
gnome eog
|
||||
gnome epiphany
|
||||
gnome evince
|
||||
gnome file-roller
|
||||
gnome gdm
|
||||
gnome gedit
|
||||
gnome gnome-backgrounds
|
||||
gnome gnome-calculator
|
||||
gnome gnome-calendar
|
||||
gnome gnome-characters
|
||||
gnome gnome-clocks
|
||||
gnome gnome-color-manager
|
||||
gnome gnome-contacts
|
||||
gnome gnome-control-center
|
||||
gnome gnome-dictionary
|
||||
gnome gnome-disk-utility
|
||||
gnome gnome-documents
|
||||
gnome gnome-font-viewer
|
||||
.
|
||||
.
|
||||
gnome sushi
|
||||
gnome totem
|
||||
gnome tracker
|
||||
gnome tracker-miners
|
||||
gnome vino
|
||||
gnome xdg-user-dirs-gtk
|
||||
gnome yelp
|
||||
gnome gnome-boxes
|
||||
gnome gnome-software
|
||||
gnome simple-scan
|
||||
|
||||
```
|
||||
|
||||
Alternatively we can check the same by running following command.
|
||||
|
||||
```
|
||||
# pacman -S gnome
|
||||
:: There are 64 members in group gnome:
|
||||
:: Repository extra
|
||||
1) baobab 2) cheese 3) eog 4) epiphany 5) evince 6) file-roller 7) gdm 8) gedit 9) gnome-backgrounds 10) gnome-calculator 11) gnome-calendar 12) gnome-characters 13) gnome-clocks
|
||||
14) gnome-color-manager 15) gnome-contacts 16) gnome-control-center 17) gnome-dictionary 18) gnome-disk-utility 19) gnome-documents 20) gnome-font-viewer 21) gnome-getting-started-docs
|
||||
22) gnome-keyring 23) gnome-logs 24) gnome-maps 25) gnome-menus 26) gnome-music 27) gnome-photos 28) gnome-screenshot 29) gnome-session 30) gnome-settings-daemon 31) gnome-shell
|
||||
32) gnome-shell-extensions 33) gnome-system-monitor 34) gnome-terminal 35) gnome-themes-extra 36) gnome-todo 37) gnome-user-docs 38) gnome-user-share 39) gnome-video-effects 40) grilo-plugins
|
||||
41) gvfs 42) gvfs-afc 43) gvfs-goa 44) gvfs-google 45) gvfs-gphoto2 46) gvfs-mtp 47) gvfs-nfs 48) gvfs-smb 49) mousetweaks 50) mutter 51) nautilus 52) networkmanager 53) orca 54) rygel
|
||||
55) sushi 56) totem 57) tracker 58) tracker-miners 59) vino 60) xdg-user-dirs-gtk 61) yelp
|
||||
:: Repository community
|
||||
62) gnome-boxes 63) gnome-software 64) simple-scan
|
||||
|
||||
Enter a selection (default=all): ^C
|
||||
Interrupt signal received
|
||||
|
||||
```
|
||||
|
||||
To know exactly how many packages is associated on it, run the following command.
|
||||
|
||||
```
|
||||
# pacman -Sg gnome | wc -l
|
||||
64
|
||||
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.2daygeek.com/how-to-list-an-available-package-groups-in-linux/
|
||||
|
||||
作者:[Prakash Subramanian][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.2daygeek.com/author/prakash/
|
||||
[1]: https://www.2daygeek.com/how-to-list-installed-packages-by-size-largest-on-linux/
|
||||
[2]: https://www.2daygeek.com/how-to-view-list-the-available-packages-updates-in-linux/
|
||||
[3]: https://www.2daygeek.com/how-to-view-a-particular-package-installed-updated-upgraded-removed-erased-date-on-linux/
|
||||
[4]: https://www.2daygeek.com/how-to-view-detailed-information-about-a-package-in-linux/
|
||||
[5]: https://www.2daygeek.com/how-to-search-if-a-package-is-available-on-your-linux-distribution-or-not/
|
||||
[6]: https://www.2daygeek.com/list-of-graphical-frontend-tool-for-linux-package-manager/
|
||||
[7]: https://www.2daygeek.com/list-of-command-line-package-manager-for-linux/
|
||||
[8]: https://www.2daygeek.com/yum-command-examples-manage-packages-rhel-centos-systems/
|
||||
[9]: https://www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/
|
||||
[10]: https://www.2daygeek.com/zypper-command-examples-manage-packages-opensuse-system/
|
||||
[11]: https://wiki.debian.org/tasksel
|
||||
[12]: https://www.2daygeek.com/tasksel-install-group-of-software-in-a-single-click-or-single-command-on-debian-ubuntu/
|
||||
[13]: https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/
|
@ -0,0 +1,103 @@
|
||||
Visualize Disk Usage On Your Linux System
|
||||
======
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2018/09/filelight-720x340.png)
|
||||
|
||||
Finding disk space usage is no big deal in Unix-like operating systems. We have a built-in command named [**du**][1] that can be used to calculate and summarize the disk space usage in minutes. And, we have some third-party tools like [**Ncdu**][2] and [**Agedu**][3] which can also be used to track down the disk usage. As you already know, these are all command line utilities and you will see the disk usage results in plain-text format. However, some of you’d like to view the results in visual or kind of image format. No worries! I know one such GUI tool to find out the disk usage details. Say hello to **“Filelight”** , a graphical utility to visualize disk usage on your Linux system and displays the disk usage results in a colored radial layout. Filelight is one of the oldest project and it has been around for a long time. It is completely free to use and open source.
|
||||
|
||||
### Installing Filelight
|
||||
|
||||
Filelight is part of KDE applications and comes pre-installed with KDE-based Linux distributions.
|
||||
|
||||
If you’re using non-KDE distros, Filelight is available in the official repositories, so you can install it using the default package manager.
|
||||
|
||||
On Arch Linux and its variants such as Antergos, Manjaro Linux, Filelight can be installed as below.
|
||||
|
||||
```
|
||||
$ sudo pacman -S filelight
|
||||
```
|
||||
|
||||
On Debian, Ubuntu, Linux Mint:
|
||||
|
||||
```
|
||||
$ sudo apt install filelight
|
||||
```
|
||||
|
||||
On Fedora:
|
||||
|
||||
```
|
||||
$ sudo dnf install filelight
|
||||
```
|
||||
|
||||
On openSUSE:
|
||||
|
||||
```
|
||||
$ sudo zypper install filelight
|
||||
```
|
||||
|
||||
### Visualize Disk Usage On Your Linux System
|
||||
|
||||
Once installed, launch Filelight from Menu or application launcher.
|
||||
|
||||
FIlelight graphically represents your filesystem as a set of concentric segmented-rings.
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2018/09/filelight-1-1.png)
|
||||
|
||||
As you can see, Filelight displays the disk usage of the **/** and **/boot** filesystems by default.
|
||||
|
||||
You can also scan the individual folders of your choice to view the disk usage of that particular folder. To do so, go to **Filelight - > Scan -> Scan Folder** and choose the folder you want to scan.
|
||||
|
||||
Filelight excludes the following directories from scanning:
|
||||
|
||||
* /dev
|
||||
* /proc
|
||||
* /sys
|
||||
* /root
|
||||
|
||||
|
||||
|
||||
This option is helpful to skip the directories that you may not have permissions to read, or folders that are part of a virtual filesystem, such as /proc.
|
||||
|
||||
If you want to add any folder in this list, go to **Filelight - > Settings -> Scanning** and click “add” button and choose the folder you want to add in this list.
|
||||
|
||||
![](http://www.ostechnix.com/wp-content/uploads/2018/09/filelight-settings.png)
|
||||
|
||||
Similarly, to remove a folder from the list, choose the folder and click on “Remove”.
|
||||
|
||||
If you want to change the way filelight looks, go to **Settings - > Appearance** tab and change the color scheme as per your liking.
|
||||
|
||||
Each segment in the radial layout is represented with different colors. The following image represents the entire radial layout of **/** filesystem. To view the full information of files and folders, just hover the mouse pointer over them.
|
||||
|
||||
![](https://www.ostechnix.com/wp-content/uploads/2018/09/filelight-2.png)
|
||||
|
||||
You can navigate around the the filesystem by simply clicking on the respective segment. To view the disk usage of any file or folder, just click on them and you will get the complete disk usage details of that particular folder/file.
|
||||
|
||||
Not just local filesystem, Filelight can able to scan your local, remote and removable disks. If you’re using any KDE-based Linux distribution, it can be integrated into file managers like Konqueror, Dolphin and Krusader.
|
||||
|
||||
Unlike the CLI utilities, you don’t have to use any extra arguments or options to view the results in human-readable format. Filelight will display the disk usage in human-readable format by default.
|
||||
|
||||
### Conclusion
|
||||
|
||||
By using Filelight, you can quickly discover where exactly your diskspace is being used in your filesystem and free up the space wherever necessary by deleting the unwanted files or folders. If you are looking for some simple and user-learnedly graphical disk usage viewer, Filelight is worth trying.
|
||||
|
||||
And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned!
|
||||
|
||||
Cheers!
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.ostechnix.com/filelight-visualize-disk-usage-on-your-linux-system/
|
||||
|
||||
作者:[SK][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.ostechnix.com/author/sk/
|
||||
[1]: https://www.ostechnix.com/find-size-directory-linux/
|
||||
[2]: https://www.ostechnix.com/check-disk-space-usage-linux-using-ncdu/
|
||||
[3]: https://www.ostechnix.com/agedu-find-out-wasted-disk-space-in-linux/
|
@ -1,124 +0,0 @@
|
||||
差异文件(diffs)和补丁文件(patches)简介
|
||||
======
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/find-file-linux-code_magnifying_glass_zero.png?itok=E2HoPDg0)
|
||||
|
||||
如果你曾有机会在一个使用分布式开发模型的大型代码库上工作过,你就应该听说过类似下面的话,"Sue刚发过来一个补丁","Rajiv 正在签出差异文件", 可能这些词(补丁,差异文件)对你而言很陌生,而你确定很想搞懂他们到底指什么。开源软件对上述提到的名词有很大的贡献,作为从开发 Apache web 服务器到开发Linux 内核的开发模型,"基于补丁文件的开发" 这一模式贯穿了上述项目的始终。实际上,你可能不知道 Apache 的名字就来自一系列的代码补丁,他们被一一收集起来并针对原来的[NCSA HTTPd server source code][1]进行了校对
|
||||
|
||||
你可能认为前面说的只不过是些逸闻,但是一份早期的[capture of the Apache website][2]声称Apache 的名字就是来自于最早的“补丁文件”集合;(译注:Apache 英文音和补丁相似),是“打了补丁的”服务器的英文名字简化。
|
||||
|
||||
好了,言归正传,程序员嘴里说的"差异"和"补丁" 到底是什么?
|
||||
|
||||
首先,在这篇文章里,我们可以认为这两个术语都指向同一个概念。“差异” 就是”补丁“。Unix 下的同名工具程序diff("差异")和patch("补丁")剖析了一个或多个文件之间的”差异”。下面我们看看diff 的例子:
|
||||
|
||||
一个"补丁"指的是文件之间一系列差异,这些差异能被 Unix 的 diff程序应用在源代码树上,使之转变为程序员想要的文件状态。我们能使用diff 工具来创建“差异”( 或“补丁”),然后将他们“打” 在一个没有这个补丁的源代码版本上,此外,(我又要开始跑题了...),“补丁” 这个词真的指在计算机的早期使用打卡机的时候,用来覆盖在纸带上的用于修复代码错误的覆盖纸,那个时代纸带(上面有孔)就是在计算机处理器上运行的程序。下面的这张图,来自[Wikipedia Page][3] 真切的描绘了最初的“ 打补丁”这个词的出处:
|
||||
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/360px-harvard_mark_i_program_tape.agr_.jpg)
|
||||
|
||||
现在你对补丁和差异就了一个基本的概念,让我们来看看软件开发者是怎么使用这些工具的。如果你还没有使用过类似于[Git][4]这样的源代码版本控制工具的话,我将会一步步展示最流行的软件项目是怎么使用它们的。如果你将一个软件的生命周期看成是一条时间线的话,你就能看见这个软件的点滴变化,比如在何时源代码树加上了一个功能,在何时源代码树修复了一个功能缺陷。我们称这些改变的点为“进行了一次提交”,”提交“这个词被当今最流行的源代码版本管理工具Git使用, 当你想检查在一个提交前后的代码变化的话,(或者在许多个提交之间的代码变化),你都可以使用工具来观察文件差异。
|
||||
|
||||
如果你在使用 Git 开发软件的话,你开发环境本地有可能就有你想交给别的开发者的提交,为了给别的开发者你的提交,一个方法就是创建一个你本地文件的差异文件,然后将这个“补丁”发送给和你工作在同一个源代码树的别的开发者。别的开发者在“打”了你的补丁之后,就能看到在你的代码变树上的变化。
|
||||
|
||||
|
||||
### Linux, Git, 和 GitHub
|
||||
|
||||
这种共享补丁的开发模型正是现今 Linux 内核社区如何处理内核修改提议而采用的模型。如果你有机会浏览任何一个主流的 Linux 内核邮件列表-主要是[LKML][6],包括[linux-containers][7],[fs-devel][8],[Netdev][9]等等,你能看到很多开发者会贴出他们想让其他内核开发者审核,测试或者合入Linux官方Git代码树某个提交的补丁。当然,讨论 Git 不在这篇文章范围之内(Git 是由 Linus Torvalds 开发的源代码控制系统,它支持分布式开发模型以及允许独立于主要代码仓库的补丁包,这些补丁包能被推送或拉取到不同的源代码树上并遵守这些代码树各自的开发流程。)
|
||||
|
||||
在继续我们的话题之前,我们当然不能忽略和补丁和差异这个概念最相关的的服务:[GitHub][10]。从它的名字就能猜想出 GitHub 是基于 Git 的,而且它还围绕着 Git对分布式开源代码开发模型提供了基于Web 和 API 的工作流管理。(译注:即Pull Request -- 拉取请求)。在 GitHub 上,分享补丁的方式不是像 Linux 内核社区那样通过邮件列表,而是通过创建一个 **拉取请求** 。当你提交你自己源代码的改动时,你能通过创建一个针对软件项目的主仓库的“拉取请求”来分享你的代码改动(译注:即核心开发者维护一个主仓库,开发者去“fork”这个仓库,待各自的提交后再创建针对这个主仓库的拉取请求,所有的拉取请求由主仓库的核心开发者批准后才能合入主代码库。)GitHub 被当今很多活跃的开源社区所采用,如[Kubernetes][11],[Docker][12],[the Container Network Interface (CNI)][13],[Istio][14]等等。在 GitHub 的世界里,用户会倾向于使用基于 Web 页面的方式来审核一个拉取请求里的补丁或差异,你也可以直接访问原始的补丁并在命令行上直接使用它们。
|
||||
|
||||
|
||||
|
||||
### 该说点干货了
|
||||
|
||||
我们前面已经讲了在流行的开源社区了是怎么应用补丁和 diff的,现在看看一些例子。
|
||||
|
||||
第一个例子包括一个源代码树的两个不同拷贝,其中一个有代码改动,我们想用 diff来看看这些改动是什么。这个例子里,我们想看的是“合并格式”的补丁,这是现在软件开发世界里最通用的格式。如果想知道更详细参数的用法以及如何生成diff,请参考diff手册。原始的代码在sources-orig目录 而改动后的代码在sources-fixed目录. 如果要在你的命令行上用“合并格式”来展示补丁,请运行如下命令。(译注: 参数 N 代表如果比较的文件不存在,则认为是个空文件, a代表将所有文件都作为文本文件对待,u 代表使用合并格式并输出上下文,r 代表递归比较目录)
|
||||
|
||||
|
||||
```
|
||||
$ diff -Naur sources-orig/ sources-fixed/
|
||||
```
|
||||
|
||||
...下面是 diff命令的输出:
|
||||
|
||||
```
|
||||
diff -Naur sources-orig/officespace/interest.go sources-fixed/officespace/interest.go
|
||||
--- sources-orig/officespace/interest.go 2018-08-10 16:39:11.000000000 -0400
|
||||
+++ sources-fixed/officespace/interest.go 2018-08-10 16:39:40.000000000 -0400
|
||||
@@ -11,15 +11,13 @@
|
||||
InterestRate float64
|
||||
}
|
||||
|
||||
+// compute the rounded interest for a transaction
|
||||
func computeInterest(acct *Account, t Transaction) float64 {
|
||||
|
||||
interest := t.Amount * t.InterestRate
|
||||
roundedInterest := math.Floor(interest*100) / 100.0
|
||||
remainingInterest := interest - roundedInterest
|
||||
|
||||
- // a little extra..
|
||||
- remainingInterest *= 1000
|
||||
-
|
||||
// Save the remaining interest into an account we control:
|
||||
acct.Balance = acct.Balance + remainingInterest
|
||||
```
|
||||
最开始几行 diff的输出可以这样解释:三个‘---’显示了原来文件的名字;任何在原文件(译注:不是源文件)里存在而在新文件里不存在的行将会用前缀‘-’,用来表示这些行被从源代码里‘减去’了。而‘+++’表示的则相反:在新文件里被加上的行会被放上前缀‘+’,表示这是在新文件里被'加上'的行。每一个补丁”块“(用@@作为前缀的的部分)都有上下文的行号,这能帮助补丁工具(或其他处理器)知道在代码的哪里应用这个补丁块。你能看到我们已经修改了”办公室“这部电影里提到的那个函数(移除了三行并加上了一行代码注释),电影里那个有点贪心的工程师可是偷偷的在计算利息的函数里加了点”料“哦。( LCTT译注:剧情详情请见电影 https://movie.douban.com/subject/1296424/)
|
||||
|
||||
|
||||
如果你想找人来测试你的代码改动,你可以将差异保存到一个补丁里:
|
||||
|
||||
```
|
||||
$ diff -Naur sources-orig/ sources-fixed/ >myfixes.patch
|
||||
```
|
||||
|
||||
现在你有补丁 myfixes.patch了,你能把它分享给别的开发者,他们可以将这个补丁打在他们自己的源代码树上从而得到和你一样的代码并测试他们。如果一个开发者的当前工作目录就是他的源代码树的根的话,他可以用下面的命令来打补丁:
|
||||
|
||||
|
||||
```
|
||||
$ patch -p1 < ../myfixes.patch
|
||||
patching file officespace/interest.go
|
||||
```
|
||||
现在这个开发者的源代码树已经打好补丁并准备好构建和测试文件的修改了。那么如果这个开发者在打补丁之前已经改动过了怎么办?只要这些改动没有直接冲突(译注:比如改在同一行上),补丁工具就能自动的合并代码的改动。例如下面的interest.go 文件,他有其他几处改动,然后它想打上myfixes.patch 这个补丁:
|
||||
|
||||
|
||||
```
|
||||
$ patch -p1 < ../myfixes.patch
|
||||
patching file officespace/interest.go
|
||||
Hunk #1 succeeded at 26 (offset 15 lines).
|
||||
```
|
||||
在这个例子中,补丁警告说代码改动并不在文件原来的地方而是偏移了15行。如果你文件改动的很厉害,补丁可能干脆说找不到要应用的地方,还好补丁程序提供了提供了打开”模糊“匹配的选项(这个选项在文档里有预置的警告信息,对其讲解已经超出了本文的范围)
|
||||
|
||||
如果你使用 Git 或者 GitHub 的话,你可能不会直接使用diff或patch。Git 已经内置了这些功能,你能使用这些功能和共享一个源代码树的其他开发者交互,拉取或合并代码。Git一个比较相近的功能是可以使用 git diff 来对你的本地代码树生成全局差异,又或者对你的任意两次”引用“(可能是一个代表提交的数字,或一个标记或分支的名字,等等)做全局补丁。你甚至能简单的用管道将 git diff的输出到一个文件里(这个文件必须严格符合将要被使用它的程序的输入要求),然后将这个文件交给一个并不使用 Git 的开发者应用到他的代码上。当然,GitHub 把这些功能放到了 Web 上,你能直接在 Web 页面上查看一个拉取请求的文件变动。在Web 上你能看到所展示的合并差异,GitHub 还允许你将这些代码改动下载为原始的补丁文件。
|
||||
|
||||
|
||||
### 总结
|
||||
|
||||
好了,你已经学到了”差异“和”补丁“是什么,以及在 Unix/Linux 上怎么使用命令行工具和他们交互。除非你还在像 Linux 内核开发这样的项目中工作而使用完全基于补丁的开发方式,你应该会主要通过你的源代码控制系统(如Git)来使用补丁。但熟悉像 GitHub 这样的高级别工具的技术背景和技术底层对你的工作也是大有裨益的。谁知道会不会有一天你需要和一个来自 Linux 世界邮件列表的补丁包打交道呢?
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/8/diffs-patches
|
||||
|
||||
作者:[Phil Estes][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[David Chen](https://github.com/DavidChenLiang)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:https://opensource.com/users/estesp
|
||||
[1]:https://github.com/TooDumbForAName/ncsa-httpd
|
||||
[2]:https://web.archive.org/web/19970615081902/http:/www.apache.org/info.html
|
||||
[3]:https://en.wikipedia.org/wiki/Patch_(computing)
|
||||
[4]:https://git-scm.com/
|
||||
[5]:https://subversion.apache.org/
|
||||
[6]:https://lkml.org/
|
||||
[7]:https://lists.linuxfoundation.org/pipermail/containers/
|
||||
[8]:https://patchwork.kernel.org/project/linux-fsdevel/list/
|
||||
[9]:https://www.spinics.net/lists/netdev/
|
||||
[10]:https://github.com/
|
||||
[11]:https://kubernetes.io/
|
||||
[12]:https://www.docker.com/
|
||||
[13]:https://github.com/containernetworking/cni
|
||||
[14]:https://istio.io/
|
@ -0,0 +1,346 @@
|
||||
使用 PySimpleGUI 轻松为程序和脚本增加 GUI
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/web_browser_desktop_devlopment_design_system_computer.jpg?itok=pfqRrJgh)
|
||||
|
||||
对于 `.exe` 类型的程序文件,我们可以通过双击鼠标左键打开;但对于 `.py` 类型的 Python 程序,几乎不会有人尝试同样的操作。对于一个(非程序员类型的)典型用户,他们双击打开 `.exe` 文件时预期弹出一个可以交互的窗体。基于 `Tkinter`,可以通过<ruby>标准 Python 安装<rt>standard Python installations</rt></ruby>的方式提供 GUI,但很多程序都不太可能这样做。
|
||||
|
||||
如果打开 Python 程序并进入 GUI 界面变得如此容易,以至于真正的初学者也可以掌握,会怎样呢?会有人感兴趣并使用吗?这个问题不好回答,因为直到今天创建自定义 GUI 布局仍不是件容易的事情。
|
||||
|
||||
在为程序或脚本增加 GUI 这件事上,似乎存在能力的“错配”。(缺乏这方面能力的)真正的初学者被迫只能使用命令行方式,而很多(具备这方面能力的)高级程序员却不愿意花时间创建一个 `Tkinter` GUI。
|
||||
|
||||
### GUI 框架
|
||||
|
||||
Python 的 GUI 框架并不少,其中 `Tkinter`,`wxPython`,`Qt` 和 `Kivy` 是几种比较主流的框架。此外,还有不少在上述框架基础上封装的简化框架,例如 `EasyGUI`,`PyGUI` 和 `Pyforms` 等。
|
||||
|
||||
但问题在于,对于初学者(这里是指编程经验不超过 6 个月的用户)而言,即使是最简单的主流框架,他们也无从下手;他们也可以选择封装过的(简化)框架,但仍难以甚至无法创建自定义 GUI <ruby>布局<rt>layout</rt></ruby>。即便学会了某种(简化)框架,也需要编写连篇累牍的代码。
|
||||
|
||||
[`PySimpleGUI`][1] 尝试解决上述 GUI 难题,它提供了一种简单明了、易于理解、方便自定义的 GUI 接口。如果使用 `PySimpleGUI`,很多复杂的 GUI 也仅需不到 20 行代码。
|
||||
|
||||
### 秘诀
|
||||
|
||||
`PySimpleGUI` 极为适合初学者的秘诀在于,它已经包含了绝大多数原本需要用户编写的代码。`PySimpleGUI` 处理按钮<ruby>回调<rt>callback</rt></ruby>,无需用户编写代码。对于初学者,在几周内掌握函数的概念已经不容易了,要求其理解回调函数似乎有些强人所难。
|
||||
|
||||
在大部分 GUI 框架中,布局 GUI <ruby>小部件<rt>widgets</rt></ruby>通常需要写一些代码,每个小部件至少 1-2 行。`PySimpleGUI` 使用了“auto-packer”技术,可以自动创建布局。因而,布局 GUI 窗口不再需要 `pack` 或 `grid` 系统。
|
||||
|
||||
(LCTT 译注:这里提到的 `pack` 和 `grid` 都是 `Tkinter` 的布局管理器,另外一种叫做 `place`)
|
||||
|
||||
最后,`PySimpleGUI` 框架编写中有效利用 Python 语言特性,降低用户代码量并简化GUI 数据返回的方式。在<ruby>窗体<rt>form</rt></ruby>布局中创建小部件时,小部件会被部署到对应的布局中,无需额外的代码。
|
||||
|
||||
### GUI 是什么?
|
||||
|
||||
绝大多数 GUI 只完成一件事情:收集用户数据并返回。在程序员看来,可以归纳为如下的函数调用:
|
||||
|
||||
```
|
||||
button, values = GUI_Display(gui_layout)
|
||||
```
|
||||
|
||||
绝大多数 GUI 支持的用户行为包括鼠标点击(例如,“确认”,“取消”,“保存”,“是”和“否”等)和内容输入。GUI 本质上可以归结为一行代码。
|
||||
|
||||
这也正是 `PySimpleGUI` (简单 GUI 模式)的工作原理。当执行命令显示 GUI 后,除非点击鼠标关闭窗体,否则不会执行任何代码。
|
||||
|
||||
当然还有更复杂的 GUI,其中鼠标点击后窗口并不关闭;例如,机器人的远程控制界面,聊天窗口等。这类复杂的窗体也可以用 `PySimpleGUI` 创建。
|
||||
|
||||
### 快速创建 GUI
|
||||
|
||||
`PySimpleGUI` 什么时候有用呢?显然,是你需要 GUI 的时候。仅需不超过 5 分钟,就可以让你创建并尝试 GUI。最便捷的 GUI 创建方式就是从 [PySimpleGUI 经典实例][2]中拷贝一份代码。具体操作流程如下:
|
||||
|
||||
* 找到一个与你需求最接近的 GUI
|
||||
* 从经典实例中拷贝代码
|
||||
* 粘贴到 IDE 中并运行
|
||||
|
||||
下面我们看一下书中的第一个<ruby>经典实例<rt>recipe</rt></ruby>:
|
||||
|
||||
```
|
||||
import PySimpleGUI as sg
|
||||
|
||||
# Very basic form. Return values as a list
|
||||
form = sg.FlexForm('Simple data entry form') # begin with a blank form
|
||||
|
||||
layout = [
|
||||
[sg.Text('Please enter your Name, Address, Phone')],
|
||||
[sg.Text('Name', size=(15, 1)), sg.InputText('name')],
|
||||
[sg.Text('Address', size=(15, 1)), sg.InputText('address')],
|
||||
[sg.Text('Phone', size=(15, 1)), sg.InputText('phone')],
|
||||
[sg.Submit(), sg.Cancel()]
|
||||
]
|
||||
|
||||
button, values = form.LayoutAndRead(layout)
|
||||
|
||||
print(button, values[0], values[1], values[2])
|
||||
```
|
||||
|
||||
运行后会打开一个大小适中的窗体。
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/pysimplegui_cookbook-form.jpg)
|
||||
|
||||
如果你只是想收集一些字符串类型的值,拷贝上述经典实例中的代码,稍作修改即可满足你的需求。
|
||||
|
||||
你甚至可以只用 5 行代码创建一个自定义 GUI 布局。
|
||||
|
||||
```
|
||||
import PySimpleGUI as sg
|
||||
|
||||
form = sg.FlexForm('My first GUI')
|
||||
|
||||
layout = [ [sg.Text('Enter your name'), sg.InputText()],
|
||||
[sg.OK()] ]
|
||||
|
||||
button, (name,) = form.LayoutAndRead(layout)
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/pysimplegui-5-line-form.jpg)
|
||||
|
||||
### 5 分钟内创建一个自定义 GUI
|
||||
|
||||
在简单布局的基础上,通过修改经典实例中的代码,5 分钟内即可使用 `PySimpleGUI` 创建自定义布局。
|
||||
|
||||
在 `PySimpleGUI` 中,<ruby>小部件<rt>widgets</rt></ruby>被称为<ruby>元素<rt>elements</rt></ruby>。元素的名称与编码中使用的名称保持一致。
|
||||
|
||||
(LCTT 译注:`Tkinter` 中使用小部件这个词)
|
||||
|
||||
#### 核心元素
|
||||
```
|
||||
Text
|
||||
InputText
|
||||
Multiline
|
||||
InputCombo
|
||||
Listbox
|
||||
Radio
|
||||
Checkbox
|
||||
Spin
|
||||
Output
|
||||
SimpleButton
|
||||
RealtimeButton
|
||||
ReadFormButton
|
||||
ProgressBar
|
||||
Image
|
||||
Slider
|
||||
Column
|
||||
```
|
||||
|
||||
#### 元素简写
|
||||
|
||||
`PySimpleGUI` 还包含两种元素简写方式。一种是元素类型名称简写,例如 `T` 用作 `Text` 的简写;另一种是元素参数被配置了默认值,你可以无需指定所有参数,例如 `Submit` 按钮默认的文本就是“Submit”。
|
||||
|
||||
```
|
||||
T = Text
|
||||
Txt = Text
|
||||
In = InputText
|
||||
Input = IntputText
|
||||
Combo = InputCombo
|
||||
DropDown = InputCombo
|
||||
Drop = InputCombo
|
||||
```
|
||||
|
||||
(LCTT 译注:第一种简写就是 Python 类的别名,第二种简写是在返回元素对象的 Python 函数定义时指定了参数的默认值)
|
||||
|
||||
#### 按钮简写
|
||||
|
||||
一些通用按钮具有简写实现,包括:
|
||||
|
||||
```
|
||||
FolderBrowse
|
||||
FileBrowse
|
||||
FileSaveAs
|
||||
Save
|
||||
Submit
|
||||
OK
|
||||
Ok (LCTT 译注:这里 `k` 是小写)
|
||||
Cancel
|
||||
Quit
|
||||
Exit
|
||||
Yes
|
||||
No
|
||||
```
|
||||
|
||||
此外,还有通用按钮功能对应的简写:
|
||||
|
||||
```
|
||||
SimpleButton
|
||||
ReadFormButton
|
||||
RealtimeButton
|
||||
```
|
||||
|
||||
(LCTT 译注:其实就是返回 `Button` 类实例的函数)
|
||||
|
||||
上面就是 `PySimpleGUI` 支持的全部元素。如果不在上述列表之中,就不会在你的窗口布局中生效。
|
||||
|
||||
(LCTT 译注:上述都是 `PySimpleGUI` 的类名、类别名或返回实例的函数,自然只能使用列表内的。)
|
||||
|
||||
#### GUI 设计模式
|
||||
|
||||
对于 GUI 程序,创建并展示窗口的调用大同小异,差异在于元素的布局。
|
||||
|
||||
设计模式代码与上面的例子基本一致,只是移除了布局:
|
||||
|
||||
```
|
||||
import PySimpleGUI as sg
|
||||
|
||||
form = sg.FlexForm('Simple data entry form')
|
||||
# Define your form here (it's a list of lists)
|
||||
button, values = form.LayoutAndRead(layout)
|
||||
```
|
||||
|
||||
(LCTT 译注:这段代码无法运行,只是为了说明每个程序都会用到的设计模式)
|
||||
|
||||
对于绝大多数 GUI,编码流程如下:
|
||||
|
||||
* 创建窗体对象
|
||||
* 以“列表的列表”的形式定义 GUI
|
||||
* 展示 GUI 并获取元素的值
|
||||
|
||||
上述流程与 `PySimpleGUI` 设计模式部分的代码一一对应。
|
||||
|
||||
#### GUI 布局
|
||||
|
||||
要创建自定义 GUI,首先要将窗体分割成多个行,因为窗体是一行一行定义的。然后,在每一行中从左到右依次放置元素。
|
||||
|
||||
我们得到的就是一个“列表的列表”,类似如下:
|
||||
|
||||
```
|
||||
layout = [ [Text('Row 1')],
|
||||
[Text('Row 2'), Checkbox('Checkbox 1', OK()), Checkbox('Checkbox 2'), OK()] ]
|
||||
|
||||
```
|
||||
|
||||
上述布局对应的效果如下:
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/pysimplegui-custom-form.jpg)
|
||||
|
||||
### 展示 GUI
|
||||
|
||||
当你完成布局、拷贝完用于创建和展示窗体的代码后,下一步就是展示窗体并收集用户数据。
|
||||
|
||||
下面这行代码用于展示窗体并返回收集的数据:
|
||||
|
||||
```
|
||||
button, values = form.LayoutAndRead(layout)
|
||||
```
|
||||
|
||||
窗体返回的结果由两部分组成:一部分是被点击按钮的名称,另一部分是一个列表,包含所有用户输入窗体的值。
|
||||
|
||||
在这个例子中,窗体显示后用户直接点击 `OK` 按钮,返回的结果如下:
|
||||
|
||||
```
|
||||
button == 'OK'
|
||||
values == [False, False]
|
||||
```
|
||||
|
||||
`Checkbox` 类型元素返回 `True` 或 `False` 类型的值。由于默认处于未选中状态,两个元素的值都是 `False`。
|
||||
|
||||
### 显示元素的值
|
||||
|
||||
一旦从 GUI 获取返回值,检查返回变量中的值是个不错的想法。与其使用 `print` 语句进行打印,我们不妨坚持使用 GUI 并在一个窗口中输出这些值。
|
||||
|
||||
(LCTT 译注:考虑使用的是 Python 3 版本,`print` 应该是函数而不是语句)
|
||||
|
||||
在 `PySimpleGUI` 中,有多种消息框可供选取。传递给消息框(函数)的数据会被显示在消息框中;函数可以接受任意数目的参数,你可以轻松的将所有要查看的变量展示出来。
|
||||
|
||||
在 `PySimpleGUI` 中,最常用的消息框是 `MsgBox`。要展示上面例子中的数据,只需编写一行代码:
|
||||
|
||||
```
|
||||
MsgBox('The GUI returned:', button, values)
|
||||
```
|
||||
|
||||
### 整合
|
||||
|
||||
好了,你已经了解了基础知识,让我们创建一个包含尽可能多 `PySimpleGUI` 元素的窗体吧!此外,为了更好的感观效果,我们将采用绿色/棕褐色的配色方案。
|
||||
|
||||
```
|
||||
import PySimpleGUI as sg
|
||||
|
||||
sg.ChangeLookAndFeel('GreenTan')
|
||||
|
||||
form = sg.FlexForm('Everything bagel', default_element_size=(40, 1))
|
||||
|
||||
column1 = [[sg.Text('Column 1', background_color='#d3dfda', justification='center', size=(10,1))],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
|
||||
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]]
|
||||
layout = [
|
||||
[sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25))],
|
||||
[sg.Text('Here is some text.... and a place to enter text')],
|
||||
[sg.InputText('This is my text')],
|
||||
[sg.Checkbox('My first checkbox!'), sg.Checkbox('My second checkbox!', default=True)],
|
||||
[sg.Radio('My first Radio! ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
|
||||
[sg.Multiline(default_text='This is the default Text should you decide not to type anything', size=(35, 3)),
|
||||
sg.Multiline(default_text='A second multi-line', size=(35, 3))],
|
||||
[sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 3)),
|
||||
sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
|
||||
[sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
|
||||
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
|
||||
sg.Column(column1, background_color='#d3dfda')],
|
||||
[sg.Text('_' * 80)],
|
||||
[sg.Text('Choose A Folder', size=(35, 1))],
|
||||
[sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'),
|
||||
sg.InputText('Default Folder'), sg.FolderBrowse()],
|
||||
[sg.Submit(), sg.Cancel()]
|
||||
]
|
||||
|
||||
button, values = form.LayoutAndRead(layout)
|
||||
sg.MsgBox(button, values)
|
||||
```
|
||||
|
||||
看上面要写不少代码,但如果你试着直接使用 `Tkinter` 框架实现同样的 GUI,你很快就会发现 `PySimpleGUI` 版本的代码是多么的简洁。
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/pysimplegui-everything.jpg)
|
||||
|
||||
代码的最后一行打开了一个消息框,效果如下:
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/pysimplegui-message-box.jpg)
|
||||
|
||||
消息框函数中的每一个参数的内容都会被打印到单独的行中。本例的消息框中包含两行,其中第二行非常长而且包含列表嵌套。
|
||||
|
||||
建议花一点时间将上述结果与 GUI 中的元素一一比对,这样可以更好的理解这些结果是如何产生的。
|
||||
|
||||
### 为你的程序或脚本添加 GUI
|
||||
|
||||
如果你有一个命令行方式使用的脚本,添加 GUI 不一定意味着完全放弃该脚本。一种简单的方案如下:如果脚本不需要命令行参数,那么可以直接使用 GUI 调用该脚本;反之,就按原来的方式运行脚本。
|
||||
|
||||
仅需类似如下的逻辑:
|
||||
|
||||
```
|
||||
if len(sys.argv) == 1:
|
||||
# collect arguments from GUI
|
||||
else:
|
||||
# collect arguements from sys.argv
|
||||
```
|
||||
|
||||
创建并运行 GUI 最便捷的方式就是从 [PySimpleGUI 经典实例][2]中拷贝一份代码并修改。
|
||||
|
||||
快来试试吧!给你一直疲于手动执行的脚本增加一些趣味。只需 5-10 分钟即可玩转示例脚本。你可能发现一个几乎满足你需求的经典实例;如果找不到,也很容易自己编写一个。即使你真的玩不转,也只是浪费了 5-10 分钟而已。
|
||||
|
||||
### 资源
|
||||
|
||||
#### 安装方式
|
||||
|
||||
支持 `Tkinter` 的系统就支持 `PySimpleGUI`,甚至包括<ruby>树莓派<rt>Raspberry Pi</rt></ruby>,但你需要使用 Python 3。
|
||||
|
||||
```
|
||||
pip install PySimpleGUI
|
||||
```
|
||||
|
||||
#### 文档
|
||||
|
||||
* [手册][3]
|
||||
* [经典实例][2]
|
||||
* [GitHub repository][1]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/8/pysimplegui
|
||||
|
||||
作者:[Mike Barnett][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[pinewall](https://github.com/pinewall)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/pysimplegui
|
||||
[1]: https://github.com/MikeTheWatchGuy/PySimpleGUI
|
||||
[2]: https://pysimplegui.readthedocs.io/en/latest/cookbook/
|
||||
[3]: https://pysimplegui.readthedocs.io/en/latest/
|
@ -0,0 +1,356 @@
|
||||
|
||||
|
||||
增强 Vim 编辑器,提高编辑效率
|
||||
======
|
||||
|
||||
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_hands_team_collaboration.png?itok=u82QepPk)
|
||||
|
||||
编者注:标题和文章最初提到的 `vi` 编辑器,现已更新为编辑器的正确名称:`Vim`。
|
||||
|
||||
`Vim` 作为一款功能强大、选项丰富的编辑器,为许多用户所热爱。本文介绍了一些在 `Vim` 中默认未启用但实际非常有用的选项。虽然可以在每个 `Vim` 会话中单独启用,但为了创建一个开箱即用的高效编辑环境,还是建议在 `Vim` 的配置文件中配置这些命令。
|
||||
|
||||
## 开始前的准备
|
||||
|
||||
这里所说的选项或配置均位于用户主目录中的 `Vim` 启动配置文件 `.vimrc`。 按照下面的说明在 `.vimrc` 中设置选项:
|
||||
|
||||
(注意:`vimrc` 文件也用于 `Linux` 中的全局配置,如 `/etc/vimrc` 或 `/etc/vim/vimrc`。本文所说的 `.vimrc` 均是指位于用户主目录中的 `.vimrc` 文件。)
|
||||
|
||||
`Linux` 系统中:
|
||||
|
||||
* 用 `Vim` 打开 `.vimrc` 文件: `vim ~/.vimrc`
|
||||
* 复制本文最后的 `选项列表` 粘贴到 `.vimrc` 文件
|
||||
* 保存并关闭 (`:wq`)
|
||||
|
||||
译者注:此处不建议使用 `Vim` 编辑 `.vimrc` 文件,因为很可能无法粘贴成功,可以选择 `gedit` 编辑器编辑 `.vimrc` 文件。
|
||||
|
||||
`Windows` 系统中:
|
||||
|
||||
* 首先,[安装 gvim][1]
|
||||
* 打开 `gvim`
|
||||
* 单击 `编辑` -> `启动设置`,打开 `.vimrc` 文件
|
||||
* 复制本文最后的 `选项列表` 粘贴到 `.vimrc` 文件
|
||||
* 单击 `文件` -> `保存`
|
||||
|
||||
译者注:此处应注意不要使用 `Windows` 自带的记事本编辑该 `.vimrc` 文件。
|
||||
|
||||
下面,我们将深入研究提高 `Vim` 编辑效率的选项。主要分为以下几类:
|
||||
|
||||
1. 缩进 & 制表符
|
||||
2. 显示 & 格式化
|
||||
3. 搜索
|
||||
4. 浏览 & 滚动
|
||||
5. 拼写
|
||||
6. 其他选项
|
||||
|
||||
## 1. 缩进 & 制表符
|
||||
|
||||
使 `Vim` 在创建新行的时候使用与上一行同样的缩进:
|
||||
|
||||
```vim
|
||||
set autoindent
|
||||
```
|
||||
|
||||
创建新行时使用智能缩进,主要用于 `C` 语言一类的程序。通常,打开 `smartindent` 时也应该打开 `autoindent`:
|
||||
|
||||
```vim
|
||||
set smartindent
|
||||
```
|
||||
|
||||
注意:`Vim` 具有语言感知功能,且其默认设置可以基于文件中的编程语言来改变配置以提高效率。有许多默认的配置选项,包括 `axs cindent`,`cinoptions`,`indentexpr` 等,没有在这里说明。 `syn` 是一个非常有用的命令,用于设置文件的语法以更改显示模式。
|
||||
|
||||
译者注:这里的 `syn` 是指 `syntax`,可用于设置文件所用的编程语言,开启对应的语法高亮,以及执行自动事件 (`autocmd`)。
|
||||
|
||||
设置文件里的制表符 `(TAB)` 的宽度(以空格的数量表示):
|
||||
|
||||
```vim
|
||||
set tabstop=4
|
||||
```
|
||||
|
||||
设置移位操作 `>>` 或 `<<` 的缩进长度(以空格的数量表示):
|
||||
|
||||
```vim
|
||||
set shiftwidth=4
|
||||
```
|
||||
|
||||
如果你更喜欢在编辑文件时使用空格而不是制表符,设置以下选项可以使 `Vim` 在你按下 `Tab` 键时用空格代替制表符。
|
||||
|
||||
```vim
|
||||
set expandtab
|
||||
```
|
||||
|
||||
注意:这可能会导致依赖于制表符的 `Python` 等编程语言出现问题。这时,你可以根据文件类型设置该选项(请参考 `autocmd`)。
|
||||
|
||||
## 2. 显示 & 格式化
|
||||
|
||||
要在每行的前面显示行号:
|
||||
|
||||
```vim
|
||||
set number
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture01.png)
|
||||
|
||||
要在文本行超过一定长度时自动换行:
|
||||
|
||||
```vim
|
||||
set textwidth=80
|
||||
```
|
||||
|
||||
要根据从窗口右侧向左数的列数来自动换行:
|
||||
|
||||
```vim
|
||||
set wrapmargin=2
|
||||
```
|
||||
|
||||
译者注:如果 `textwidth` 选项不等于零,本选项无效。
|
||||
|
||||
插入括号时,短暂地跳转到匹配的括号:
|
||||
|
||||
```vim
|
||||
set showmatch
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture02-03.jpg)
|
||||
|
||||
## 3. 搜索
|
||||
|
||||
高亮搜索内容的所有匹配位置:
|
||||
|
||||
```vim
|
||||
set hlsearch
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture04.png)
|
||||
|
||||
搜索过程中动态显示匹配内容:
|
||||
|
||||
```vim
|
||||
set incsearch
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/picture05.png)
|
||||
|
||||
搜索时忽略大小写:
|
||||
|
||||
```vim
|
||||
set ignorecase
|
||||
```
|
||||
|
||||
在打开 `ignorecase` 选项的条件下,搜索内容包含部分大写字符时,要使搜索大小写敏感:
|
||||
|
||||
```vim
|
||||
set smartcase
|
||||
```
|
||||
|
||||
例如,如果文件内容是:
|
||||
|
||||
> test\
|
||||
> Test
|
||||
|
||||
当打开 `ignorecase` 和 `smartcase` 选项时,搜索 `test` 时的突出显示:
|
||||
|
||||
> <font color=yellow>test</font>\
|
||||
> <font color=yellow>Test</font>
|
||||
|
||||
搜索 `Test` 时的突出显示:
|
||||
|
||||
> test\
|
||||
> <font color=yellow>Test</font>
|
||||
|
||||
## 4. 浏览 & 滚动
|
||||
|
||||
为获得更好的视觉体验,你可能希望将光标放在窗口中间而不是第一行,以下选项使光标距窗口上下保留 5 行。
|
||||
|
||||
```vim
|
||||
set scrolloff=5
|
||||
```
|
||||
|
||||
一个例子:
|
||||
|
||||
第一张图中 `scrolloff=0`,第二张图中 `scrolloff=5`。
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture06-07.jpg)
|
||||
|
||||
提示:如果你没有设置选项 `nowrap`,那么设置 `sidescrolloff` 将非常有用。
|
||||
|
||||
在 `Vim` 窗口底部显示一个永久状态栏,可以显示文件名、行号和列号等内容:
|
||||
|
||||
```vim
|
||||
set laststatus=2
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/picture08.png)
|
||||
|
||||
## 5. 拼写
|
||||
|
||||
`Vim` 有一个内置的拼写检查器,对于文本编辑和编码非常有用。`Vim` 可以识别文件类型并仅对代码中的注释进行拼写检查。使用下面的选项打开英语拼写检查:
|
||||
|
||||
```vim
|
||||
set spell spelllang=en_us
|
||||
```
|
||||
|
||||
译者注:中文、日文或其它东亚语字符通常会在打开拼写检查时被标为拼写错误,因为拼写检查不支持这些语种,可以在 `spelllang` 选项中加入 `cjk` 来忽略这些错误标注。
|
||||
|
||||
## 6. 其他选项
|
||||
|
||||
禁止创建备份文件:启用此选项后,`Vim` 将在覆盖文件前创建一个备份,文件成功写入后保留该备份。如果不想保留该备份文件,可以按下面的方式关闭:
|
||||
|
||||
```vim
|
||||
set nobackup
|
||||
```
|
||||
|
||||
禁止创建交换文件:启用此选项后,`Vim` 将在编辑该文件时创建一个交换文件。 交换文件用于在崩溃或发生使用冲突时恢复文件。交换文件是以 `.` 开头并以 `.swp` 结尾的隐藏文件。
|
||||
|
||||
```vim
|
||||
set noswapfile
|
||||
```
|
||||
|
||||
如果需要在同一个 `Vim` 窗口中编辑多个文件并进行切换。默认情况下,工作目录是打开的第一个文件的目录。而将工作目录自动切换到正在编辑的文件的目录是非常有用的。要自动切换工作目录:
|
||||
|
||||
```vim
|
||||
set autochdir
|
||||
```
|
||||
|
||||
`Vim` 自动维护编辑的历史记录,允许撤消更改。默认情况下,该历史记录仅在文件关闭之前有效。`Vim` 包含一个增强功能,使得即使在文件关闭后也可以维护撤消历史记录,这意味着即使在保存、关闭和重新打开文件后,也可以撤消之前的更改。历史记录文件是使用 `.un~` 扩展名保存的隐藏文件。
|
||||
|
||||
```vim
|
||||
set undofile
|
||||
```
|
||||
|
||||
错误信息响铃,只对错误信息起作用:
|
||||
|
||||
```vim
|
||||
set errorbells
|
||||
```
|
||||
|
||||
如果你愿意,还可以设置错误视觉提示:
|
||||
|
||||
```vim
|
||||
set visualbell
|
||||
```
|
||||
|
||||
## 惊喜
|
||||
|
||||
vi provides long-format as well as short-format commands. Either format can be used to set or unset the configuration.
|
||||
|
||||
`Vim` 提供长格式和短格式命令,两种格式都可用于设置或取消选项配置。
|
||||
|
||||
`autoindent` 选项的长格式是:
|
||||
|
||||
```vim
|
||||
set autoindent
|
||||
```
|
||||
|
||||
`autoindent` 选项的短格式是:
|
||||
|
||||
```vim
|
||||
set ai
|
||||
```
|
||||
|
||||
To see the current configuration setting of a command without changing its current value, use `?` at the end:
|
||||
|
||||
要在不更改选项当前值的情况下查看其当前设置,可以在 `Vim` 的命令行上使用在末尾加上 `?` 的命令:
|
||||
|
||||
```vim
|
||||
set autoindent?
|
||||
```
|
||||
|
||||
在大多数选项前加上 `no` 前缀可以取消或关闭选项:
|
||||
|
||||
```vim
|
||||
set noautoindent
|
||||
```
|
||||
|
||||
可以为单独的文件配置选项,而不必修改全局配置文件。需要的话,请打开文件并输入 `:`,然后键入 `set`命令。这样的话,配置仅对当前的文件编辑会话有效。
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture09.png)
|
||||
|
||||
使用命令行获取帮助:
|
||||
|
||||
```vim
|
||||
:help autoindent
|
||||
```
|
||||
|
||||
![](https://opensource.com/sites/default/files/uploads/picture10-11.jpg)
|
||||
|
||||
注意:此处列出的命令仅对 `Linux` 上的 `Vim 7.4` 版本和 `Windows` 上的 `Vim 8.0` 版本进行了测试。
|
||||
|
||||
这些有用的命令肯定会增强您的 `Vim` 使用体验。你会推荐哪些其他有用的命令?
|
||||
|
||||
## 选项列表
|
||||
|
||||
复制该选项列表粘贴到 `.vimrc` 文件中:
|
||||
|
||||
```vim
|
||||
" Indentation & Tabs
|
||||
|
||||
set autoindent
|
||||
|
||||
set smartindent
|
||||
|
||||
set tabstop=4
|
||||
|
||||
set shiftwidth=4
|
||||
|
||||
set expandtab
|
||||
|
||||
set smarttab
|
||||
|
||||
" Display & format
|
||||
|
||||
set number
|
||||
|
||||
set textwidth=80
|
||||
|
||||
set wrapmargin=2
|
||||
|
||||
set showmatch
|
||||
|
||||
" Search
|
||||
|
||||
set hlsearch
|
||||
|
||||
set incsearch
|
||||
|
||||
set ignorecase
|
||||
|
||||
set smartcase
|
||||
|
||||
" Browse & Scroll
|
||||
|
||||
set scrolloff=5
|
||||
|
||||
set laststatus=2
|
||||
|
||||
" Spell
|
||||
|
||||
set spell spelllang=en_us
|
||||
|
||||
" Miscellaneous
|
||||
|
||||
set nobackup
|
||||
|
||||
set noswapfile
|
||||
|
||||
set autochdir
|
||||
|
||||
set undofile
|
||||
|
||||
set visualbell
|
||||
|
||||
set errorbells
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/18/9/vi-editor-productivity-powerhouse
|
||||
|
||||
作者:[Girish Managoli][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[idea2act](https://github.com/idea2act)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/gammay
|
||||
[1]: https://www.vim.org/download.php#pc
|
Loading…
Reference in New Issue
Block a user