mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-13 22:30:37 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
752f88e196
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,4 +1,4 @@
|
||||
How To Enable Hardware Accelerated Video Decoding In Chromium On Ubuntu Or Linux Mint
|
||||
Grave Accent翻译中 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.
|
||||
|
||||
|
@ -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,110 +0,0 @@
|
||||
translating---geekpi
|
||||
|
||||
Find your systems easily on a LAN with mDNS
|
||||
======
|
||||
|
||||
![](https://fedoramagazine.org/wp-content/uploads/2018/09/mDNS-816x345.jpg)
|
||||
|
||||
Multicast DNS, or mDNS, lets systems broadcast queries on a local network to find other resources by name. Fedora users often own multiple Linux systems on a router without sophisticated name services. In that case, mDNS lets you talk to your multiple systems by name — without touching the router in most cases. You also don’t have to keep files like /etc/hosts in sync on all the local systems. This article shows you how to set it up.
|
||||
|
||||
mDNS is a zero-configuration networking service that’s been around for quite a while. Fedora ships Avahi, a zero-configuration stack that includes mDNS, as part of Workstation. (mDNS is also part of Bonjour, found on Mac OS.)
|
||||
|
||||
This article assumes you have two systems running supported versions of Fedora (27 or 28). Their host names are meant to be castor and pollux.
|
||||
|
||||
### Installing packages
|
||||
|
||||
Make sure the nss-mdns and avahi packages are installed on your system. You might have a different version, which is fine:
|
||||
```
|
||||
$ rpm -q nss-mdns avahi
|
||||
nss-mdns-0.14.1-1.fc28.x86_64
|
||||
avahi-0.7-13.fc28.x86_64
|
||||
|
||||
```
|
||||
|
||||
Fedora Workstation provides both of these packages by default. If not present, install them:
|
||||
```
|
||||
$ sudo dnf install nss-mdns avahi
|
||||
|
||||
```
|
||||
|
||||
Make sure the avahi-daemon.service unit is enabled and running. Again, this is the default on Fedora Workstation.
|
||||
```
|
||||
$ sudo systemctl enable --now avahi-daemon.service
|
||||
|
||||
```
|
||||
|
||||
Although optional, you might also want to install the avahi-tools package. This package includes a number of handy utilities for checking how well the zero-configuration services on your system are working. Use this sudo command:
|
||||
```
|
||||
$ sudo dnf install avahi-tools
|
||||
|
||||
```
|
||||
|
||||
The /etc/nsswitch.conf file controls which services your system uses to resolve services, and in what order. You should see a line like this in that file:
|
||||
```
|
||||
hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname
|
||||
|
||||
```
|
||||
|
||||
Notice the commands mdns4_minimal [NOTFOUND=return]. They tell your system to use the multicast DNS resolver to resolve a hostname to an IP address. Even if that service works, the remaining services are tried if the name doesn’t resolve.
|
||||
|
||||
If you don’t see a configuration similar to this, you can edit it (as the root user). However, the nss-mdns package handles this for you. Remove and reinstall that package to fix the file, if you’re uncomfortable editing it yourself.
|
||||
|
||||
Follow the steps above for **both systems**.
|
||||
|
||||
### Setting host name and testing
|
||||
|
||||
Now that you’ve done the common configuration work, set up each host’s name in one of these ways:
|
||||
|
||||
1. If you’re using Fedora Workstation, [you can use this procedure][1].
|
||||
|
||||
2. If not, use hostnamectl to do the honors. Do this for the first box:
|
||||
```
|
||||
$ hostnamectl set-hostname castor
|
||||
|
||||
```
|
||||
|
||||
3. You can also edit the /etc/avahi/avahi-daemon.conf file, remove the comment on the host-name setting line, and set the name there. By default, though, Avahi uses the system provided host name, so you **shouldn’t** need this method.
|
||||
|
||||
Next, restart the Avahi daemon so it picks up changes:
|
||||
```
|
||||
$ sudo systemctl restart avahi-daemon.service
|
||||
|
||||
```
|
||||
|
||||
Then set your other box properly:
|
||||
```
|
||||
$ hostnamectl set-hostname pollux
|
||||
$ sudo systemctl restart avahi-daemon.service
|
||||
|
||||
```
|
||||
|
||||
As long as your network router is not disallowing mDNS traffic, you should now be able to login to castor and ping the other box. You should use the default .local domain name so resolution works correctly:
|
||||
```
|
||||
$ ping pollux.local
|
||||
PING pollux.local (192.168.0.1) 56(84) bytes of data.
|
||||
64 bytes from 192.168.0.1 (192.168.0.1): icmp_seq=1 ttl=64 time=3.17 ms
|
||||
64 bytes from 192.168.0.1 (192.168.0.1): icmp_seq=2 ttl=64 time=1.24 ms
|
||||
...
|
||||
|
||||
```
|
||||
|
||||
The same trick should also work from pollux if you ping castor.local. It’s much more convenient now to access your systems around the network!
|
||||
|
||||
Moreover, don’t be surprised if your router advertises services. Modern WiFi and wired routers often provide these services to make life easier for consumers.
|
||||
|
||||
This process works for most systems. However, if you run into trouble, use avahi-browse and other tools from the avahi-tools package to see what services are available.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/find-systems-easily-lan-mdns/
|
||||
|
||||
作者:[Paul W. Frields][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://fedoramagazine.org/author/pfrields/
|
||||
[1]: https://fedoramagazine.org/set-hostname-fedora/
|
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,108 @@
|
||||
使用 mDNS 在局域网中轻松发现系统
|
||||
======
|
||||
|
||||
![](https://fedoramagazine.org/wp-content/uploads/2018/09/mDNS-816x345.jpg)
|
||||
|
||||
多播 DNS 或 mDNS 允许系统通过在广播查询局域网中的其他资源。Fedora 用户经常在没有复杂名称服务的路由器上拥有多个 Linux 系统。在这种情况下,mDNS 允许你按名称与多个系统通信 - 多数情况下不用路由器。你也不必在所有本地系统上同步类似 /etc/hosts 之类的文件。本文介绍如何设置它。
|
||||
|
||||
mDNS 是一个零配置网络服务,它已经诞生了很长一段时间。Fedora 将 Avahi (包含 mDNS 的零配置系统)作为工作站的一部分。 (mDNS 也是 Bonjour 的一部分,可在 Mac OS 上找到。)
|
||||
|
||||
本文假设你有两个系统运行受支持的 Fedora 版本(27 或 28)。它们的主机名是 castor 和 pollux。
|
||||
|
||||
### 安装包
|
||||
|
||||
确保系统上安装了 nss-mdns 和 avahi 软件包。你可能是不同的版本,这也没问题:
|
||||
```
|
||||
$ rpm -q nss-mdns avahi
|
||||
nss-mdns-0.14.1-1.fc28.x86_64
|
||||
avahi-0.7-13.fc28.x86_64
|
||||
|
||||
```
|
||||
|
||||
Fedora Workstation 默认提供这两个包。如果不存在,请安装它们:
|
||||
```
|
||||
$ sudo dnf install nss-mdns avahi
|
||||
|
||||
```
|
||||
|
||||
确保 avahi-daemon.service 单元已启用并正在运行。同样,这是 Fedora Workstation 的默认设置。
|
||||
```
|
||||
$ sudo systemctl enable --now avahi-daemon.service
|
||||
|
||||
```
|
||||
|
||||
虽然是可选的,但你可能还需要安装 avahi-tools 软件包。该软件包包括许多方便的程序,用于检查系统上的零配置服务的工作情况。使用这个 sudo 命令:
|
||||
```
|
||||
$ sudo dnf install avahi-tools
|
||||
|
||||
```
|
||||
|
||||
/etc/nsswitch.conf 控制系统使用哪个服务用于解析,以及它们的顺序。你应该在那个文件中看到这样的一行:
|
||||
```
|
||||
hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname
|
||||
|
||||
```
|
||||
|
||||
注意命令 mdns4_minimal [NOTFOUND=return]。它们告诉你的系统使用多播 DNS 解析程序将主机名解析为 IP 地址。即使该服务有效,如果名称无法解析,也会尝试其余服务。
|
||||
|
||||
如果你没有看到与此类似的配置,则可以对其进行编辑(以 root 用户身份)。但是,nss-mdns 包会为你处理此问题。如果你对自己编辑它感到不舒服,请删除并重新安装该软件包以修复该文件。
|
||||
|
||||
在**两个系统**中执行同样的步骤 。
|
||||
|
||||
### 设置主机名并测试
|
||||
|
||||
现在你已完成常见的配置工作,请使用以下方法之一设置每个主机的名称:
|
||||
|
||||
1. 如果你正在使用 Fedora Workstation,[你可以使用这个步骤][1]。
|
||||
|
||||
2. 如果没有,请使用 hostnamectl 来做。在第一台机器上这么做:
|
||||
```
|
||||
$ hostnamectl set-hostname castor
|
||||
|
||||
```
|
||||
|
||||
3. 你还可以编辑 /etc/avahi/avahi-daemon.conf,删除主机名设置行上的注释,并在那里设置名称。但是,默认情况下,Avahi 使用系统提供的主机名,因此你**不应该**需要此方法。
|
||||
|
||||
接下来,重启 Avahi 守护进程,以便它接收更改:
|
||||
```
|
||||
$ sudo systemctl restart avahi-daemon.service
|
||||
|
||||
```
|
||||
|
||||
然后正确设置另一台机器:
|
||||
```
|
||||
$ hostnamectl set-hostname pollux
|
||||
$ sudo systemctl restart avahi-daemon.service
|
||||
|
||||
```
|
||||
|
||||
只要你的路由器没有禁止 mDNS 流量,你现在应该能够登录到 castor 并 ping 通另一台机器。你应该使用默认的 .local 域名,以便解析正常工作:
|
||||
```
|
||||
$ ping pollux.local
|
||||
PING pollux.local (192.168.0.1) 56(84) bytes of data.
|
||||
64 bytes from 192.168.0.1 (192.168.0.1): icmp_seq=1 ttl=64 time=3.17 ms
|
||||
64 bytes from 192.168.0.1 (192.168.0.1): icmp_seq=2 ttl=64 time=1.24 ms
|
||||
...
|
||||
|
||||
```
|
||||
|
||||
如果你在 pollux ping castor.local,同样的技巧也适用 。现在在网络中访问你的系统更方便了!
|
||||
|
||||
此外,如果你的路由器宣传这个服务,请不要感到惊讶。现代 WiFi 和有线路由器通常提供这些服务,以使消费者的生活更轻松。
|
||||
|
||||
此过程适用于大多数系统。但是,如果遇到麻烦,请使用 avahi-browse 和 avahi-tools 软件包中的其他工具来查看可用的服务。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://fedoramagazine.org/find-systems-easily-lan-mdns/
|
||||
|
||||
作者:[Paul W. Frields][a]
|
||||
选题:[lujun9972](https://github.com/lujun9972)
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://fedoramagazine.org/author/pfrields/
|
||||
[1]: https://fedoramagazine.org/set-hostname-fedora/
|
Loading…
Reference in New Issue
Block a user