Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2021-01-15 19:47:50 +08:00
commit c4294704ad
16 changed files with 936 additions and 550 deletions

View File

@ -0,0 +1,27 @@
name: LCTT Article Checker
on:
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
env:
TRAVIS_REPO_SLUG: ${{ github.repository }}
TRAVIS_BRANCH: master
TRAVIS_PULL_REQUEST: ${{ github.event.number }}
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
steps:
- name: Set ENV variables
run: |
echo "::set-env name=TRAVIS_BRANCH::${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')}"
echo "::set-env name=TRAVIS_EVENT_TYPE::$(if [ "schedule" == "${{ github.event_name }}" ]; then echo "cron"; else echo "${{ github.event_name }}"; fi)"
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: "checkout master branch & return to pull request branch"
run: CURRENT=$(echo ${{github.ref}} | sed "s|refs/|refs/remotes/|") && git checkout master && git checkout $CURRENT
if: ${{ github.event_name == 'pull_request' }}
- name: run check
if: ${{ github.event_name == 'pull_request' }}
run: sh ./scripts/check.sh;

View File

@ -1,27 +0,0 @@
language: minimal
install:
- sudo apt-get install jq
- git clone --depth=1 -b gh-pages https://github.com/LCTT/TranslateProject/ build && rm -rf build/.git
script:
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then sh ./scripts/check.sh; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sh ./scripts/badge.sh; fi'
- 'if [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then sh ./scripts/status.sh; fi'
branches:
only:
- master
# - status
except:
- gh-pages
git:
submodules: false
depth: false
deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN
local_dir: build
on:
branch:
- master
# - status

View File

@ -1,29 +1,29 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-13016-1.html)
[#]: subject: (My 3 favorite open source productivity apps)
[#]: via: (https://opensource.com/article/21/1/open-source-productivity-apps)
[#]: author: (Taz Brown https://opensource.com/users/heronthecli)
我最喜欢的 3 个开源生产力应用
======
简化你的敏捷工作流程,提高你的工作效率。
![Working on a team, busy worklife][1]
> 简化你的敏捷工作流程,提高你的工作效率。
![](https://img.linux.net.cn/data/attachment/album/202101/14/215039op8zl611f8p76vrf.jpg)
生产力应用确实可以让你的工作流程变得更加轻松。在本文中,我将分享一些我用来简化工作流程、提高整体生产力的开源应用。本文中所有的生产力应用都是免费的 Linux 生产力应用。
### Tomboy/Gnote
[Tomboy][2] 是一款可以在 Linux、Windows 和 macOS 上使用的简单记事本应用。它是 GNU LGPLv2 下的开源软件。
[Tomboy][2] 是一款可以在 Linux、Windows 和 macOS 上使用的简单记事本应用。它是 GNU LGPLv2 下许可的开源软件。
Tomboy 使用起来非常简单。你写下一张纸条,选择是否将它贴在桌面上,完成后就可以删除它。
![Tomboy and Gnote][3]
Tonya "Taz" Brown, [CC BY-SA 4.0][4]
它(以及它的克隆版 [Gnote][5]是一个很好的快速记笔记的小程序。很多时候当我在做某件事情的时候会有一些想法或思路想要回忆。Tomboy 可以让我快速创建一个笔记,在我忘记之前把我的想法记下来。然后我就可以把这些想法转移到一个更长久的地方。
### Joplin
@ -32,11 +32,9 @@ Tomboy 使用起来非常简单。你写下一张纸条,选择是否将它贴
![Joplin][7]
[Joplin 仓库][8]提供的截图作者Tonya "Taz" Brown[CC BY-SA 4.0][4]
它可以使用 Dropbox、OneDrive、Nextcloud 等云同步服务进行同步。它很容易安装,可能就在你的 Linux 仓库里。当你在桌面上安装它时,它一个应用中实际包含了两个:你会得到一个标准的图形用户界面 GUI或者打开一个终端在那里使用 Joplin。
它可以使用 Dropbox、OneDrive、Nextcloud 等云同步服务进行同步。它很容易安装,可能就在你的 Linux 仓库里。当你在桌面上安装它时,它一个应用中实际包含了两个。你会得到一个标准的图形用户界面 GUI或者打开一个终端在那里使用 Joplin。
桌面有一个非常漂亮的界面。笔记被组织在笔记本中,这基本上使它们成为你的手册页。而且因为笔记是 Markdown 格式的,所以它们会被渲染,你可以实时编辑它们。我喜欢使用 Markdown因为它让我写笔记的速度很快。你也可以导出或导入 Joplin 笔记。
桌面版有一个非常漂亮的界面。笔记被组织在笔记本中,这基本上使它们成为你的手册页。而且因为笔记是 Markdown 格式的,所以它们会被渲染,你可以实时编辑它们。我喜欢使用 Markdown因为它让我写笔记的速度很快。你也可以导出或导入 Joplin 笔记。
### Evolution
@ -44,13 +42,10 @@ Tomboy 使用起来非常简单。你写下一张纸条,选择是否将它贴
![GNOME Evolution][11]
([GNOME][12], [CC BY-SA 4.0][4])
我在运行 Fedora 的台式电脑上使用它。它的效率很高,绝对能帮助我度过繁忙的一天。它让我能够使用 Linux 开展业务;我还能要求什么呢?
要在 Fedora 中使用它,打开一个终端并输入以下命令:
```
sudo dnf remove evolution
sudo dnf update
@ -73,7 +68,7 @@ via: https://opensource.com/article/21/1/open-source-productivity-apps
作者:[Taz Brown][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (bestony)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
@ -250,7 +250,7 @@ via: https://writing.kemitchell.com/2016/09/21/MIT-License-Line-by-Line.html
作者:[Kyle E. Mitchell][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[bestony](https://github.com/bestony)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,87 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Do Linux distributions still matter with containers?)
[#]: via: (https://opensource.com/article/19/2/linux-distributions-still-matter-containers)
[#]: author: (Scott McCarty https://opensource.com/users/fatherlinux)
Do Linux distributions still matter with containers?
======
There are two major trends in container builds: using a base image and building from scratch. Each has engineering tradeoffs.
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cube_innovation_process_block_container.png?itok=vkPYmSRQ)
Some people say Linux distributions no longer matter with containers. Alternative approaches, like distroless and scratch containers, seem to be all the rage. It appears we are considering and making technology decisions based more on fashion sense and immediate emotional gratification than thinking through the secondary effects of our choices. We should be asking questions like: How will these choices affect maintenance six months down the road? What are the engineering tradeoffs? How does this paradigm shift affect our build systems at scale?
It's frustrating to watch. If we forget that engineering is a zero-sum game with measurable tradeoffs—advantages and disadvantages, with costs and benefits of different approaches— we do ourselves a disservice, we do our employers a disservice, and we do our colleagues who will eventually maintain our code a disservice. Finally, we do all of the maintainers ([hail the maintainers!][1]) a disservice by not appreciating the work they do.
### Understanding the problem
To understand the problem, we have to investigate why we started using Linux distributions in the first place. I would group the reasons into two major buckets: kernels and other packages. Compiling kernels is actually fairly easy. Slackware and Gentoo (I still have a soft spot in my heart) taught us that.
On the other hand, the tremendous amount of development and runtime software that needs to be packaged for a usable Linux system can be daunting. Furthermore, the only way you can ensure that millions of permutations of packages can be installed and work together is by using the old paradigm: compile it and ship it together as a thing (i.e., a Linux distribution). So, why do Linux distributions compile kernels and all the packages together? Simple: to make sure things work together.
First, let's talk about kernels. The kernel is special. Booting a Linux system without a compiled kernel is a bit of a challenge. It's the core of a Linux operating system, and it's the first thing we rely on when a system boots. Kernels have a lot of different configuration options when they're being compiled that can have a tremendous effect on how hardware and software run on one. A secondary problem in this bucket is that system software, like compilers, C libraries, and interpreters, must be tuned for the options you built into the kernel. Gentoo taught us this in a visceral way, which turned everyone into a miniature distribution maintainer.
Embarrassingly (because I have worked with containers for the last five years), I must admit that I have compiled kernels quite recently. I had to get nested KVM working on RHEL 7 so that I could run [OpenShift on OpenStack][2] virtual machines, in a KVM virtual machine on my laptop, as well as [our Container Development Kit (CDK][3]). #justsayin Suffice to say, I fired RHEL7 up on a brand new 4.X kernel at the time. Like any good sysadmin, I was a little worried that I missed some important configuration options and patches. And, of course, I had missed some things. Sleep mode stopped working right, my docking station stopped working right, and there were numerous other small, random errors. But it did work well enough for a live demo of OpenShift on OpenStack, in a single KVM virtual machine on my laptop. Come on, that's kinda' fun, right? But I digress…
Now, let's talk about all the other packages. While the kernel and associated system software can be tricky to compile, the much, much bigger problem from a workload perspective is compiling thousands and thousands of packages to give us a useable Linux system. Each package requires subject matter expertise. Some pieces of software require running only three commands: **./configure** , **make** , and **make install**. Others require a lot of subject matter expertise ranging from adding users and configuring specific defaults in **etc** to running post-install scripts and adding systemd unit files. The set of skills necessary for the thousands of different pieces of software you might use is daunting for any single person. But, if you want a usable system with the ability to try new software whenever you want, you have to learn how to compile and install the new software before you can even begin to learn to use it. That's Linux without a Linux distribution. That's the engineering problem you are agreeing to when you forgo a Linux distribution.
The point is that you have to build everything together to ensure it works together with any sane level of reliability, and it takes a ton of knowledge to build a usable cohort of packages. This is more knowledge than any single developer or sysadmin is ever going to reasonably learn and retain. Every problem I described applies to your [container host][4] (kernel and system software) and [container image][5] (system software and all other packages)—notice the overlap; there are compilers, C libraries, interpreters, and JVMs in the container image, too.
### The solution
You already know this, but Linux distributions are the solution. Stop reading and send your nearest package maintainer (again, hail the maintainers!) an e-card (wait, did I just give my age away?). Seriously though, these people do a ton of work, and it's really underappreciated. Kubernetes, Istio, Prometheus, and Knative: I am looking at you. Your time is coming too, when you will be in maintenance mode, overused, and underappreciated. I will be writing this same article again, probably about Kubernetes, in about seven to 10 years.
### First principles with container builds
There are tradeoffs to building from scratch and building from base images.
#### Building from base images
Building from base images has the advantage that most build operations are nothing more than a package install or update. It relies on a ton of work done by package maintainers in a Linux distribution. It also has the advantage that a patching event six months—or even 10 years—from now (with RHEL) is an operations/systems administrator event (yum update), not a developer event (that requires picking through code to figure out why some function argument no longer works).
Let's double-click on that a bit. Application code relies on a lot of libraries ranging from JSON munging libraries to object-relational mappers. Unlike the Linux kernel and Glibc, these types of libraries change with very little regard to breaking API compatibility. That means that three years from now your patching event likely becomes a code-changing event, not a yum update event. Got it, let that sink in. Developers, you are getting paged at 2 AM if the security team can't find a firewall hack to block the exploit.
Building from a base image is not perfect; there are disadvantages, like the size of all the dependencies that get dragged in. This will almost always make your container images larger than building from scratch. Another disadvantage is you will not always have access to the latest upstream code. This can be frustrating for developers, especially when you just want to get something out the door, but not as frustrating as being paged to look at a library you haven't thought about in three years that the upstream maintainers have been changing the whole time.
If you are a web developer and rolling your eyes at me, I have one word for you: DevOps. That means you are carrying a pager, my friend.
#### Building from scratch
Scratch builds have the advantage of being really small. When you don't rely on a Linux distribution in the container, you have a lot of control, which means you can customize everything for your needs. This is a best-of-breed model, and it's valid in certain use cases. Another advantage is you have access to the latest packages. You don't have to wait for a Linux distro to update anything. You are in control, so you choose when to spend the engineering work to incorporate new software.
Remember, there is a cost to controlling everything. Often, updating to new libraries with new features drags in unwanted API changes, which means fixing incompatibilities in code (in other words, [shaving yaks][6]). Shaving yaks at 2 AM when the application doesn't work is not fun. Luckily, with containers, you can roll back and shave the yaks the next business day, but it will still eat into your time for delivering new value to the business, new features to your applications. Welcome to the life of a sysadmin.
OK, that said, there are times that building from scratch makes sense. I will completely concede that statically compiled Golang programs and C programs are two decent candidates for scratch/distroless builds. With these types of programs, every container build is a compile event. You still have to worry about API breakage three years from now, but if you are a Golang shop, you should have the skillset to fix things over time.
### Conclusion
Basically, Linux distributions do a ton of work to save you time—on a regular Linux system or with containers. The knowledge that maintainers have is tremendous and leveraged so much without really being appreciated. The adoption of containers has made the problem even worse because it's even further abstracted.
With container hosts, a Linux distribution offers you access to a wide hardware ecosystem, ranging from tiny ARM systems, to giant 128 CPU x86 boxes, to cloud-provider VMs. They offer working container engines and container runtimes out of the box, so you can just fire up your containers and let somebody else worry about making things work.
For container images, Linux distributions offer you easy access to a ton of software for your projects. Even when you build from scratch, you will likely look at how a package maintainer built and shipped things—a good artist is a good thief—so, don't undervalue this work.
So, thank you to all of the maintainers in Fedora, RHEL (Frantisek, you are my hero), Debian, Gentoo, and every other Linux distribution. I appreciate the work you do, even though I am a "container guy."
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/2/linux-distributions-still-matter-containers
作者:[Scott McCarty][a]
选题:[lujun9972][b]
译者:[译者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/fatherlinux
[b]: https://github.com/lujun9972
[1]: https://aeon.co/essays/innovation-is-overvalued-maintenance-often-matters-more
[2]: https://blog.openshift.com/openshift-on-openstack-delivering-applications-better-together/
[3]: https://developers.redhat.com/blog/2018/02/13/red-hat-cdk-nested-kvm/
[4]: https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction/#h.8tyd9p17othl
[5]: https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction/#h.dqlu6589ootw
[6]: https://en.wiktionary.org/wiki/yak_shaving

View File

@ -1,172 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (Chao-zhi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (5 Streaming Audio Players for Linux)
[#]: via: (https://www.linux.com/blog/2019/2/5-streaming-audio-players-linux)
[#]: author: (Jack Wallen https://www.linux.com/users/jlwallen)
5 Streaming Audio Players for Linux
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/music-main.png?itok=bTxfvadR)
As I work, throughout the day, music is always playing in the background. Most often, that music is in the form of vinyl spinning on a turntable. But when Im not in purist mode, Ill opt to listen to audio by way of a streaming app. Naturally, Im on the Linux platform, so the only tools I have at my disposal are those that play well on my operating system of choice. Fortunately, plenty of options exist for those who want to stream audio to their Linux desktops.
In fact, Linux offers a number of solid offerings for music streaming, and Ill highlight five of my favorite tools for this task. A word of warning, not all of these players are open source. But if youre okay running a proprietary app on your open source desktop, you have some really powerful options. Lets take a look at whats available.
### Spotify
Spotify for Linux isnt some dumb-downed, half-baked app that crashes every other time you open it, and doesnt offer the full-range of features found on the macOS and Windows equivalent. In fact, the Linux version of Spotify is exactly the same as youll find on other platforms. With the Spotify streaming client you can listen to music and podcasts, create playlists, discover new artists, and so much more. And the Spotify interface (Figure 1) is quite easy to navigate and use.
![Spotify][2]
Figure 1: The Spotify interface makes it easy to find new music and old favorites.
[Used with permission][3]
You can install Spotify either using snap (with the command sudo snap install spotify), or from the official repository, with the following commands:
* sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 931FF8E79F0876134EDDBDCCA87FF9DF48BF1C90
* sudo echo deb <http://repository.spotify.com> stable non-free | sudo tee /etc/apt/sources.list.d/spotify.list
* sudo apt-get update
* sudo apt-get install spotify-client
Once installed, youll want to log into your Spotify account, so you can start streaming all of the great music to help motivate you to get your work done. If you have Spotify installed on other devices (and logged into the same account), you can dictate to which device the music should stream (by clicking the Devices Available icon near the bottom right corner of the Spotify window).
### Clementine
Clementine one of the best music players available to the Linux platform. Clementine not only allows user to play locally stored music, but to connect to numerous streaming audio services, such as:
* Amazon Cloud Drive
* Box
* Dropbox
* Icecast
* Jamendo
* Magnatune
* RockRadio.com
* Radiotunes.com
* SomaFM
* SoundCloud
* Spotify
* Subsonic
* Vk.com
* Or internet radio streams
There are two caveats to using Clementine. The first is you must be using the most recent version (as the build available in some repositories is out of date and wont install the necessary streaming plugins). Second, even with the most recent build, some streaming services wont function as expected. For example, with Spotify, youll only have available to you the Top Tracks (and not your playlist … or the ability to search for songs).
With Clementine Internet radio streaming, youll find musicians and bands youve never heard of (Figure 2), and plenty of them to tune into.
![Clementine][5]
Figure 2: Clementine Internet radio is a great way to find new music.
[Used with permission][3]
### Odio
Odio is a cross-platform, proprietary app (available for Linux, MacOS, and Windows) that allows you to stream internet music stations of all genres. Radio stations are curated from [www.radio-browser.info][6] and the app itself does an incredible job of presenting the streams for you (Figure 3).
![Odio][8]
Figure 3: The Odio interface is one of the best youll find.
[Used with permission][3]
Odio makes it very easy to find unique Internet radio stations and even add those you find and enjoy to your library. Currently, the only way to install Odio on Linux is via Snap. If your distribution supports snap packages, install this streaming app with the command:
sudo snap install odio
Once installed, you can open the app and start using it. There is no need to log into (or create) an account. Odio is very limited in its settings. In fact, it only offers the choice between a dark or light theme in the settings window. However, as limited as it might be, Odio is one of your best bets for playing Internet radio on Linux.
Streamtuner2 is an outstanding Internet radio station GUI tool. With it you can stream music from the likes of:
* Internet radio stations
* Jameno
* MyOggRadio
* Shoutcast.com
* SurfMusic
* TuneIn
* Xiph.org
* YouTube
### StreamTuner2
Streamtuner2 offers a nice (if not slightly outdated) interface, that makes it quite easy to find and stream your favorite music. The one caveat with StreamTuner2 is that its really just a GUI for finding the streams you want to hear. When you find a station, double-click on it to open the app associated with the stream. That means you must have the necessary apps installed, in order for the streams to play. If you dont have the proper apps, you cant play the streams. Because of this, youll spend a good amount of time figuring out what apps to install for certain streams (Figure 4).
![Streamtuner2][10]
Figure 4: Configuring Streamtuner2 isnt for the faint of heart.
[Used with permission][3]
### VLC
VLC has been, for a very long time, dubbed the best media playback tool for Linux. Thats with good reason, as it can play just about anything you throw at it. Included in that list is streaming radio stations. Although you wont find VLC connecting to the likes of Spotify, you can head over to Internet-Radio, click on a playlist and have VLC open it without a problem. And considering how many internet radio stations are available at the moment, you wont have any problem finding music to suit your tastes. VLC also includes tools like visualizers, equalizers (Figure 5), and more.
![VLC ][12]
Figure 5: The VLC visualizer and equalizer features in action.
[Used with permission][3]
The only caveat to VLC is that you do have to have a URL for the Internet Radio you wish you hear, as the tool itself doesnt curate. But with those links in hand, you wont find a better media player than VLC.
### Always More Where That Came From
If one of these five tools doesnt fit your needs, I suggest you open your distributions app store and search for one that will. There are plenty of tools to make streaming music, podcasts, and more not only possible on Linux, but easy.
Learn more about Linux through the free ["Introduction to Linux" ][13] course from The Linux Foundation and edX.
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/2019/2/5-streaming-audio-players-linux
作者:[Jack Wallen][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linux.com/users/jlwallen
[b]: https://github.com/lujun9972
[2]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/spotify_0.jpg?itok=8-Ym-R61 (Spotify)
[3]: https://www.linux.com/licenses/category/used-permission
[5]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/clementine_0.jpg?itok=5oODJO3b (Clementine)
[6]: http://www.radio-browser.info
[8]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/odio.jpg?itok=sNPTSS3c (Odio)
[10]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/streamtuner2.jpg?itok=1MSbafWj (Streamtuner2)
[12]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/vlc_0.jpg?itok=QEOsq7Ii (VLC )
[13]: https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (ShuyRoy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
@ -54,7 +54,7 @@ via: https://www.networkworld.com/article/3387117/intel-formally-launches-optane
作者:[Andy Patrizio][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[RiaXu](https://github.com/ShuyRoy)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,195 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (stevenzdg988)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Learn Python by creating a video game)
[#]: via: (https://opensource.com/article/20/10/learn-python-ebook)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Learn Python by creating a video game
======
Get to know Python the fun way using the step-by-step instructions in
our new eBook.
![Arcade games][1]
Python is one of the most popular programming languages out there. Whether you want to learn it for work or for fun, it's a powerful and useful language for any purpose. You can create applications to help you with daily tasks, fun games you and your friends can play, scripts to process data, applications to generate or parse information, and much more.
No matter what you intend to do with a programming language, we think it's more fun to learn by creating a game than by crunching numbers or transforming strings. And if you're completely new to programming, it's a lot easier to understand why you have to do something in code when you can see the code working in a familiar setting like a video game.
You may not select [Python][2] as the best programming language available (everyone has their own answer for that), but it is a relatively non-intimidating one. Python can use a lot of words (such as `is` and `is not`) instead of symbols (such as `=` and `!=`). It also manages many low-level tasks so that you usually don't have to worry about things like data types and garbage collection. This generally means you can get started coding without the upfront frustration that a complex language like [C][3] or [Java][4] presents.
To help you learn Python, we wrote an eBook showing how to create a platformer video game with it. Step through the lessons to learn Python while building a video game. As an additional benefit, you'll also learn about programming logic, syntax, operators, and more. You can see immediate results as you learn, so everything you learn is promptly reinforced.
### Python in a minute
Python is a general-purpose language, meaning it (like most languages) provides functions to do simple "tricks" with numbers and letters. Linux users already have Python installed. Mac users have an old version of Python, but you can [install the latest version][5] from the Python.org website. Windows users can learn to install Python from this [install Python on Windows][6] article.
Once installed, you can start an interactive Python shell and do math:
```
$ python3
&gt;&gt;&gt; 5+6
11
&gt;&gt;&gt; 11/2
5.5
&gt;&gt;&gt; 11//2
5
&gt;&gt;&gt; 11%2
1
```
As you can see from this sample, there's some special notation required, but it's mostly familiar to anyone comfortable with math. Maybe you're not a numbers person and prefer letters:
```
$ python3
&gt;&gt;&gt; string = "hello world"
&gt;&gt;&gt; print(string)
hello world
&gt;&gt;&gt; print(string.upper())
HELLO WORLD
&gt;&gt;&gt; print(string[0])
h
&gt;&gt;&gt; print(string[1])
e
&gt;&gt;&gt; print(string[2])
l
&gt;&gt;&gt; print(string[3])
l
&gt;&gt;&gt; print(string[4])
o
```
Again, there's special notation for relatively basic tasks, but even without an explanation, you probably already detected that the `[0]` and `[1]` notation enables you to "slice" data and `print` presents data on your screen.
### Pygame in five minutes
If you want to create a video game or anything beyond a basic calculator with Python alone, it could take a lot of study, work, and time. Luckily, Python's been around for a couple of decades, so people have developed libraries of code to help you perform typical programming feats with (comparatively) very little effort. [Pygame][7] is a set of code modules designed for creating video games. It's [not the only such library][8], but it's the oldest (for better and for worse), so there's a lot of documentation and examples online.
Start by learning the [recommended Python virtual environment workflow][9]:
```
$ python3 -m venv mycode/venv
$ cd mycode
$ source ./venv/bin/activate
(venv)$
```
Once you're in a virtual environment, you can safely install Pygame into your project folder:
```
(venv)$ echo "pygame" &gt;&gt; requirements.txt
(venv)$ python -m pip install -r requirements.txt
[...] Installing collected packages: pygame
Successfully installed pygame-x.y.z
```
Now that you have Pygame installed, you can create a simple demo application. It's easier than you think. Python can do what's called _object-oriented programming_ (OOP), which is a fancy computer science term to describe when code is structured as if you were creating physical objects with code. Programmers aren't deluded, though. They know they're not really making physical objects when they code, but it can help to imagine it that way because then you understand the limits of your programmed world.
For instance, if you were stranded on a desert island and wanted a coffee cup to appear, you'd have to harvest some clay, fashion a cup, and bake it. If you were very clever, you'll create a mold first so that whenever you want another cup, you can quickly create a new one from your template. Even though each cup came from the same template, they would be physically independent: should one break, you still have others. And you could make each coffee cup appear unique by adding color or etchings.
In Pygame, and in many programming tasks, you use similar logic. A thing can't appear in your programmed world until you define it. Here's how to make a coffee cup appear in a Python and Pygame program.
#### Object-oriented programming with Pygame
Create a new file called `main.py` and enter this code to initiate the Pygame module and to use a Pygame template to create a window:
```
import pygame
pygame.init()
screen = pygame.display.set_mode((960,720))
```
Just as you might use a template to create an object in real life, you use a template provided by Pygame to create a _sprite_ (which is Pygame's term for a visual game object). In object-oriented programming, a _class_ represents a template for an object. Type this code into your document:
```
class Cup(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        # image
        img = pygame.image.load('coffeecup.png').convert()
        self.image = img
        # volume
        self.rect = self.image.get_rect()
        self.rect.x = 10
        self.rect.y = 10
```
This code block uses Pygame's `sprite` template to design a coffee cup sprite. Your coffee cup sprite has an image because of `self.image`, while `self.rect` gives it volume (width and height). These are attributes Pygame expects a sprite to possess, but if you were creating a playable video game, you could give it any other attribute you want, such as health points and a score.
All you've done so far is create a window and the _template_ for a coffee cup. Your game doesn't actually _make_ a cup yet.
The last part of your code must use your template to generate a cup and add it to your game world. As you may know, computers are very fast, so technically, the code you've created so far would only run for a millisecond or so. When writing a graphical computer application, you must force the computer to remain open whether or not it thinks it has completed the prescribed tasks. Programmers do this with an _infinite loop_, which in Python is represented by the instruction `while True` (True is always true, so the loop never ends).
An infinite loop ensures your application stays open long enough for the computer user to see and use the application:
```
cup = Cup()
while True:
    pygame.display.update()
    screen.blit(cup.image, cup.rect)
```
This code sample creates a cup from your template `Cup` and then updates the display using a Pygame function. Finally, it draws the cup's image within its bounding box using Pygame's `blit` function.
#### Get a graphic
Before you can run the code successfully, you need a graphic for your coffee cup. You can find lots of [Creative Commons][10] coffee cup graphics on [FreeSVG.org][11]. I used [this one][12]. Save the graphic in your project directory, and call it `coffeecup.png`.
#### Run the game
Launch your application:
```
`(venv)$ python ./main.py`
```
![Coffee cup in Pygame][13]
(Seth Kenlon, [CC BY-SA 4.0][14])
### [Download the Python gaming eBook][15]
Pygame is a powerful framework, and there's a lot more you can do with it than just draw coffee cups on your screen. [Download our free eBook][15] to get to know Pygame—and Python itself—better.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/10/learn-python-ebook
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者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/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/arcade_game_gaming.jpg?itok=84Rjk_32 (Arcade games)
[2]: https://www.python.org/
[3]: https://opensource.com/article/20/8/c-programming-cheat-sheet
[4]: https://opensource.com/resources/java
[5]: https://www.python.org/downloads/mac-osx
[6]: https://opensource.com/article/19/8/how-install-python-windows
[7]: https://www.pygame.org/news
[8]: https://opensource.com/article/18/4/easy-2d-game-creation-python-and-arcade
[9]: https://opensource.com/article/20/9/venv-python
[10]: https://opensource.com/article/20/1/what-creative-commons
[11]: http://freesvg.org
[12]: https://freesvg.org/1548870028
[13]: https://opensource.com/sites/default/files/uploads/pygame-cup.jpg (Coffee cup in Pygame)
[14]: https://creativecommons.org/licenses/by-sa/4.0/
[15]: https://opensource.com/downloads/python-gaming-ebook

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,234 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Cross-compiling made easy with Golang)
[#]: via: (https://opensource.com/article/21/1/go-cross-compiling)
[#]: author: (Gaurav Kamathe https://opensource.com/users/gkamathe)
Cross-compiling made easy with Golang
======
I learned about Go's cross-compilation capabilities by stepping out of
my comfort zone.
![Person using a laptop][1]
I work with multiple servers with various architectures (e.g., Intel, AMD, Arm, etc.) when I'm testing software on Linux. Once I've [provisioned a Linux box][2] and the server meets my testing needs, I still have a number of steps to do:
1. Download and install prerequisite software.
2. Verify whether new test packages for the software I'm testing are available on the build server.
3. Get and set the required yum repos for the dependent software packages.
4. Download and install the new test packages (based on step #2).
5. Get and set up the required SSL certificates.
6. Set up the test environment, get the required Git repos, change configurations in files, restart daemons, etc.
7. Do anything else that needs to be done.
### Script it all away
These steps are so routine that it makes sense to automate them and save the script to a central location (like a file server) where I can download it when I need it. I did this by writing a 100120-line Bash shell script that does all the configuration for me (including error checks). The script simplifies my workflow by:
1. Provisioning a new Linux system (of the architecture under test)
2. Logging into the system and downloading the automated shell script from a central location
3. Running it to configure the system
4. Starting the testing
### Enter Go
I've wanted to learn [Golang][3] for a while, and converting my beloved shell script into a Go program seemed like a good project to help me get started. The syntax seemed fairly simple, and after trying out some test programs, I set out to advance my knowledge and become familiar with the Go standard library.
It took me a week to write the Go program on my laptop. I tested my program often on my go-to x86 server to weed our errors and improve the program. Everything worked fine.
I continued relying on my shell script until I finished the Go program. Then I pushed the binary onto a central file server so that every time I provisioned a new server, all I had to do was wget the binary, set the executable bit on, and run the binary. I was happy with the early results:
```
$ wget <http://file.example.com/\>&lt;myuser&gt;/bins/prepnode
$ chmod  +x ./prepnode
$ ./prepnode
```
### And then, an issue
The next week, I provisioned a fresh new server from the pool, as usual, downloaded the binary, set the executable bit, and ran the binary. It errored out—with a strange error:
```
$ ./prepnode
bash: ./prepnode: cannot execute binary file: Exec format error
$
```
At first, I thought maybe the executable bit was not set. However, it was set as expected:
```
$ ls -l prepnode
-rwxr-xr-x. 1 root root 2640529 Dec 16 05:43 prepnode
```
What happened? I didn't make any changes to the source code, the compilation threw no errors nor warnings, and it worked well the last time I ran it, so I looked more closely at the error message, `format error`.
I checked the binary's format, and everything looked OK:
```
$ file prepnode
prepnode: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
```
I quickly ran the following command to identify the architecture of the test server I provisioned and where the binary was trying to run. It was Arm64 architecture, but the binary I compiled (on my x86 laptop) was generating an x86-64 format binary:
```
$ uname -m
aarch64
```
### Compilation 101 for scripting folks
Until then, I had never accounted for this scenario (although I knew about it). I primarily work on scripting languages (usually Python) coupled with shell scripting. The Bash shell and the Python interpreter are available on most Linux servers of any architecture. Hence, everything had worked well before.
However, now I was dealing with a compiled language, Go, which produces an executable binary. The compiled binary consists of [opcodes][4] or assembly instructions that are tied to a specific architecture. That's why I got the format error. Since the Arm64 CPU (where I ran the binary) could not interpret the binary's x86-64 instructions, it errored out. Previously, the shell and Python interpreter took care of the underlying opcodes or architecture-specific instructions for me.
### Cross-compiling with Go
I checked the Golang docs and discovered that to produce an Arm64 binary, all I had to do was set two environment variables when compiling the Go program before running the `go build` command.
`GOOS` refers to the operating system (Linux, Windows, BSD, etc.), while `GOARCH` refers to the architecture to build for.
```
`$ env GOOS=linux GOARCH=arm64 go build -o prepnode_arm64`
```
After building the program, I reran the `file` command, and this time it showed Arm AArch64 instead of the x86 it showed before. Therefore, I was able to build a binary for a different architecture than the one on my laptop:
```
$ file prepnode_arm64
prepnode_arm64: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped
```
I copied the binary onto the Arm server from my laptop. Now, running the binary (after setting the executable bit on) produced no errors:
```
$ ./prepnode_arm64  -h
Usage of ./prepnode_arm64:
  -c    Clean existing installation
  -n    Do not start test run (default true)
  -s    Use stage environment, default is qa
  -v    Enable verbose output
```
### What about other architectures?
x86 and Arm are two of the five architectures I test software on. I was worried that Go might not support the other ones, but that was not the case. You can find out which architectures Go supports with:
```
`$ go tool dist list`
```
Go supports a variety of platforms and operating systems, including:
* AIX
* Android
* Darwin
* Dragonfly
* FreeBSD
* Illumos
* JavaScript
* Linux
* NetBSD
* OpenBSD
* Plan 9
* Solaris
* Windows
To find the specific Linux architectures it supports, run:
```
`$ go tool dist list | grep linux`
```
As the output below shows, Go supports all of the architectures I use. Although x86_64 is not on the list, AMD64 is compatible with x86_64, so you can produce an AMD64 binary, and it will run fine on x86 architecture:
```
$ go tool dist list | grep linux
linux/386
linux/amd64
linux/arm
linux/arm64
linux/mips
linux/mips64
linux/mips64le
linux/mipsle
linux/ppc64
linux/ppc64le
linux/riscv64
linux/s390x
```
### Handling all architectures
Generatiing binaries for all of the architectures under my test is as simple as writing a tiny shell script from my x86 laptop:
```
#!/usr/bin/bash
archs=(amd64 arm64 ppc64le ppc64 s390x)
for arch in ${archs[@]}
do
        env GOOS=linux GOARCH=${arch} go build -o prepnode_${arch}
done
[/code] [code]
$ file prepnode_*
prepnode_amd64:   ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=y03MzCXoZERH-0EwAAYI/p909FDnk7xEUo2LdHIyo/V2ABa7X_rLkPNHaFqUQ6/5p_q8MZiR2WYkA5CzJiF, not stripped
prepnode_arm64:   ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, Go BuildID=q-H-CCtLv__jVOcdcOpA/CywRwDz9LN2Wk_fWeJHt/K4-3P5tU2mzlWJa0noGN/SEev9TJFyvHdKZnPaZgb, not stripped
prepnode_ppc64:   ELF 64-bit MSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), statically linked, Go BuildID=DMWfc1QwOGIq2hxEzL_u/UE-9CIvkIMeNC_ocW4ry/r-7NcMATXatoXJQz3yUO/xzfiDIBuUxbuiyaw5Goq, not stripped
prepnode_ppc64le: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), statically linked, Go BuildID=C6qCjxwO9s63FJKDrv3f/xCJa4E6LPVpEZqmbF6B4/Mu6T_OR-dx-vLavn1Gyq/AWR1pK1cLz9YzLSFt5eU, not stripped
prepnode_s390x:   ELF 64-bit MSB executable, IBM S/390, version 1 (SYSV), statically linked, Go BuildID=faC_HDe1_iVq2XhpPD3d/7TIv0rulE4RZybgJVmPz/o_SZW_0iS0EkJJZHANxx/zuZgo79Je7zAs3v6Lxuz, not stripped
```
Now, whenever I provision a new machine, I just run this wget command to download the binary for a specific architecture, set the executable bit on, and run the binary:
```
$ wget <http://file.domain.com/\>&lt;myuser&gt;/bins/prepnode_&lt;arch&gt;
$ chmod +x ./prepnode_&lt;arch&gt;
$ ./prepnode_&lt;arch&gt;
```
### But why?
You may be wondering why I didn't save all of this hassle by sticking to shell scripts or porting the program over to Python instead of a compiled language. All fair points. But then I wouldn't have learned about Go's cross-compilation capabilities and how programs work underneath the hood when they're executing on the CPU. In computing, there are always trade-offs to be considered, but never let them stop you from learning.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/1/go-cross-compiling
作者:[Gaurav Kamathe][a]
选题:[lujun9972][b]
译者:[译者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/gkamathe
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/laptop_screen_desk_work_chat_text.png?itok=UXqIDRDD (Person using a laptop)
[2]: https://opensource.com/article/20/12/linux-server
[3]: https://golang.org/
[4]: https://en.wikipedia.org/wiki/Opcode

View File

@ -0,0 +1,110 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Discover Fedora Kinoite: a Silverblue variant with the KDE Plasma desktop)
[#]: via: (https://fedoramagazine.org/discover-fedora-kinoite/)
[#]: author: (Timothée Ravier https://fedoramagazine.org/author/siosm/)
Discover Fedora Kinoite: a Silverblue variant with the KDE Plasma desktop
======
![][1]
Photo by [Jaakko Kemppainen][2] on [Unsplash][3]
Fedora Kinoite is an immutable desktop operating system featuring the [KDE Plasma desktop][4]. In short, Fedora Kinoite is like Fedora Silverblue but with KDE instead of GNOME. It is an emerging variant of Fedora, based on the same technologies as Fedora Silverblue (rpm-ostree, Flatpak, podman) and created exclusively from official RPM packages from Fedora.
### Fedora Kinoite is like Silverblue, but what is Silverblue?
From the [Fedora Silverblue documentation][5]:
> Fedora Silverblue is an immutable desktop operating system. It aims to be extremely stable and reliable. It also aims to be an excellent platform for developers and for those using container-focused workflows.
For more details about what makes Fedora Silverblue interesting, read the “[What is Fedora Silverblue?][6]” article previously published on Fedora Magazine. Everything in that article also applies to Fedora Kinoite.
### Fedora Kinoite status
Kinoite is not yet an official emerging edition of Fedora. But this is [in progress][7] and currently planned for Fedora 35. However, it is already usable! [Join us][8] if you want to help.
Kinoite is made from the same packages that are available in the Fedora repositories and that go into the classic Fedora KDE Plasma Spin, so it is as functional and stable as classic Fedora. Im also “eating my own dog food” as it is the only OS installed on the laptop that I am currently using to write this article.
However, be aware that Kinoite does not currently have graphical support for updates. You will need to be confortable with using the command line to manage updates, install Flatpaks, or overlay packages with rpm-ostree.
#### How to try Fedora Kinoite
As Kinoite is not yet an official Fedora edition, there is not a dedicated installer for it for now. To get started, [install Silverblue][9] and switch to Kinoite with the following commands:
```
# Add the temporary unofficial Kinoite remote
$ curl -O https://tim.siosm.fr/downloads/siosm_gpg.pub
$ sudo ostree remote add kinoite https://siosm.fr/kinoite/ --gpg-import siosm_gpg.pub
# Optional, only if you want to keep Silverblue available
$ sudo ostree admin pin 0
# Switch to Kinoite
$ sudo rpm-ostree rebase kinoite:fedora/33/x86_64/kinoite
# Reboot
$ sudo systemctl reboot
```
#### How to keep it up-to-date
Kinoite does not yet have graphical support for updates in Discover. Work is in progress to teach Discover how to manage an rpm-ostree system. Flatpak management mostly works with Discover but the command line is still the best option for now.
To update the system, use:
```
$ rpm-ostree update
```
To update Flatpaks, use:
```
$ flatpak update
```
### Status of KDE Apps Flatpaks
Just like Fedora Silverblue, Fedora Kinoite focuses on applications delivered as Flatpaks. Some non KDE applications are available in the Fedora Flatpak registry, but until this selection is expanded with KDE ones, your best bet is to look for them in [Flathub][10] (see all [KDE Apps on Flathub][11]). Be aware that applications on Flathub may include non-free or proprietary software. The KDE SIG is working on packaging KDE Apps [as Fedora provided Flatpaks][12] but this is not ready yet.
### Submitting bug reports
Report issues in the [Fedora KDE SIG issue tracker][13] or in the discussion thread at [discussion.fedoraproject.org][14].
### Other desktop variants
Although this project started with KDE, I have also already created variants for XFCE, Mate, Deepin, Pantheon, and LXQt. They are currently available from the same remote as Kinoite. Note that they will remain unofficial until someone steps up to maintain them officially in Fedora.
I have also created an additional smaller Base variant without any desktop environment. This allows you to overlay the lightweight window manager of your choice (i3, Sway, etc.). The same caveats as the ones for other desktop environments apply (currently unofficial and will need a maintainer).
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/discover-fedora-kinoite/
作者:[Timothée Ravier][a]
选题:[lujun9972][b]
译者:[译者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/siosm/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2021/01/kinoite-816x345.jpg
[2]: https://unsplash.com/@jaakkok?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[3]: https://unsplash.com/s/photos/crystal?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[4]: https://kde.org/plasma-desktop/
[5]: https://docs.fedoraproject.org/en-US/fedora-silverblue/
[6]: https://fedoramagazine.org/what-is-silverblue/
[7]: https://pagure.io/fedora-kde/SIG/issue/4
[8]: https://fedoraproject.org/wiki/SIGs/KDE
[9]: https://docs.fedoraproject.org/en-US/fedora-silverblue/installation/
[10]: https://flathub.org
[11]: https://flathub.org/apps/search/org.kde
[12]: https://pagure.io/fedora-kde/SIG/issue/13
[13]: https://pagure.io/fedora-kde/SIG
[14]: https://discussion.fedoraproject.org/t/kinoite-a-kde-and-now-xfce-version-of-fedora-silverblue/147

View File

@ -0,0 +1,67 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How I prioritize tasks on my to-do list)
[#]: via: (https://opensource.com/article/21/1/prioritize-tasks)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
How I prioritize tasks on my to-do list
======
Use the Eisenhower Matrix to better organize and prioritize your to-do
lists.
![Team checklist and to dos][1]
In prior years, this annual series covered individual apps. This year, we are looking at all-in-one solutions in addition to strategies to help in 2021. Welcome to day 4 of 21 Days of Productivity in 2021. In this article, I'll examine a strategy for prioritizing tasks on a to-do list. To find the open source tool that suits your routine, check out [this list][2]. 
It is easy to add things to a task or to-do list. Almost too easy, really. And once on the list, the challenge becomes figuring out what to do first. Do we do the thing at the top of the list? Is the top of the list the most important thing? How do we figure out what the most important thing is?
![To-do list][3]
To-do. Today? Tomorrow? Who knows? (Kevin Sonney, [CC BY-SA 4.0][4])
[Much like email][5], we can prioritize tasks based on a couple of things, and this lets us figure out what needs to be done first and what can wait until later.
I use a method commonly known as the _Eisenhower Matrix_ since it was taken from a quote by US President Dwight D. Eisenhower. Draw a box split horizontally and vertically. Label the columns "Urgent" and "Not Urgent," and the rows "Important" and "Not Important."
![Eisenhower matrix][6]
An Eisenhower Matrix. (Kevin Sonney, [CC BY-SA 4.0][4])
You can typically put all of the things on a to-do list in one of the boxes. But how do we know what to put where? Urgency and importance are often subjective. So the first step is to decide what is important to you. My family (including my pets), my work, and my hobbies are all important. If something on my to-do list isn't related to those three things, I can immediately put it into the "Not Important" row.
Urgency is a little more cut and dry. Is it something that needs to be done today or tomorrow? Then it is probably "Urgent." Does it have a deadline that is approaching, but there are days/weeks/months until that time, or perhaps it doesn't have a deadline at all? Certainly "Not Urgent."
Now we can translate the boxes into priorities. "Urgent/Important" is the highest priority (i.e., Priority 1) and needs to be done first. "Not Urgent/Important" comes next (Priority 2), then "Urgent/Not Important" (Priority 3), and finally "Not Urgent/Not Important" (Priority 4 or no priority at all).
Notice that "Urgent/Not Important" is third, not second. This is because people spend a lot of time on things that are important because they are urgent, not because they are _actually_ important. When I look at these, I ask myself some questions. Are these tasks that need to be done by me specifically? Are these tasks I can ask other people to do? Are they important and urgent for someone else? Does that change their importance for me? Maybe they need to be re-classified, or perhaps they are things I can ask someone else to do and remove them from my list.
![After prioritizing][7]
After prioritizing. (Kevin Sonney, [CC BY-SA 4.0][4])
There is a single question to ask about the items in the "Not Urgent/Not Important" box, and that is "Do these need to even be on my list at all?" In all honesty, we often clog up our to-do lists with things that are not urgent or important, and we can remove them from our list altogether. I know it is hard to admit that "This is never going to get done," but after I accept that, it is a relief to take that item off my list and not worry about it anymore.
After all that, it is pretty easy to look at my list and say, "This is what I need to work on now," and get it done, which is what my to-do list is for: Providing guidance and focus to my day.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/1/prioritize-tasks
作者:[Kevin Sonney][a]
选题:[lujun9972][b]
译者:[译者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/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/todo_checklist_team_metrics_report.png?itok=oB5uQbzf (Team checklist and to dos)
[2]: https://opensource.com/article/20/5/alternatives-list
[3]: https://opensource.com/sites/default/files/pictures/to-do-list.png (To-do list)
[4]: https://creativecommons.org/licenses/by-sa/4.0/
[5]: https://opensource.com/article/21/1/email-rules
[6]: https://opensource.com/sites/default/files/pictures/eisenhower-matrix.png (Eisenhower matrix)
[7]: https://opensource.com/sites/default/files/pictures/after-prioritizing.png (After prioritizing)

View File

@ -0,0 +1,89 @@
[#]: collector: (lujun9972)
[#]: translator: (Chao-zhi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Do Linux distributions still matter with containers?)
[#]: via: (https://opensource.com/article/19/2/linux-distributions-still-matter-containers)
[#]: author: (Scott McCarty https://opensource.com/users/fatherlinux)
容器开发仍然要考虑 Linux 发行版吗?
======
容器构建有两大趋势:使用基本镜像和从头开始构建。每个都有工程上的权衡。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/cube_innovation_process_block_container.png?itok=vkPYmSRQ)
有人说 Linux 发行版不再与容器有关。像 distroless 和 scratch containers 等可替代的方法,似乎是风靡一时。看来,我们在考虑和做出技术决策时,更多的是基于时尚感和即时的情感满足,而不是考虑我们选择的次要影响。我们应该问这样的问题:这些选择将如何影响未来六个月的维护?工程权衡是什么?这种范式转换如何影响我们的大规模构建系统?
这真让人沮丧。如果我们忘记了工程是一个零和游戏,有可测量的利弊权衡,有不同方法的成本和收益——我们伤害了我们自己,我们伤害了我们的雇主,我们伤害了我们的同事,他们最终将维护我们的代码。最后,我们所有的维护人员([向维护人员致敬!][1] )会因为他们所做的工作不被赞赏,而受到伤害。
### 理解问题所在
为了理解这个问题,我们必须首先研究为什么我们使用 Linux 发行版。我将把原因分为两大类内核和其他包。编译内核实际上相当容易。Slackware 和 Gentoo 我的小心脏还是有点害怕)教会了我们这一点。
另一方面,为了一个可用的 Linux 系统需要打包大量的开发软件和应用软件,这可能会让人望而生畏。此外,确保数百万个程序包可以一起安装和工作的唯一方法是使用旧的范例:即编译它并将它作为一个玩意(即 Linux 发行版)一起发布。那么,为什么 Linux 发行版要将内核和所有包一起编译呢?很简单:确保事情协调一致。
首先,我们来谈谈内核。内核很特别。在没有编译内核的情况下引导 Linux 系统有点困难。它是 Linux 操作系统的核心,也是我们在系统启动时首先依赖的。内核在编译时有很多不同的配置选项,这些选项会对硬件和软件如何在一个内核上运行产生巨大影响。这个 bucket 中的第二个问题是,系统软件(如编译器 、C 库和解释器必须针对内核中内置的选项进行调优。Gentoo 的 wiki 以一种发自内心的方式教我们这一点,它把每个人都变成了一个微型的开发版维护者。
令人尴尬的是(因为我在过去五年里一直在使用容器),我必须承认我最近编译过内核。我必须让嵌套的 KVM 在 RHEL7 上工作,这样我才能在笔记本电脑上的 KVM 虚拟机中运行 [OpenShift on OpenStack][2] 虚拟机,以及我的 [Container Development KitCDK][3])。我只想说,当时我在一个全新的 4.X 内核上启动了 RHEL7。和任何优秀的系统管理员一样我有点担心自己错过了一些重要的配置选项和补丁。当然我也的确错过了一些东西。比如睡眠模式停止正常工作我的扩展底座停止正常工作还有许多其他小的随机错误。但它在我的笔记本电脑上的一个 KVM 虚拟机上,对于 OpenStack 上的 OpenShift 的实时演示来说已经足够好了。来吧,这很有趣,对吧?但我离题了……
现在,我们来谈谈其他的软件包。虽然内核和相关的系统软件可能很难编译,但从工作负载的角度来看,更大的问题是编译成千上万的包,以提供一个可用的 Linux 系统。每个软件包都需要专业知识。有些软件只需要运行三个命令:**。/configure**、**make** 和 **make install**。另一些则需要大量的专业知识,从在 **etc** 中添加用户和配置特定的默认值到运行安装后脚本和添加 systemd 单元文件。对于任何一个人来说,调试好你可能用得到的成千上万种不同软件所需要的一套技能都是令人望而生畏的。但是,如果你想要一个可以随时尝试新软件的可用系统,你必须学会如何编译和安装新软件,然后才能开始学习使用它。这就是没有 Linux 发行版的 Linux。当您放弃使用 Linux 发行版时,那么你就得自己编译软件。
关键是,您必须将所有内容构建在一起,以确保它能够以任何合理的可靠性级别协同工作,而且构建一个可用的包队列需要大量的知识。这是任何一个开发人员或系统管理员都无法合理地学习和保留的知识。我描述的每个问题都适用于您的 [container host][4] 内核和系统软件)和 [container image][5] 系统软件和所有其他包)——请注意;在容器镜像中还包含有编译器 、C 库、解释器和 JVM。
### 解决方案
所以你也看到了,其实使用 Linux 发行版就是解决方案。不要再去阅读和发送给最新的包维护人员再次向维护人员致敬一张电子卡等等我是不是把我的年龄告诉别人了。但说真的这些人做了大量的工作这真的是被低估了。KubernetesIstioPrometheus还有 Knative我在看着你们。你们的时代要来了你们在维护模式下过渡操劳并且被低估。大约七到十年后我将再次写这篇文章可能是关于 Kubernetes 的。
### 容器构建的首要原则
从零开始构建和从基础镜像构建之间存在权衡。
#### 从基础镜像构建
从基本镜像构建的优点是,大多数构建操作只不过是安装或更新包。它依赖于 Linux 发行版中包维护人员所做的大量工作。它还有一个优点,即六个月甚至十年后的修补事件(使用 RHEL 是操作/系统管理员事件 yum update而不是开发人员事件这需要通过代码找出某些函数参数不再工作的原因
你想想,应用程序代码依赖于许多库,从 JSON mung 库到对象关系映射器。与 Linux 内核和 Glibc 不同,这些类型的库很少改变 API 兼容性。这意味着三年后您的修补事件可能会变成代码更改事件,而不是 yum 更新事件。因此让他自己深入下去吧。开发人员,如果安全团队找不到防火墙黑客来阻止攻击,您将在凌晨 2 点收到呼叫。
从基础镜像构建不是完美的;还有一些缺点,比如所有被拖入的依赖项的大小。这几乎总是会使容器镜像比从头开始构建的镜像更大。另一个缺点是您不总是能够访问最新的上游代码。这可能会让开发人员感到沮丧,尤其是当你只想使用依赖项中的一部分功能时,但是你仍然不得不将你更本用不着的东西一起打包带走,因为上游的维护人员一直在改变这个库。
如果你是一个 web 开发人员对我睁大眼睛我有一个词可以形容你DevOps。那意味着你带着寻呼机我的朋友。
#### Scratch 构建
Scratch 构建的优点是镜像非常小。当您不依赖容器中的 Linux 发行版时,您有很多控制权,这意味着您可以根据需要定制所有内容。这是一个同类最佳的模型,在某些用例中是很有效的。另一个优势是您可以访问最新的软件包。您不必等待 Linux 发行版更新任何内容。是你自己在控制,所以你自行选择什么时候去费功夫纳入新的软件。
记住,控制一切都是有代价的。通常,更新到具有新特性的新库会拖累不必要的 API 更改,这意味着修复代码中的不兼容(换句话说,这就像[给牦牛剪毛 ][6])。在凌晨 2 点应用程序不起作用的时候给牦牛剪毛是不好玩的。幸运的是,使用容器,您可以在下一个工作日回滚并给牦牛剪毛,但它仍会占用您为业务提供新价值、为应用程序提供新功能的时间。欢迎来到系统管理员的生活。
好吧,也就是说,有些时候,白手起家是有意义的。我完全承认,静态编译的 Golang 程序和 C 程序是 scratch/distorless 构建的两个不错的候选程序。对于这些类型的程序,每个容器构建都是一个编译事件。三年后你仍然需要担心 API 的损坏,但是如果你是一个 Golang 商店,你应该有能力随着时间的推移修复问题。
### 结论
基本上Linux 发行版做了大量工作来节省您在常规 Linux 系统或容器上的时间。维护人员所拥有的知识是巨大的,而且没有得到真正的赏识。容器的采用使得问题更加严重,因为它被进一步抽象了。
通过容器主机Linux 发行版可以让您访问广泛的硬件生态系统,从微型 ARM 系统到 128 核 CPU x86 巨型机箱,再到云提供商虚拟机。他们提供可工作的容器引擎和开箱即用的容器运行时间,所以你只需启动你的容器,让其他人担心事情的进展。
对于容器镜像Linux 发行版为您的项目提供了对大量软件的轻松访问。即使您从头开始构建,您也可能会看到一个包维护人员是如何构建和运送东西的——一个好的艺术家是一个好的小偷,所以不要低估这项工作的价值。
所以,感谢 Fedora、RHELFrantisek你是我的英雄 、Debian、Gentoo 和其他 Linux 发行版的所有维护人员。我很感激你所做的工作,尽管我是个“容器工人”
--------------------------------------------------------------------------------
via: https://opensource.com/article/19/2/linux-distributions-still-matter-containers
作者:[Scott McCarty][a]
选题:[lujun9972][b]
译者:[Chao-zhi](https://github.com/Chao-zhi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/fatherlinux
[b]: https://github.com/lujun9972
[1]: https://aeon.co/essays/innovation-is-overvalued-maintenance-often-matters-more
[2]: https://blog.openshift.com/openshift-on-openstack-delivering-applications-better-together/
[3]: https://developers.redhat.com/blog/2018/02/13/red-hat-cdk-nested-kvm/
[4]: https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction/#h.8tyd9p17othl
[5]: https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction/#h.dqlu6589ootw
[6]: https://en.wiktionary.org/wiki/yak_shaving

View File

@ -0,0 +1,166 @@
[#]: collector: (lujun9972)
[#]: translator: (Chao-zhi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (5 Streaming Audio Players for Linux)
[#]: via: (https://www.linux.com/blog/2019/2/5-streaming-audio-players-linux)
[#]: author: (Jack Wallen https://www.linux.com/users/jlwallen)
5 个适用于 Linux 的流式音频播放器
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/music-main.png?itok=bTxfvadR)
当我工作的时候,我会一直在后台播放音乐。大多数情况下,会是插入 CD 光盘来播放音乐。但有时我不想用这种单纯的方法听音乐时,我会选择听流媒体音频应用程序的方式。然而,由于我工作在 Linux 平台上,所以我只可以使用在我的操作系统上运行良好的软件。幸运的是,对于想在 Linux 桌面听流式音频的人来说,有很多工具可以选择。
事实上Linux 为音乐流提供了许多可靠的产品,我将重点介绍我最喜欢的五种用于此任务的工具。警告一句,并不是所有的玩意都是开源的。但是如果你可以在你的开源桌面上运行一个专有的应用程序,你有一些非常棒的选择。让我们来看看有什么可用的。
### Spotify
Linux 版的 Spotify 不是那种在你启动就闪退的愚蠢的、半生不熟的应用程序也没有阉割什么功能。事实上Spotify 的 Linux 版本与其他平台上的版本完全相同。使用 Spotify 流媒体客户端您可以收听音乐和播客创建播放列表发现新的艺术家等等。Spotify 界面(图 1非常易于导航和使用。
![Spotify][2]
图 1Spotify 界面可以很容易地找到新的音乐和旧的收藏。
[Used with permission][3]
您可以使用 snap使用 `sudo snap install Spotify` 命令)安装 Spotify也可以使用以下命令从官方存储库安装 Spotify
```
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 931FF8E79F0876134EDDBDCCA87FF9DF48BF1C90
sudo echo deb <http://repository.spotify.com> stable non-free | sudo tee /etc/apt/sources.list.d/spotify.list
sudo apt-get update
sudo apt-get install spotify-client
```
一旦安装,你就可以登录你的 Spotify 帐户,这样你就可以开始听好听的音乐,以帮助激励你完成你的工作。如果您已在其他设备上安装了 Spotify并登录到同一帐户则可以指定音乐应流到哪个设备通过单击 Spotify 窗口右下角附近的“可用设备”图标)。
### Clementine
Clementine 是 Linux 平台上最好的音乐播放器之一。Clementine 不仅允许用户播放本地存储的音乐,还可以连接到许多流媒体音频服务,例如:
* Amazon Cloud Drive
* Box
* Dropbox
* Icecast
* Jamendo
* Magnatune
* RockRadio.com
* Radiotunes.com
* SomaFM
* SoundCloud
* Spotify
* Subsonic
* Vk.com
* 或其他有趣的电台
使用 Clementine 有两个注意事项。首先,您必须使用最新版本(因为某些存储库中可用的构建已过时,并且不会安装必要的流式处理插件)。第二,即使是最新的构建,一些流媒体服务也不会像预期的那样工作。例如,接入 Spotify 频道时,您只能使用最热门的曲目(而无法使用播放列表,或搜索歌曲的功能)。
使用 Clementine 互联网流媒体服务时,你会发现其中有很多你从来没有听说过的音乐家和乐队(图 2
![Clementine][5]
图 2Clementine 互联网广播是寻找新音乐的好方法。
[Used with permission][3]
### Odio
Odio 是一个跨平台的专有应用程序(可用于 Linux、MacOS 和 Windows它允许您流式传输各种类型的互联网音乐站。广播的内容是取自 [www.radio-browser.info][6] 而应用程序本身在为您呈现流方面做了令人难以置信的工作(图 3
![Odio][8]
图 3Odio 接口是您能找到的最好的接口之一。
[Used with permission][3]
Odio 让你很容易找到独特的互联网广播电台,甚至可以把你找到并喜欢的电台添加到你的库中。目前,在 Linux 上安装 Odio 的唯一方法是通过 Snap。如果您的发行版支持 snap 软件包,请使用以下命令安装此流应用程序:
```
sudo snap install odio
```
安装后您可以打开应用程序并开始使用它。无需登录或创建帐户。Odio 的设置非常有限。实际上它只提供了在设置窗口中选择暗主题或亮主题的选项。然而尽管它可能是有限的Odio 是在 Linux 上播放互联网广播的最佳选择之一。
### StreamTuner2
Streamtuner2 是一个优秀的互联网电台 GUI 工具。使用它,您可以流式播放以下音乐:
* Internet radio stations
* Jameno
* MyOggRadio
* Shoutcast.com
* SurfMusic
* TuneIn
* Xiph.org
* YouTube
Streamtuner2 提供了一个很好的界面如果不是有点过时的话可以很容易地找到和播放您喜爱的音乐。StreamTuner2 的一个警告是,它实际上只是一个用于查找您想要听到的流的 GUI。当你找到一个站点时双击它打开与流相关的应用程序。这意味着您必须安装必要的应用程序才能播放流。如果你没有合适的应用程序你就不能播放流。因此您将花费大量的时间来确定要为某些流安装哪些应用程序图 4
![Streamtuner2][10]
图4配置 Streamtuner2 需要一个坚强的心脏。
[Used with permission][3]
### VLC
很长一段时间以来VLC 一直被称为 Linux 最好的媒体播放工具。这是有充分理由的,因为几乎所有你丢给它的东西它都能播放。其中包括流媒体广播电台。虽然你无法让 VLC 连接到 Spotify 这样的网站,但你可以直接访问互联网广播,点击播放列表,而 VLC 毫无疑问可以打开它。考虑到目前有很多互联网广播电台你在寻找适合自己口味的音乐方面不会有任何问题。VLC 还包括可视化工具、均衡器(图 5等工具。
![VLC ][12]
图 5VLC 可视化工具和均衡器特性。
[Used with permission][3]
VLC 唯一需要注意的是,你必须有一个你希望听到的互联网广播的 URL因为这个工具本身并不能进行管理。但是有了这些链接你就找不到比 VLC 更好的媒体播放器了。
### 这些工具软件怎么来的
如果这五个工具都不太不适合你的需要,我建议你打开你发行版的应用商店,搜索一个适合你的。有很多工具可以制作流媒体音乐、播客等等,不仅可以在 Linux 上实现,而且很简单。
通过 Linux 基金会和 edX 提供的免费[“Linux 简介”][13]课程了解更多关于 Linux 的信息。
--------------------------------------------------------------------------------
via: https://www.linux.com/blog/2019/2/5-streaming-audio-players-linux
作者:[Jack Wallen][a]
选题:[lujun9972][b]
译者:[Chao-zhi](https://github.com/Chao-zhi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.linux.com/users/jlwallen
[b]: https://github.com/lujun9972
[2]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/spotify_0.jpg?itok=8-Ym-R61 (Spotify)
[3]: https://www.linux.com/licenses/category/used-permission
[5]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/clementine_0.jpg?itok=5oODJO3b (Clementine)
[6]: http://www.radio-browser.info
[8]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/odio.jpg?itok=sNPTSS3c (Odio)
[10]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/streamtuner2.jpg?itok=1MSbafWj (Streamtuner2)
[12]: https://www.linux.com/sites/lcom/files/styles/rendered_file/public/vlc_0.jpg?itok=QEOsq7Ii (VLC )
[13]: https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux

View File

@ -0,0 +1,180 @@
[#]: collector: (lujun9972)
[#]: translator: (stevenzdg988)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Learn Python by creating a video game)
[#]: via: (https://opensource.com/article/20/10/learn-python-ebook)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
通过创建视频游戏来学习 Python
======
在新电子书中使用分步说明的这种娱乐方式来了解学习 Python。
![街机游戏][1]
Python 是目前最流行的程序设计语言之一。不管是为了工作还是娱乐为目的学习 Python它都是一门功能强大且非常有用的编程语言。您可以创建应用程序来帮助您完成日常任务创建你和你的朋友喜欢玩的游戏创建用于处理数据的脚本创建用于生成或分析信息的应用程序等等。
无论您计划使用哪种程序设计语言做什么,我们都认为通过创建游戏来学习比通过处理数字或变换字符串来学习更为有趣。然而,如果你完全是一个编程的新手,那么可以轻松地理解为什么必须在代码中执行某些操作,因为你可以看到代码运行在一个熟悉的环境下就像是一个电视游戏。
您可能没有选择 [Python][2] 作为可用的最佳编程语言(每个人对此都有自己的答案),但它不是一门令人恐惧的编程语言。 Python可以使用很多关键字例如 `is``is not`)代替符号(例如 `=``!=`)。它还管理许多低级任务,因此您通常不必担心数据类型和无用信息收集之类的事情。通常,这意味着你可以开始编写代码,而不会像在 [C][3] 或 [Java][4] 那样的复杂编程语言面前遇到挫折。
为了帮助您学习 Python我们编写了电子书教你如何使用 Python 创建电视游戏平台。在制作电视游戏的同时逐步通过课程学习 Python。另外一个好处是您还将学习编程逻辑语法运算符等更多的内容。您可以在学习过程中立即看到结果因此您学到的所有内容都会得到及时巩固。
### 让我们开始 Python
Python 是一种用途广泛的编程语言,这意味着它(与大多数语言一样)提供了简单的 “特有的方式” 的功能处理数字和字符。Linux 操作系统用户已经安装了 Python。 Mac 操作系统用户使用的是 Python 的旧版本,但是您可以从 Python.org 网站 [安装最新版本][5]。Windows 操作系统用户可以从这篇 [在 Windows 上安装 Python][6] 的文章中学习如何安装 Python。
安装完成后,您可以启动交互式 `Python Shell` 进行算术运算:
```
$ python3
&gt;&gt;&gt; 5+6
11
&gt;&gt;&gt; 11/2
5.5
&gt;&gt;&gt; 11//2
5
&gt;&gt;&gt; 11%2
1
```
从该示例可以了解,需要一些特殊的符号,但学过数学的人都最熟悉不过了。也许您不是数字型的人,而更喜欢字母:
```
$ python3
&gt;&gt;&gt; string = "hello world"
&gt;&gt;&gt; print(string)
hello world
&gt;&gt;&gt; print(string.upper())
HELLO WORLD
&gt;&gt;&gt; print(string[0])
h
&gt;&gt;&gt; print(string[1])
e
&gt;&gt;&gt; print(string[2])
l
&gt;&gt;&gt; print(string[3])
l
&gt;&gt;&gt; print(string[4])
o
```
同样,相对地说基础的任务有特殊的符号表示法,但是即使没有说明,你也可能已经发现 `[0]``[1]` 符号表示法是将数据 "切片"并且利用 `print` 函数将其中的数据显示在屏幕上。
### 五分钟搞定 Pygame
如果你只想使用 Python 来创建视频游戏或除基本计算以外的其他项目这可能需要投入大量的学习努力和时间。幸运的是Python 诞生已有二十年了,开发者已经开发了代码库来帮助您轻松(相对)地实施典型的程序设计。 [Pygame][7] 是一组用于创建视频游戏的代码模块。它 [不是唯一的类库][8],但是它是最古老的(不论好坏),因此在线上有很多文档和示例。
首先学习 [介绍 Python 虚拟环境工作流程][9]
```
$ python3 -m venv mycode/venv
$ cd mycode
$ source ./venv/bin/activate
(venv)$
```
进入虚拟环境后,可以安全地将 Pygame 安装到项目文件夹中:
```
(venv)$ echo "pygame" &gt;&gt; requirements.txt
(venv)$ python -m pip install -r requirements.txt
[...] Installing collected packages: pygame
Successfully installed pygame-x.y.z
```
现在你已经安装了 Pygame就可以创建一个简单的演示应用程序。它比您想象的要容易。 Python 可以执行称为 _object-oriented programming_ OOP “面向对象的编程”)的操作,这是计算机科学术语,用于描述代码的结构,就像您使用代码创建物理对象一样。然而,程序员并没有受到迷惑。他们知道在编写代码时并没有真正在制造物理对象,但是这样有助于想象,因为这样可以了解编程世界的局限性。
例如,如果您被困在一个荒岛上并想要一杯咖啡,那么您就必须收集一些黏土,做一个杯子,然后烘烤它。如果你足够聪明,先创建一个模具,以便每当需要另一个杯子时,都可以从模板中快速创建一个新杯子。即使每个杯子都来自相同的模板,它们在物理上也是独立的:如果一个杯子破裂,您还会有另一个杯子。您可以通过添加颜色或蚀刻使每个咖啡杯显得独特。
在 Pygame 和许多编程任务中,你使用类似的逻辑。在定义之前,不会出现在你的编程项目中。这就是怎样做一杯咖啡在 Python 和 Pygame 定制项目的形象比喻。
#### 使用 Pygame 进行面向对象的编程
创建一个名为 `main.py` 的文件,并输入以下代码用以启动 Pygame 模块并使用 Pygame 模板创建一个窗口:
```
import pygame
pygame.init()
screen = pygame.display.set_mode((960,720))
```
就像您可能在现实生活中使用模板来创建对象一样,您也可以使用 Pygame 提供的模板来创建 _sprite_(这是 Pygame 的视觉游戏对象术语。在面向对象的编程中_class_ 表示对象的模板。在您的文档中输入以下代码:
```
class Cup(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        # image
        img = pygame.image.load('coffeecup.png').convert()
        self.image = img
        # volume
        self.rect = self.image.get_rect()
        self.rect.x = 10
        self.rect.y = 10
```
该代码块使用 Pygame 的 `sprite` 模板设计咖啡杯子精灵图形。由于 ,你的咖啡杯子精灵图形具有 `self.image` 图像,而 `self.rect` 则赋予了它体积(宽度和高度)。这些是 Pygame 期望精灵图形拥有的属性,但是如果您要创建可玩的视频游戏,则可以为其指定任何其他所需的属性,例如健康点和得分。
到目前为止,您所要做的就是创建一个窗口和一个用于咖啡杯的 _template_ 。您的游戏实际上还不是杯水。
代码的最后一部分必须使用模板来生成杯子并将其添加到游戏世界中。如您所知,计算机运行速度非常快,因此从技术上讲,您到目前为止创建的代码只能运行一毫秒左右。编写图形计算机应用程序时,无论计算机是否认为已完成规定的任务,都必须强制其保持打开状态。程序员使用 _infinite loop_ 来执行此操作,该循环在 Python 中由 `while True` 指令表示True 始终为真,因此循环永远不会结束)。
无限循环确保您的应用程序保持打开状态足够长的时间,以使计算机用户可以查看和使用该应用程序:
```
cup = Cup()
while True:
    pygame.display.update()
    screen.blit(cup.image, cup.rect)
```
此代码示例从模板 `Cup` 创建杯子,然后使用 Pygame 函数更新显示。最后,使用 Pygame 的 `blit` 函数在其边框内绘制杯子的图像。
#### 获取图形
在成功运行代码之前,您需要为咖啡杯准备一个图形。您可以在 [FreeSVG.org][11] 上找到许多 [Creative Commons公用创作][10] 咖啡杯图形。我用了 [这个][12]。将图形保存在项目目录中,并将其命名为 `coffeecup.png`
#### 运行游戏
启动应用程序:
```
`(venv)$ python ./main.py`
```
![Pygame 中的咖啡杯][13]
(Seth Kenlon, [CC BY-SA 4.0][14])
### [下载 Python 游戏电子书][15]
Pygame 是一个功能强大的框架,除了在屏幕上绘制咖啡杯之外,您还可以做更多的事情。[下载我们的免费电子书][15] 更好地了解 Pygame 和 Python。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/10/learn-python-ebook
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/stevenzdg988)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/arcade_game_gaming.jpg?itok=84Rjk_32 (Arcade games)
[2]: https://www.python.org/
[3]: https://opensource.com/article/20/8/c-programming-cheat-sheet
[4]: https://opensource.com/resources/java
[5]: https://www.python.org/downloads/mac-osx
[6]: https://opensource.com/article/19/8/how-install-python-windows
[7]: https://www.pygame.org/news
[8]: https://opensource.com/article/18/4/easy-2d-game-creation-python-and-arcade
[9]: https://opensource.com/article/20/9/venv-python
[10]: https://opensource.com/article/20/1/what-creative-commons
[11]: http://freesvg.org
[12]: https://freesvg.org/1548870028
[13]: https://opensource.com/sites/default/files/uploads/pygame-cup.jpg (Coffee cup in Pygame)
[14]: https://creativecommons.org/licenses/by-sa/4.0/
[15]: https://opensource.com/downloads/python-gaming-ebook

View File

@ -7,51 +7,50 @@
[#]: via: (https://opensource.com/article/21/1/ceph-raspberry-pi)
[#]: author: (AJ Canlas https://opensource.com/users/ajscanlas)
Deploy Ceph in a Raspberry Pi cluster
在树莓派集群中部署 Ceph
======
Install Ceph storage using ceph-ansible and deploy it in a Raspberry Pi
cluster.
使用 ceph-ansible 安装 Ceph 存储,并将其部署在树莓派集群中。
![Vector, generic Raspberry Pi board][1]
[Ceph][2] is an open source software storage platform that provides object, block, and filesystem storage in a unified storage cluster. I first used Ceph when I [integrat][3][ed it with OpenStack][3]. At first, I was confused about why I should use Ceph since storage devices are widely available. But after using it for more than three years, the platform's stability and integrity have proven its value again and again.
[Ceph][2] 是一个开源软件存储平台,它在统一的存储集群中提供对象、块和文件系统存储。我第一次使用 Ceph 是在 [OpenStack 中集成它][3]的时候。一开始,我很困惑,既然存储设备广泛存在,为什么要使用 Ceph。但在使用了三年多之后这个平台的稳定性和完整性一再证明了它的价值。
This article will show you how to install Ceph using [ceph-ansible][4] (an officially supported Ansible playbook for Ceph) and deploy it in a Raspberry Pi cluster.
本文将告诉你如何使用 [ceph-ansible][4]Ceph 官方支持的 Ansible playbook安装 Ceph并将其部署在树莓派集群中。
**Materials:**
**材料:**
1. Four Raspberry Pi 4B 4GB models
2. Four 32GB microSD cards (boot OS)
3. Four Raspberry Pi cases with fans and heatsinks (very important)
4. Four Raspberry Pi chargers
5. Six 32GB USB flash drives (for the Ceph OSD nodes)
1. 树莓派 4B 4GB 型号四台。
2. 四张 32GB 的 microSD 卡(启动操作系统)
3. 四个树莓派外壳,带风扇和散热片(非常重要)
4. 四个树莓派充电器
5. 6 个 32GB U 盘(用于 Ceph OSD 节点)
**Architecture:**
**架构:**
![Project architecture][5]
(Aaron John Canlas, [CC BY-SA 4.0][6])
Aaron John Canlas, [CC BY-SA 4.0][6]
Regarding the configuration:
关于配置:
* Both the front-end and back-end networks are in the same subnet
* The [Ceph Monitor][7] software uses a Raspberry Pi 4B with 4GB RAM
* The [Ceph OSD][8] nodes use the same Raspberry Pi model but with two USB flash drives for the OSD disks
* 前端和后端网络都在同一个子网中
* [Ceph Monitor][7] 软件使用 4GB 内存的树莓派 4B。
* [Ceph OSD][8] 节点使用相同的树莓派型号,但有两个 U 盘用于 OSD 磁盘
### Deploy Ceph using ceph-ansible
### 使用 ceph-ansible 部署 Ceph
Using Ceph's Ansible repository makes the deployment smooth and simple.
使用 Ceph 的 Ansible 仓库可以让部署变得顺畅简单
#### 1\. Copy ssh keys to all servers
#### 1\. 复制 ssh 密钥到所有服务器
I have a common user called `cephadmin` on all servers (each Raspberry Pi is a server in this context). The `cephadmin` user is configured with passwordless `sudo` to make things easier.
我在所有的服务器上都有一个名为 `cephadmin` 的共同用户(在此背景下,每个树莓派都是一台服务器)。`cephadmin` 用户配置了无密码的 `sudo`,以方便工作。
After generating a key using `ssh-keygen`, deploy all keys using `ssh-copy-id`.
使用 `ssh-keygen` 生成密钥后,使用 `ssh-copy-id` 部署所有密钥。
I use a Bash for-loop because I'm using consistent and incremental hostnames:
我使用了一个Bash for 循环,因为我使用的是一致并递增的主机名:
```
@ -60,18 +59,18 @@ $ for i in {0..3}; \
done
```
You need to accept and enter your password on each one, but you can automate this with `expect`.
你需要每个接受并输入密码,但你可以用 `expect` 来自动完成。
#### 2\. Clone ceph-ansible and install requirements
#### 2\. 克隆 ceph-ansible 并安装依赖
Install Git to clone the repository:
安装 Git 来克隆仓库:
```
`$ sudo yum install git -y`
```
Clone the ceph-ansible repository:
克隆 ceph-ansible 仓库:
```
@ -79,30 +78,30 @@ $ git clone <https://github.com/ceph/ceph-ansible.git>
$ cd ceph-ansible/
```
I'm using an AArch64 build of CentOS 7, so I must install some required packages before continuing.
我使用的是 CentOS 7 的 AArch64 构建,所以在继续之前,我必须安装一些所需的包。
First, Python pip:
首先安装 Python pip
```
`$ sudo yum install python3-pip -y`
```
Then the packages ceph-ansible needs:
接着是 ceph-ansible 需要的包:
```
`$ sudo yum install python3-devel libffi-devel openssl-devel -y`
```
Finally, the requirements `ceph-ansible` needs:
最后,`ceph-ansible` 需要的依赖:
```
`$ pip3 install -r requirements.txt --user`
```
I received this error:
我收到了这个错误:
```
@ -112,27 +111,27 @@ this version only you can also set the environment variable
CRYPTOGRAPHY_ALLOW_OPENSSL_102 to allow OpenSSL 1.0.2.
```
This may be related to the architecture, because I can't replicate the error in a CentOS 7 virtual machine.
这可能与架构有关,因为我无法在 CentOS 7 虚拟机中复现该错误。
For deployment, export `CRYPTOGRAPHY_ALLOW_OPENSSL_102` to `True` so that Ansible can run:
部署时,将 `CRYPTOGRAPHY_ALLOW_OPENSSL_102` 导出为 `True`,这样 Ansible 就可以运行了。
```
`$ export CRYPTOGRAPHY_ALLOW_OPENSSL_102=True`
```
#### 3\. Configure ceph-ansible for deployment
#### 3\. 配置 ceph-ansible 进行部署
Now you're ready to deploy Ceph using ceph-ansible.
现在你可以使用 ceph-ansible 部署 Ceph 了。
Copy `site.yml.sample` to `site.yml`:
复制 `site.yml.sample``site.yml`
```
`$ mv site.yml.sample site.yml`
```
Create `all.yml` in the `group_vars` directory:
`group_vars` 目录下创建 `all.yml`
```
@ -149,7 +148,7 @@ configure_firewall: false
EOF
```
Create `osds.yml` in the `group_vars` directory:
`group_vars` 目录下创建 `osds.yml`
```
@ -161,7 +160,7 @@ devices:
EOF
```
Create an inventory file:
创建一个 inventory 文件:
```
@ -176,7 +175,7 @@ rpi4b4-3
EOF
```
As of this writing, there is a bug in the ceph-ansible repository (according to this [bug ticket][9]). You can mitigate the bug by editing line 85 and 86 of the roles:
在写这篇文章的时候ceph-ansible 仓库里有一个 bug根据这个 [bug 工单][9])。你可以通过编辑角色的第 85 行和第 86 行来减轻这个 bug。
```
@ -184,26 +183,26 @@ As of this writing, there is a bug in the ceph-ansible repository (according to
    - (wait_for_all_osds_up.stdout | from_json)["osdmap"]["num_osds"] == (wait_for_all_osds_up.stdout | from_json)["osdmap"]["num_up_osds"]
```
#### 4\. Deploy Ceph
#### 4\. 部署 Ceph
Run the Ansible playbook with your inventory file:
用你的 inventory 文件运行 Ansible playbook
```
`$ ansible-playbook -i inventory site.yml`
```
After 1520 minutes, you should see this result:
15-20 分钟后,你应该看到这个结果:
![Ceph deployment][10]
(Aaron John Canlas, [CC BY-SA 4.0][6])
### Next steps
### 下面的步骤
Previously, I [manually deployed][11] an OpenStack cluster in another Raspberry Pi cluster. I hope to integrate it with this one. I'm also looking into deploying with [TripleO][12].
之前,我在另一个树莓派集群中[手动部署][11]了一个 OpenStack 集群。我希望能将其与这个集群整合在一起。我也在研究用 [TripleO][12] 部署。
The possibilities for Raspberry Pi, Ansible, and OpenStack are endless. Get started with your own experiment, and let me know how it goes in the comments.
树莓派、Ansible 和 OpenStack 的可能性是无穷的。开始做你自己的实验,并在评论中告诉我结果如何。
--------------------------------------------------------------------------------
@ -211,7 +210,7 @@ via: https://opensource.com/article/21/1/ceph-raspberry-pi
作者:[AJ Canlas][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出