diff --git a/published/20150604 12 Globally Recognized Linux Certifications.md b/published/20150604 12 Globally Recognized Linux Certifications.md new file mode 100644 index 0000000000..3b1ed918ba --- /dev/null +++ b/published/20150604 12 Globally Recognized Linux Certifications.md @@ -0,0 +1,172 @@ +12 个全球认可的 Linux 认证 +================================================================================ +大家好,今天我们将会认识一些非常有价值的全球认可的Linux认证。Linux认证是不同的Linux专业机构在全球范围内进行的认证程序。Linux认证可以让Linux专业人才可以在服务器领域或者相关公司等等这些地方更容易获得Linux相关的工作。Linux认证评估一个人在Linux的各个领域里的专业程度。有很多不错的Linux专业机构提供不同的Linux认证。但是,在公司谋取一份工作时全球仅有少数被非常认可的Linux认证含金量很高,这些工作包括管理服务器,虚拟化,安装系统与软件,配置程序,应用支持和其他Linux操作系统相关的东西。随着全球使用Linux操作系统的服务器的增长,拉动了对于Linux专业人才的需求。为了更好的证明Linux专业技术水平,在全球看来,更好的、著名的认证总是有着更高的优先级。 + +这里是一些全球认可的Linux认证,我们接下来将会一一谈到。 + +### 1. CompTIA Linxu+ ### + +CompTIA Linux+ 是LPI(Linux Professional Institute,Linux专业委员会)主办的一个Linux认证,在全世界范围内提供培训。其提供的Linux相关知识,可以用于从事一大批Linux相关专业的工作,如Linux管理员、高级网络管理员、系统管理员、Linux数据库管理员和Web管理员。如果任何人想从事安装和维护Linux操作系统,该课程会帮助他达到认证要求,并且通过提供对Linux系统更宽阔的认识,能够为通过考试做好准备。LPI的CompTIA Linux+认证的主要目的就是,提供给证书持有者足够扎实的,关于安装软件、操作、管理和设备排障的知识。我们可以付出一定的费用、时间和努力,完成CompTIA Linux+,同时获得三个业内认可的证书:**LPI LPIC-1**和**SUSE Certified Linux Administrator (CLA)**证书。 + +- **认证代码** : LX0-103,LX0-104(2015年3月30日启动)或者LX0-101,LX0-102 +- 题目数量:每次考试60道题 +- 题目类型:多选 +- 考试时长:90分钟 +- 要求:A+,Network+,并且有至少12个月的Linux管理经验 +- 分数线:500 (对于200-800的范围来说) +- 语言:英语,将来会有德语,葡萄牙语,繁体中文,西班牙。 +- 有效期:认证后三年有效 + +**注意**:不同系列的考试不能合并。如果你考的是LX0-101,那么你必须考LX0-102完成认证。同样的,LX0-103和LX0-104又是一个系列。LX0-103和LX0-104系列是LX0-101和LX0-102系列的升级版。 + +### 2. LPIC ### + +LPIC,全称Linux专业委员会认证( Linux Professional Institute Certification),是Linux专业委员会的一个Linux认证程序。这是一个多级别的认证程序,要求在每个级别通过一系列(通常是两个)的认证考试。该认证有三个级别,包括初级水平认证 **LPIC-1** ,高级水平认证 **LPIC-2**和最高水平认证 **LPIC-3**。前两个认证侧重于 **Linux系统管理**,而最后一个认证侧重一些专业技能,包括虚拟化和安全。为了得到 **LPIC-3** 认证,一个持有有效的 **LPIC-1** 与**LPIC-2** 认证的考生必须通过300复杂环境测试、303安全测试、304虚拟化测试和高可用性测试中的一个。**LPIC-1**认证按照证书持有者可以通过运行Linux,使用命令行界面和基本的网络知识安装,维护,配置等任务而设计,LPIC-2测试考生是否作为管理中小型混合网络的候选人。LPIC-3认证是为企业级Linux专业技能设计所设计,代表了最高的专业水平和不针对特定 Linux 发行版的行业认证。 + +- **认证代码**:LPIC-1(101和102),LPIC-2(201和202)和LPIC-3(300,303或者304) +- 题目类型:60个多项选择 +- 考试时长:90分钟 +- 要求:无,建议有 Linux Essentials 认证 +- 分数线:500(在200-800的范围内) +- 语言:LPIC-1:英语,德语,意大利语,葡萄牙语,西班牙语(现代),汉语(简体),汉语(繁体),日语 +- LPIC-2:英语,德语,葡萄牙语,日语 +- LPIC-3:英语,日语 +- 有效期:退休之后五年内仍然有效 + +### 3.Oracle Linux OCA ### + +Oracle联合认证(OCA)为个人而定制,适用于那些想证明其部署和管理Oracle Linux操作系统的知识牢固的人。该认证专业知识仅仅针对Oracle Linux发行版,这个系统完全是为Oracle产品特别剪裁的,可以运行Oracle设计的系统,包括Oracle Exadata数据库服务器,Oracle Exalytics In-Memory 服务器,Oracle Exalogic 均衡云,和Oracle数据库应用等。Oracle Linux的“坚不可摧企业内核”为企业应用带来了高性能、高扩展性和稳定性。OCA认证覆盖了如管理本地磁盘设备、管理文件系统、安装和移除Solaris包与补丁,优化系统启动过程和系统进程。这是拿到OCP证书系列的第一步。OCA认证以其前身为Sun Certified Solaris Associate(SCSAS)而为人所知。 + +- **认证代码**:OCA +- 题目类型:75道多项选择 +- 考试时长:120分钟 +- 要求:无 +- 分数线:64% +- 有效期:永远有效 + +### 4. Oracle Linux OCP ### + +Oracle专业认证(OCP)是Oracle公司为Oracle Linux提供的一个认证,覆盖更多的进阶知识和技能,对于一个Oracle Linux管理员来说。它囊括的知识有配置网络接口、管理交换分区配置、崩溃转储、管理软件、数据库和重要文件。OCP认证是技术性专业知识和专业技能的基准测试,这些知识与技能需要在公司里广泛用于开发、部署和管理应用、中间件和数据库。Oracle Linux OCP的工作机会在增长,这得益于工作市场和经济发展。根据考试纲领,证书持有者有能力胜任安全管理、为Oracle 数据库准备Oracle Linux系统、排除故障和进行恢复操作、安装软件包、安装和配置内核模块、维护交换空间、完成用户和组管理、创建文件系统、配置逻辑卷管理(LVM)、文件分享服务等等。 + +- **认证代码**:OCP +- 题目类型:60至80道多项选择题 +- 考试时长:120分钟 +- 要求:Oracle Linux OCA +- 分数线:64% +- 有效期:永远有效 + +### 5. RHCSA ### + +RHCSA是红帽公司作为红帽认证系统工程师推出的一个认证程序。RHCSA们是指一些拥有在著名的红帽Linux环境下完成核心系统管理技能和能力的人。这是一个入门级的认证程序,关注在系统管理上的实际胜任能力,包括安装、配置一个红帽Linux系统,接入一个可用的网络提供网络服务。一个红帽认证的系统管理员可以理解和使用基本的工具,用以处理文件、目录、命令行环境和文档;操作运行中的系统,包括以不同的启动级别启动、识别进程、开启和停止虚拟机和控制服务;使用分区和逻辑卷配置本地存储;创建和配置文件系统和文件系统属性,包括权限、加密、访问控制列表和网络文件系统;部署配置和维护系统,包括软件安装、更新和核心服务;管理用户和组,包括使用一个中心的目录用于验证;安全性的工作,包括基本的基本防火墙和SELinux配置。要获得RHCE和其他认证,首先得认证过RHCSA。 + +- **认证代码**:RHCSA +- 课程代码:RH124,RH134和RH199 +- 考试代码:EX200 +- 考试时长:21-22小时,取决于选择的课程 +- 要求:无。有一些Linux基础知识更好 +- 分数线:300总分,210过(70%) +- 有效期:3年 + +### 6. RHCE ### + +RHCE,也叫做红帽认证工程师,是一个中到高级水平的认证程序,为一些想要学习更多技能和知识,成为一个负责红帽企业Linux的高级系统管理员的RHCSA开设的,RHCE应该有能力、知识和技能来配置静态路由、包过滤、NAT、设定内核运行参数、配置一个ISCSI初始化程序,生成并发送系统用量报告、使用shell脚本自动完成系统维护任务、配置系统日志,包括远程日志、提供网络服务如HTTP/HTTPS、FTP、NFS、SMB、SMTP、SSH和NTP等等。推荐希望获得更多高级水平的认证的RHCSA们、已经完成系统管理员I,II和III、或者已经完成RHCE 快速跟进培训的人们参加认证。 + +- **认证代码**:RHCE +- 课程代码:RH124,RH134,RH254和RH199 +- 考试代码:EX200和EX300 +- 考试时长:21-22个小时,取决于所选课程 +- 要求:一个RHCSA证书 +- 分数线:300总分,210过(70%) +- 有效期:3年 + +### 7. RHCA ### + +RHCA即红帽认证架构师,是红帽公司的一个认证程序。它的关注点在系统管理的实际能力,包括安装和配置一个红帽Linux系统,并加入到一个可用网络中运行网络服务。RHCA是所有红帽认证中最高水平的认证。考生需要选择他们希望针对的领域,或者选择合格的红帽认证的任意组合来创建一个他们自己的领域。这里有三个主要的领域:数据中心、云和应用平台。精通数据中心领域的RHCA能够运行、管理数据中心;而熟悉云的可以创建、配置和管理私有云和混合云、云应用平台以及使用红帽企业Linux平台的灵活存储方案;精通应用平台集合的RHCA拥有技能如安装、配置和管理红帽JBoss企业应用平台和应用,云应用平台和混合云环境,借助红帽的OpenShift企业版,使用红帽JBoss数据虚拟化技术从多个资源里组合数据。 + +- **认证代码**:RHCA +- 课程代码:CL210,CL220.CL280,RH236,RH318,RH413,RH436,RH442,JB248和JB450 +- 考试代码:EX333,EX401,EX423或者EX318,EX436和EX442 +- 考试时长:21-22个小时,取决于所选课程 +- 要求:未过期的RHCE证书 +- 分数线:300总分,210过(70%) +- 有效期:3年 + +### 8. SUSE CLA ### + +SUSE认证Linux管理员(SUSE CLA)是SUSE推出的一个初级认证,关注点在SUSE Linux企业服务器环境下的日常任务管理。为了获得SUSE CLA认证,不用必须完成课程任务,只需要通过考试就能获得认证。SUSE CLA们能够、也有技术去使用Linux桌面、定位并利用帮助资源、管理Linux文件系统、用Linux Shell和命令行工作、安装SLE 11 SP22、管理系统安装、硬件、备份和恢复、用YaST管理Linux、Linux进程和服务、存储、配置网络、远程接入、SLE 11 SP2监控,任务自动化和管理用户访问和安全工作。我们可以同时获得SUSE CLA,LPIC-1和CompTIA Linux认证,因为SUSE,Linux Professional Institute和CompATI合作提供了这个同时获得三个Linux认证的机会。 + +- **认证代码**:SUSE CLA +- 课程代码:3115,3116 +- 考试代码:050-720,050-710 +- 问题类型:多项选择 +- 考试时长:90分钟 +- 要求:无 +- 分数线:512 + +### 9. SUSE CLP ### + +SUSE认证Linux专业人员(CLP)是一个认证程序,为那些希望获得关于SUSE Linux企业服务器更多高级且专业的知识的人而服务。SUSE CLP是通过SUSE CLA认证后的下一步。应该通过CLA的考试并拥有证书,然后通过完成CLP的考试才能获得CLP的认证。通过SUSE CLP认证的人员有能力完成安装和配置SLES 11系统、维护文件系统、管理软件包、进程、打印、配置基础网络服务、samba、Web服务器、使用IPv6、创建和运行bash shell脚本。 + +- **认证代码**:SUSE CLP +- 课程代码:3115,3116和3117 +- 考试代码:050-721,050-697 +- 考试类型:手写 +- 考试时长:180分钟 +- 要求:SUSE CLA 认证 + +### 10. SUSE CLE ### + +SUSE认证Linux工程师(CLE)是一个工程师级别的高级认证,为那些已经通过CLE考试的人准备。为了获得CLE认证,人们需要已经获得SUSE CLA和CLP的认证。获得CLE认证的人员拥有架设复杂SUSE Linux企业服务器环境的技能。CLE认证过的人可以配置基本的网络服务、管理打印、配置和使用Open LDAP、samba、IPv6、完成服务器健康检测和性能调优、创建和执行shell脚本、部署SUSE Linux企业板、通过Xen实现虚拟化等等。 + +- **认证代码**:SUSE CLE +- 课程代码:3107 +- 考试代码:050-723 +- 考试类型:手写 +- 考试时长:120分钟 +- 要求:SUSE CLP 10或者11证书 + +### 11. LFCS ### + +Linux基金会认证系统管理员(LFCS)认证考生使用Linux和通过终端环境使用Linux的知识。LFCS是Linux基金会的一个认证程序,为使用Linux操作系统工作的系统管理员和工程师准备。Linux基金会联合业内专家、Linux内核社区,测试考生的核心领域、关键技能、知识和应用能力。通过LFCS认证的人员拥有一些技能、知识和能力,包括在命令行下编辑和操作文件、管理和处理文件系统与存储的错误、聚合分区作为LVM设备、配置交换分区、管理网络文件系统、管理用户帐号/权限和属组、创建并执行bash shell脚本、安装/升级/移除软件包等等。 + +- **认证代码**:LFCS +- 课程代码:LFCS201,LFCS220(可选) +- 考试代码:LFCS 考试 +- 考试时长:2小时 +- 要求:无 +- 分数线:74% +- 语言:英语 +- 有效期:两年 + +### 12. LFCE ### + +Linux基金会认证工程师(LFCE),是Linux基金会为Linux工程师推出的认证。相比于LFCS,通过LFCE认证的人员在Linux方面拥有更大范围的技能。这是一个工程师级别的高级认证程序。LFCE认证的人具备一些网络管理方面的技能和能力,如配置网络服务、配置包过滤、监控网络性能、IP流量、配置文件系统和文件服务、网络文件系统、从仓库安装/升级软件包、管理网络安全、配置iptables、http服务、代理服务、邮件服务等等。由于其为高级工程级别的认证程序,所以普遍认为相比LFCS,学习和通过的难度更大些。 + +- **认证代码**:LFCE +- 课程代码:LFS230 +- 考试代码:LFCE 考试 +- 考试时长:2小时 +- 要求:认证过LFCS +- 分数线:72% +- 语言:英语 +- 有效期:2年 + +### 我们发现的情况(这仅仅是我们的观点)### + +最近的调查表明,在不同的高端招聘代理中,称80%的Linux工作描述更倾向于红帽的认证。如果你是一个学生/新手,并且想学习Linux,那么我们建议选择越来越流行的Linux基金会认证,或者CompTIA Linux也可以是一个选择。如果你已经了解了oracle或suse,或者在他们的产品上工作,那oracle/suse的认证会更好些,如果你在公司里工作了,这些认证会对你的职业生涯成长有帮助:-) + +### 总结 ### + +在这个世界上,成千上万的大公司正在运行跑着Linux操作系统的服务器和主框架机,为了在这些服务器上管理、配置和工作,总是存在着对Linux技术/专业知识高度认证的需求。这些国际上承认的认证对某些人在Linux的职业生涯扮演很重要的角色。这些遍布全球的公司运行着Linux,需要Linux工程师、系统管理员和已经获得认证且在Linux相关领域干得不错的人员。全球认可的Linux认证,对于专业知识和职业生涯的辉煌都是重中之重,所以好好准备考试并获得认证,对于在Linux建立职业生涯是一个很好的选择。如果你有任何问题,想法,反馈,请写在下方的评论框里,让我们好知道哪些东西需要添加或者改进。谢谢!:-) + +-------------------------------------------------------------------------------- + +via: http://linoxide.com/linux-how-to/12-globally-recognized-linux-certifications/ + +作者:[Arun Pyasi][a] +译者:[wi-cuckoo](https://github.com/wi-cuckoo) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://linoxide.com/author/arunp/ diff --git a/sources/tech/20150616 XBMC--build a remote control.md b/sources/tech/20150616 XBMC--build a remote control.md deleted file mode 100644 index 5066e28ce2..0000000000 --- a/sources/tech/20150616 XBMC--build a remote control.md +++ /dev/null @@ -1,265 +0,0 @@ -zpl1025 -XBMC: build a remote control -================================================================================ -**Take control of your home media player with a custom remote control running on your Android phone.** - -**XBMC** is a great piece of software, and can turn almost can computer into a media centre. It can play music and videos, display pictures, and even fetch a weather forecast. To make it easy to use in a home theatre setup, you can control it via mobile phone apps that access a server running on the XBMC machine via Wi-Fi. There are loads of these available for almost all smartphone systems. - -> ### Kodi ### -> -> By the time you read this, **XBMC** may be no more. The project team have decided to rename it **Kodi** for legal reasons (and because **XBMC**, or X**-Box Media Centre**, refers to older hardware that is no longer supported). Other than the name, though, nothing has changed. Or at least nothing other than the usual raft of improvements you’d expect from a new release. This shouldn’t affect the remote software though, and it should work on both existing **XBMC** systems, and newer Kodi systems. - -We’ve recently set up an **XBMC** system for playing music, and none of the XBMC remotes we found really excel at this task, especially when the TV attached to the media centre is turned off. They were all a bit too complex, as they packed too much functionality into small screens. We wanted a system designed from the ground up to just access a music library and a radio addon, so we decided to build one ourselves. It didn’t need to be able to access the full capabilities of XBMC, because for tasks other than music, we’d simply switch back to a general-purpose XBMC remote control. Our test system was a Raspberry Pi running the RaspBMC distribution, but nothing here is specific to either the Pi or that distro, and it should work on any Linux-based XBMC system provided the appropriate packages are available. - -The first thing a remote control needs is a user interface. Many XBMC remote controls are written as standalone apps. However, this is just for our music, and we want to be accessible to guests without them having to install anything. The obvious solution is to make a web interface. XBMC does have a built-in web server, but to give us more control, we decided to use a separate web framework. There’s no problem running more than one web server on a computer at a time, but they can’t run on the same port. - -There are quite a few web frameworks available. We’ve used Bottle because it’s a simple, fast framework, and we don’t need any complex functions. Bottle is a Python module, so that’s the language in which we’ll write the server. - -You’ll probably find Bottle in your package manager. In Debian-based systems (including Raspbmc), you can grab it with: - - sudo apt-get install python-bottle - -A remote control is really just a layer that connects the user to a system. Bottle provides what we need to interact with the user, and we’ll interact with **XBMC** using its JSON API. This enables us to control the media player by sending JSON-encoded information. - -We’re going to use a simple wrapper around the XBMC JSON API called xbmcjson. It’s just enough to allow you send requests without having to worry about the actual JSON formatting or any of the banalities of communicating with a server. It’s not included in the PIP package manager, so you need to install it straight from **GitHub**: - - git clone https://github.com/jcsaaddupuy/python-xbmc.git - cd python-xbmc - sudo python setup.py install - -This is everything you need, so let’s get coding. - -#### Get started with Bottle #### - -The basic structure of our program is: - - from xbmcjson import XBMC - from bottle import route, run, template, redirect, static_file, request - import os - xbmc = XBMC(“http://192.168.0.5/jsonrpc”, “xbmc”, “xbmc”) - @route(‘/hello/’) - def index(name): - return template(‘

Hello {{name}}!

’, name=name) - run(host=”0.0.0.0”, port=8000) - -This connects to **XBMC** (though doesn’t actually use it); then Bottle starts serving up the website. In this case, it listens on host 0.0.0.0 (which is every hostname), and port 8000. It only has one site, which is /hello/XXXX where XXXX can be anything. Whatever XXXX is gets passed to index() as the parameter name. This then passes it to the template, which substitutes it into the HTML. - -You can try this out by entering the above into a file (we’ve called it remote.py), and starting it with: - - python remote.py - -You can then point your browser to localhost:8000/hello/world to see the template in action. - -@route() sets up a path in the web server, and the function index() returns the data for that path. Usually, this means returning HTML that’s generated via a template, but it doesn’t have to be (as we’ll see later). - -As we go on, we’ll add more routes to the application to make it a fully-featured XBMC remote control, but it will still be structured in the same way. - -The XBMC JSON API can be accessed by any computer on the same network as the XBMC machine. This means that you can develop it on your desktop, then deploy it to your media centre rather than fiddle round uploading every change to your home theatre PC. - -Templates – like the simple one in the previous example – are a way of combining Python and HTML to control the output. In principal, they can do quite a bit of processing, but they can get messy. We’ll use them just to format the data correctly. Before we can do that, though, we have to have some data. - -> ### Paste ### -> -> Bottle includes its own web server, which is what we’ve been using for testing the remote control. However, we found that it didn’t always perform well. When we put the remote into action, we wanted something that could deliver pages a bit quicker. Bottle can work with quite a few different web servers, and we found Paste worked quite well. In order to use this, just install it (in the package python-paste on Debian), and change the run call to: -> -> run(host=hostname, port=hostport, server=”paste”) -> -> You can see details of how to use other servers at [http://bottlepy.org/docs/dev/deployment.html][1]. - -#### Getting data from XBMC #### - -The XBMC JSON API is split up into 14 namespaces: JSONRPC, Player, Playlist, Files, AudioLibrary, VideoLibrary, Input, Application, System, Favourites, Profiles, Settings, Textures and XBMC. Each of these is available from an XBMC object in Python (apart from Favourites, in an apparent oversight). In each of these namespaces there are methods that you can use to control the application. For example, Playlist.GetItems() can be used to get the items on a particular playlist. The server returns data to us in JSON, but the xbmcjson module converts it to a Python dictionary for us. - -There are two items in XBMC that we need to use to control playback: players and playlists. Players hold a playlist and move through it item by item as each song finishes. In order to see what’s currently playing, we need to get the ID of the active player, and through that find out the ID of the current playlist. We’ve done this with the following function: - - def get_playlistid(): - player = xbmc.Player.GetActivePlayers() - if len(player[‘result’]) > 0: - playlist_data = xbmc.Player.GetProperties({“playerid”:0, “properties”:[“playlistid”]}) - if len(playlist_data[‘result’]) > 0 and “playlistid” in playlist_data[‘result’].keys(): - return playlist_data[‘result’][‘playlistid’] - return -1 - -If there isn’t a currently active player (that is, if the length of the results section in the returned data is 0), or if the current player has no playlist, this will return -1. Otherwise, it will return the numeric ID of the current playlist. - -Once we’ve got the ID of the current playlist, we can get the details of it. For our purposes, two things are important: the list of items in the playlist, and the position we are in the playlist (items aren’t removed from the playlist after they’ve been played; the current position just marches on). - - def get_playlist(): - playlistid = get_playlistid() - if playlistid >= 0: - data = xbmc.Playlist.GetItems({“playlistid”:playlistid, “properties”: [“title”, “album”, “artist”, “file”]}) - position_data = xbmc.Player.GetProperties({“playerid”:0, ‘properties’:[“position”]}) - position = int(position_data[‘result’][‘position’]) - return data[‘result’][‘items’][position:], position - return [], -1 - -This returns the current playlist starting with the item that’s currently playing (since we don’t care about stuff that’s finished), and it also includes the position as this is needed for removing items from the playlist. - -![Image](http://www.linuxvoice.com/wp-content/uploads/2015/04/xbmc2-large.jpg) - -The API is documented at [http://wiki.xbmc.org/?title=JSON-RPC_API/v6][2]. It lists all the available functions, but it a little short on details of how to use them. - -> ### JSON ### -> -> JSON stands for JavaScript Object Notation, and was originally designed as a way of serialising JavaScript Objects. It still is used for that, but it’s also a useful way of encoding all sorts of data. -> -> JSON objects always have the form: -> -> {property1:value1, property2:value2, property3:value3} -> -> For an arbitrary number of property/value pairs. To Python programmers, this all looks suspiciously similar to dictionaries, and the two are very similar. -> -> As with dictionaries, the value can itself be another JSON object, or a list, so the following is perfectly valid: -> -> {“name”:“Ben”, “jobs”:[“cook”, “bottle-washer”], “appearance”: {“height”:195, “skin”:“fair”}} -> -> JSON is often used in web services to send data back and fourth, and it’s well supported by most programming languages, so if Python’s not your thing, you should easily be able to use the same functions to control XBMC from software written in the language of your choice. - -#### Bringing them together #### - -The code to link the previous functions to a HTML page is simply: - - @route(‘/juke’) - def index(): - current_playlist, position = get_playlist() - return template(‘list’, playlist=current_playlist, offset = position) - -This only has to grab the playlist (using the function we defined above), and pass it to a template that handles the display. - -The main part of the template that handles the display of this data is: - -

Currently Playing:

- % if playlist is not None: - % position = offset - % for song in playlist: - {{song[‘title’]}} - % if song[‘type’] == ‘unknown’: - Radio - % else: - {{song[‘artist’][0]}} - % end - % if position != offset: - remove - % else: - skip - % end -
- % position += 1 - % end - -As you can see, templates are mostly written in HTML, but with a few extra bits to control output. Variables enclosed by double parenthesise are output in place (as we saw in the first ‘hello world’ example). You can also include Python code on lines starting with a percentage sign. Since indents aren’t used, you need a % end to close any code block (such as a loop or if statement). - -This template first checks that the playlist isn’t empty, then loops through every item on the playlist. Each item is displayed as the song title in bold, then the name of the artist, then a link to either skip it (if it’s the currently playing song), or remove it from the playlist. All songs have a type of ‘song’, so if the type is ‘unknown’, then it isn’t a song, but a radio station. - -The /remove/ and /skip/ routes are simple wrappers around XBMC controls that reload /juke after the change has taken effect: - - @route(‘/skip/’) - def index(position): - print xbmc.Player.GoTo({‘playerid’:0, ‘to’:’next’}) - redirect(“/juke”) - @route(‘/remove/’) - def index(position): - playlistid = get_playlistid() - if playlistid >= 0: - xbmc.Playlist.Remove({‘playlistid’:int(playlistid), ‘position’:int(position)}) - redirect(“/juke”) - -Of course, it’s no good being able to manage your playlist if you can’t add music to it. - -This is complicated slightly by the fact that once a playlist finishes, it disappears, so you need to create a new one. Rather confusingly, playlists are created by calling the Playlist.Clear() method. This can also be used to kill a playlist that is currently playing a radio station (where the type is unknown). The other complication is that radio streams sit in the playlist and never leave, so if there’s currently a radio station playing, we need to clear the playlist as well. - -These pages include a link to play the songs, which points to /play/. This page is handled by: - - @route(‘/play/’) - def index(id): - playlistid = get_playlistid() - playlist, not_needed= get_playlist() - if playlistid < 0 or playlist[0][‘type’] == ‘unknown’: - xbmc.Playlist.Clear({“playlistid”:0}) - xbmc.Playlist.Add({“playlistid”:0, “item”:{“songid”:int(id)}}) - xbmc.Player.open({“item”:{“playlistid”:0}}) - playlistid = 0 - else: - xbmc.Playlist.Add({“playlistid”:playlistid, “item”:{“songid”:int(id)}}) - remove_duplicates(playlistid) - redirect(“/juke”) - -The final thing here is a call to remove_duplicates. This isn’t essential – and some people may not like it – but it makes sure that no song appears in the playlist more than once. - -We also have pages that list all the artists in the collection, and list the songs and albums by particular artists. These are quite straightforward, and work in the same basic way as /juke. - -![Image](http://www.linuxvoice.com/wp-content/uploads/2015/04/xbmc1-large.jpg) - -The UI still needs a bit of attention, but it’s working. - -> ### Logging ### -> -> It’s not always clear how to do something using the XBMC JSON API, and the documentation is sometimes a little opaque. One way of finding out how to do something is seeing how other remote controls do it. If you turn on logging, you can see what API calls are being performed as you use another remote control, then incorporate these into your code. -> -> To turn on logging, hook your XBMC media centre up to a display and go to Settings > System > Debugging, and turn on Enable Debug Logging. With logging turned on, you need to access the XBMC machine (eg via SSH), then you can view the log. Its location should be displayed in the top-left corner of the XBMC display. In RaspBMC, it’s at /home/pi/.xbmc/temp/xbmc.log. You can then keep an eye on what API calls are being performed in real time using: -> -> cd /home/pi/.xbmc/temp -> tail -f xbmc.log | grep “JSON” - -#### Adding functionality #### - -The above code all works with songs in the XBMC library, but we also wanted to be able to play radio stations. Addons each have their own plugin URL that can be used to pull information out of them using the usual XBMC JSON commands. For example, to get the selected stations from the radio plugin, we use: - - @route(‘/radio/’) - def index(): - my_stations = xbmc.Files.GetDirectory({“directory”:”plugin://plugin.audio.radio_de/stations/my/”, “properties”: - [“title”,”thumbnail”,”playcount”,”artist”,”album”,”episode”,”season”,”showtitle”]}) - if ‘result’ in my_stations.keys(): - return template(‘radio’, stations=my_stations[‘result’][‘files’]) - else: - return template(‘error’, error=’radio’) - -This includes a file that can be added to a playlist just as any song can be. However, these files never finish playing, so (as we saw before) you need to recreate the playlist before adding any songs to it. - -#### Sharing songs #### - -As well as serving up templates, Bottle can serve static files. These are useful whenever you need things that don’t change based on the user input. That could be a CSS file, an image or an MP3. In our simple controller there’s not (yet) any CSS or images to make things look pretty, but we have added a way to download the songs. This lets the media centre act as a sort of NAS box for songs. If you’re transferring large amounts of data, it’s probably best to use something like Samba, but serving static files is a good way of grabbing a couple of tunes on your phone. - -The Bottle code to download a song by its ID is : - - @route(‘/download/’) - def index(id): - data = xbmc.AudioLibrary.GetSongDetails({“songid”:int(id), “properties”:[“file”]}) - full_filename = data[‘result’][‘songdetails’][‘file’] - path, filename = os.path.split(full_filename) - return static_file(filename, root=path, download=True) - -To use this, we just put a link to the appropriate ID in the /songsby/ page. - -We’ve gone through all the mechanics of the code, but there are a few more bits that just tie it all together. You can see for yourself at the GitHub page:[https://github.com/ben-ev/xbmc-remote][3]. - -> ### Setting up ### -> -> Once you’ve developed your remote control, you’ll need a way of ensuring that it starts every time you turn on your media centre. There are a few ways of doing this, but the easiest is just to add a command launching it to /etc/rc.local. We installed our file to /opt/xbmc-remote/remote.py with all the other files alongside it. We then added the following line to /etc/rc.local before the final exit 0 line. -> -> cd /opt/xbmc-remote && python remote.py & - -> ### GitHub ### -> -> This project is quite bare-bones at the moment, but – the business of running a magazine means we don’t have as much time as we’d like to program. However, we’ve set up a GitHub project where we hope to keep working on it, and if you think you’d benefit from the project as well, we’d love your input. -> -> To see what’s going on, head over to [https://github.com/ben-ev/xbmc-remote][4] and take a look at what state it’s in. You can get a copy of the latest code from that web page, or clone it from the command line. -> -> If you want to improve it, you can fork the project to develop in your own branch, and then send a pull request when your features are working. For more information on working with GitHub, head to [https://github.com/features][5]. - --------------------------------------------------------------------------------- - -via: http://www.linuxvoice.com/xbmc-build-a-remote-control/ - -作者:[Ben Everard][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://www.linuxvoice.com/author/ben_everard/ -[1]:http://bottlepy.org/docs/dev/deployment.html -[2]:http://wiki.xbmc.org/?title=JSON-RPC_API/v6 -[3]:https://github.com/ben-ev/xbmc-remote -[4]:https://github.com/ben-ev/xbmc-remote -[5]:https://github.com/features diff --git a/translated/share/20150604 12 Globally Recognized Linux Certifications.md b/translated/share/20150604 12 Globally Recognized Linux Certifications.md deleted file mode 100644 index 2be4e9df7d..0000000000 --- a/translated/share/20150604 12 Globally Recognized Linux Certifications.md +++ /dev/null @@ -1,172 +0,0 @@ -12个全球认可的Linux认证 -================================================================================ -大家好,今天我们将会认识一些非常有价值的全球认可的Linux认证。Linux认证是不同Linux专业机构在全球范围内进行的认证程序。Linux认证可以让Linux专业人才很容易获得Linux相关的工作,在服务器或者公司等等这些地方。Linux认证评估一个人在Linux的各个领域里的专业程度。有很多不错的Linux专业机构提供不同的Linux认证。但是全球仅有少数被十分认可的Linux认证,在公司谋取一份工作时含金量很高,这些工作包括管理服务器,虚拟化,安装系统与软件,配置程序,应用支持和其他Linux操作系统相关的东西。随着全球使用Linux操作系统的服务器的增长,拉动了对于Linux专业人才的需求。为了更好的证明Linux专业技术,公司进行的著名的认证一直有着更高的优先级,在全球看来。 - -这里是一些全球认可的Linux认证,我们接下来将会一一讨论。 - -### 1. CompTIA Linxu+ ### - -CompTIA Linux+ 是LPI“Linux Professional Institute”主办的一个Linux认证,在全世界范围内提供培训。其提供的Linux相关知识,使得产生了一大批Linux相关专业的工作,如Linux管理员,高级网络管理员,系统管理员,Linux数据库管理员和网页管理员。如果任何人想从事安装和维护Linux操作系统,该课程会帮助达到认证要求,并且通过提供对Linux系统更宽阔的认识,能够为考试做好准备。LPI的CompTIA Linux+认证的主要目的就是,提供给证书持有者足够扎实的知识,关于安装软件,操作,管理和设备排障的。我们可以用一定的费用,时间和努力,,完成CompTIA Linux+,赢得三个业内认可的证书,我们可以自动收到**LPI LPIC-1**和**SUSE Certified Linux Administrator (CLA)**证书。 - -- ** 认证代码** : LX0-103和LX0-104 (2015年三月30日启动)或者LX0-101和LX0-102 -- 题目数量:一次考试60道题 -- 题目类型:多选 -- 考试时长:90分钟 -- 要求:A+,Network+,并且有至少12个月的Linux管理经历 -- 分数线:500 (对于200-800的范围来说) -- 语言:英语,将来会有德语,葡萄牙语,汉语,西班牙。 -- 有效期:认证后三年有效 - -**注意**:不同系列的考试不能交叉。如果你考的是LX0-101,那么你必须考LX0-102完成认证。同样的,你必须考完LX0-103和LX0-104。LX0-103和LX0-104是LX0-101和LX0-102的升级版。 - -### 2. LPIC ### - -LPIC,全称Linux专业委员会认证,是Linux专业委员会的一个Linux认证程序。这是一个多层次的认证程序,要求在每个级别通过一系列(通常是两个)的认证考试。该认证有三个层次,包括初级水平认证 **LPIC-1** ,高级水平认证 **LPIC-2**和最高水平认证 **LPIC-3**。前两个认证侧重于 **Linux系统管理**,而最后一个认证侧重一些专业技能,包括虚拟化和安全。为了得到 **LPIC-3** 认证,一个持有 **LPIC-1** 与**LPIC-2** 的考生必须通过300复杂环境测试,303安全测试,304虚拟化测试和高可用性的其中一个。**LPIC-1**认证按照证书持有者可以通过运行Linux,使用命令行界面和基本的网络知识安装,维护,配置任务而设计,LPIC-2验证考生很少的管理知识,主要是中型混合网络方面。LPIC-3认证按照企业级别的Linux专业技能设计,代表了最高的专业水平(==最后这句不知道如何翻译==) - -- **认证代码**:LPIC-1(101和102),LPIC-2(201和202)和LPIC-3(300,303或者304) -- 题目类型:60个多项选择 -- 考试时长:90分钟 -- 要求:Linux基础 -- 分数线:500(在200-800的范围内) -- 语言:LPIC-1:英语,德语,意大利语,葡萄牙语,西班牙语(现代),汉语(简体),汉语(繁体),日语 -- LPIC-2:英语,德语,葡萄牙语,日语 -- LPIC-3:英语,日语 -- 有效期:退休之后五年内仍然有效 - -### 3.Oracle Linux OCA ### - -Oracle联合认证(OCA)为个人而定制,那些对部署和管理Oracle Linux操作系统且想证明知识牢固感兴趣的人。该认证专业知识仅仅是在Oracle Linux发行版上,这个系统完全是为Oracle产品特别剪裁的,为了运行在Oracle设计的系统上面,包括Oracle Exadata数据库机器,Oracle Exalytics 内存中机器,Oracle Exalogic 均衡云,和Oracle数据库应用。Oracle Linux稳定的企业级内核对于企业应用表现突出,高扩展性和稳定性。OCA认证覆盖如管理本地磁盘设备,文件系统,安装和移除Solaris包与补丁,协调系统启动过程和系统进程方面。这是达到OCP证书佼佼者的第一步。OCA认证以其前身为Sun Certified Solaris Associate(SCSAS)而为人所知。 - -- **认证代码**:OCA -- 题目类型:75道多项选择 -- 考试时长:120分钟 -- 要求:无 -- 分数线:64% -- 有效期:永远有效 - -### 4. Oracle Linux OCP ### - -Oracle Certified Professional(OCP),时Oracle公司为Oracle Linux提供的一个认证,覆盖更多的进阶知识和技能,对于一个Oracle Linux管理员来说。它囊括的知识有配置网络接口,映射交换配置,清理垃圾,管理软件、数据库和核心文件。OCP认证是技术性专业知识和专业技能的基准测试,这些知识与技能需要在公司里广泛用于开发,部署和管理应用,中间设备和数据库。Oracle Linux OCP的工作机会在增长,得益于工作市场和经济。根据考试纲领,证书持有者有能力胜任安全管理,为Oracle 数据库准备Oracle Linux系统,排除故障,安装软件包,安装和配置内核模块,维护交换空间,完成用户和组管理,创建文件系统,配置逻辑卷管理(LVM)、文件分享服务等等。 - -- **认证代码**:OCP -- 题目类型:60至80道多项选择题 -- 考试时长:120分钟 -- 要求:Oracle Linux OCA -- 分数线:64% -- 有效期:永远有效 - -### 5. RHCSA ### - -RHCSA是红帽公司作为红帽认证系统工程师推出的一个认证程序。RHCSAs指一些拥有技能和能力在著名的红帽Linux环境下完成核心系统管理的人。这是一个入门级的认证程序,关注在系统管理上的实际胜任能力,包括安装、配置一个红帽Linux系统,接入一个可用的网络运行网络服务。一个红帽认证的系统管理员可以理解和使用基本的工具,用以处理文件,目录,命令行环境和文档,操作运行中的系统,包括以不同的启动级别启动,标记进程,开启和停止虚拟机和控制服务,使用分区和逻辑卷配置本地存储,部署配置和维护系统,包括软件安装、更新和核心服务,管理用户和组,包括使用一个中心的目录用于验证,安全性工作,包括基本的基本防火墙和SELinux配置。要获得RHCE和其他认证,首先得认证过RHCSA。 - -- **认证代码**:RHCSA -- 课程代码:RH124,RH134和RH199 -- 考试代码:EX200 -- 考试时长:21-22小时,取决于选择的课程 -- 要求:无。有一些Linux基础知识更好 -- 分数线:300总分,210过(70%) -- 有效期:3年 - -### 6. RHCE ### - -RHCE,也叫做红帽认证工程师,是一个中到高级水平的认证程序,为一些红帽认证系统管理员(RHCSA),想学习一个负责红帽企业Linux的高级系统管理员要求的额外技能和知识而开设的,RHCE有能力,知识和技能配置静态的路由,包过滤,网络地址转换(NAT),设定内核运行参数,配置一个互联网小型计算机系统接口(ISCSI)初始化程序,产生并推送系统使用的报告,使用shell脚本自动完成系统维护任务,配置系统登入,包括远程登录,提供网络服务如HTTP/HTTPS,文件传输协议(FTP),网络文件系统(NFS),服务信息块(SMB),简单邮件传输协议(SMTP),安全shell(SSH)和网络时间协议(NTP)等等。RHCSAs希望获得更多高级水平的认证,并且已经完成系统管理员I,II和III,或者RHCE认证建议的RHCE快速跟进课程。 - -- **认证代码**:RHCE -- 课程代码:RH124,RH134,RH254和RH199 -- 考试代码:EX200和EX300 -- 考试时长:21-22个小时,取决于所选课程 -- 要求:一个RHCSA证书 -- 分数线:300总分,210过(70%) -- 有效期:3年 - -### 7. RHCA ### - -RHCA就是红帽认证架构师,是红帽公司的一个认证程序。它的关注点在系统管理的实际能力,包括安装和配置一个红帽Linux系统,并加入到一个可用网络中运行网络服务。RHCA是所有红帽认证中最高水平的认证。考生需要选择他们希望关注的集合,或者选择合格的红帽认证的任意组合,以此来创建一个他们自己的集合。这里有三个主要的集合,数据中心,云和应用平台。精通数据中心集合的RHCA能够运行,管理数据中心,而熟悉云的可以创建,配置和管理私有的,混合的云,云应用平台以及使用红帽企业Linux平台的灵活存储方案。精通应用平台集合的RHCA拥有技能如安装,配置和管理红帽JBoss企业应用平台和应用,云应用平台和混合云环境,借助红帽的OpenShift企业版,使用红帽JBoss数据虚拟化技术从多个资源里组合数据。 - -- **认证代码**:RHCA -- 课程代码:CL210,CL220.CL280,RH236,RH318,RH413,RH436,RH442,JB248和JB450 -- 考试代码:EX333,EX401,EX423或者EX318,EX436和EX442 -- 考试时长:21-22个小时,取决于所选课程 -- 要求:未过期的RHCE证书 -- 分数线:300总分,210过(70%) -- 有效期:3年 - -### 8. SUSE CLA ### - -SUSE认证Linux管理员(SUSE CLA)是SUSE推出的一个初级认证,关注点在SUSE Linux企业服务器环境下的日常任务管理。为了获得SUSE CLA认证,完成课程任务不是必须的,你不得不通过考试获得认证。SUSE CLA有能力,也有技术去使用Linux桌面,定位并利用帮助资源,管理Linux文件系统,用Linux Shell和命令行工作,安装SLE 11 SP22,管理系统安装,硬件,备份和恢复,用YaST管理Linux,Linux进程和服务,存储,配置网络,远程接入,SLE 11 SP2模拟器,任务自动化和管理用户访问和安全工作。我们可以同时获得LPI的SUSE CLA,LPIC-1和CompTIA Linux,因为SUSE,Linux Professional Institute和CompATI合作提供给你这个机会,去获得三个Linux认证。 - -- **认证代码**:SUSE CLA -- 课程代码:3115,3116 -- 考试代码:050-720,050-710 -- 问题类型:多项选择 -- 考试时长:90分钟 -- 要求:无 -- 分数线:512 - -### 9. SUSE CLP ### - -SUSE认证Linux专业人员(CLP)是一个认证程序,为那些希望获得关于SUSE Linux企业服务器更多高级且专业的知识的人而服务。SUSE CLP是通过SUSE CLA认证后的下一步。一个人应该通过CLA的考试并拥有证书,然后才能获得CLP的认证,通过完成CLP的考试。通过SUSE CLP认证的人员有能力完成安装和配置SUSE Linux企业服务器11系统,维护文件系统,管理软件包,进程,打印,使用IPv6配置基础网络服务,samba,网页服务器,创建和运行bash shell脚本。 - -- **认证代码**:SUSE CLP -- 课程代码:3115,3116和3117 -- 考试代码:050-721,050-697 -- 考试类型:手写 -- 考试时长:180分钟 -- 要求:SUSE CLA 认证 - -### 10. SUSE CLE ### - -SUSE认证Linux工程师(CLE)是一个工程师级别的高级认证,为那些已经通过CLE考试的人准备。为了获得CLE认证,人们需要获得SUSE CLA和CLP的认证。获得CLE认证的人员拥有架设复杂SUSE Linux企业服务器环境的技能。CLE认证过的人可以配置基本的网络服务,管理打印,配置和使用Open LDAP,samba,IPv6,完成健康检测和(这里不知道),创建和执行shell脚本,部署SUSE Linux企业板,通过Xen实现虚拟化等等。 - -- **认证代码**:SUSE CLE -- 课程代码:3107 -- 考试代码:050-723 -- 考试类型:手写 -- 考试时长:120分钟 -- 要求:SUSE CLP 10或者11证书 - -### 11. LFCS ### - -Linux基金会认证系统管理员(LFCS)认证考生Linux使用中拥有的知识和通过终端环境使用Linux。LFCS是Linux基金会的一个认证程序,为使用Linux操作系统工作的系统管理员和工程师准备。Linux基金会联合工业级专家,Linux内核社区,测试考生扎实的技能,知识和应用能力。通过LFCS认证的人员拥有一些技能,知识和能力,包括在命令行下编辑和操作文件,管理和处理文件系统与存储的错误,聚合分区作为LVM设备,配置SWAP分区,管理网络文件系统,管理用户帐号,权限和属组,创建并执行bash shell脚本,安装,升级,移除软件包等等。 - -- **认证代码**:LFCS -- 课程代码:LFCS201,LFCS220(可选) -- 考试代码:LFCS 考试 -- 考试时长:2小时 -- 要求:无 -- 分数线:74% -- 语言:英语 -- 有效期:两年 - -### 12. LFCE ### - -Linux基金会认证工程师(LFCE),是Linux基金会为Linux工程师推出的认证。通过LFCE认证的人员拥有一个对于Linux较宽范围的技能,相比于LFCS。这是一个工程师级别的高级认证程序。LFCE认证的人具备一些网络管理方面的技能和能力,如配置网络服务,包过滤,网络运行模拟器,IP连通,配置文件系统和文件服务,网络文件系统,从仓库安装,升级软件包,管理网络安全,配置iptables,http服务,代理服务,邮件服务等等。由于其为高级工程级别的认证程序,所以普遍认为相比LFCS,学习和通过的难度更大些。 - -- **认证代码**:LFCE -- 课程代码:LFS230 -- 考试代码:LFCE 考试 -- 考试时长:2小时 -- 要求:认证过LFCS -- 分数线:72% -- 语言:英语 -- 有效期:2年 - -### 我们发现的情况(这仅仅是我们的观点)### - -最近的调查表明,在不同的高端招聘代理中,称80%的Linux工作描述更倾向于红帽的认证。如果你是一个学生/新手,并且想学习Linux,那么我们建议选择越来越流行的Linux基金会认证,或者CompTIA Linux也可以是一个选择。如果你已经知道了oracle或suse,或者在他们的产品上工作,那oracle/suse的认证会更好些,如果你在一个公司工作了,这些认证会对你的职业生涯成长有帮助:-) - -### 总结 ### - -在这个世界上,成千上万的大公司正在运行跑着Linux操作系统的服务器和主框架,为了在这些服务器上管理,配置和工作,总是存在对Linux技术/专业知识高度认证的需求。这些国际上承认的认证对某些人在Linux的职业生涯扮演很重要的角色。全世界范围内的这些公司运行着Linux,需要Linux工程师,系统管理员和已经获得认证且在Linux相关领域干得不错的有热情的人员。全球认可的Linux认证,对于专业知识和职业生涯的辉煌都是很基础的,所以好好准备考试并获得认证,对于在Linux建立职业生涯是一个很好的选择。如果你有任何问题,想法,反馈,请写在下方的评论框里,让我们好知道哪些东西需要添加或者改进。谢谢!:-) - --------------------------------------------------------------------------------- - -via: http://linoxide.com/linux-how-to/12-globally-recognized-linux-certifications/ - -作者:[Arun Pyasi][a] -译者:[译者ID](https://github.com/wi-cuckoo) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://linoxide.com/author/arunp/ diff --git a/translated/tech/20150616 XBMC--build a remote control.md b/translated/tech/20150616 XBMC--build a remote control.md new file mode 100644 index 0000000000..7347aca243 --- /dev/null +++ b/translated/tech/20150616 XBMC--build a remote control.md @@ -0,0 +1,264 @@ +XBMC:自制遥控 +================================================================================ +**通过运行在 Android 手机上的自制遥控器来控制你的家庭媒体播放器。** + +**XBMC** 一款很优秀的软件,能够将几乎所有电脑变身成媒体中心。它可以播放音乐和视频,显示图片,甚至还能显示天气预报。为了在配置成家庭影院后方便使用,你可以通过手机 app 访问运行在已连接到 Wi-Fi 的 XBMC 机器上的服务来控制它。可以找到很多这种工具,几乎覆盖所有智能手机系统。 + +> ### Kodi ### +> +> 在你阅读这篇文章的时候,**XBMC** 可能已经成为历史。因为法律原因(因为名字 **XBMC** 或 X**-Box Media Center** 里引用了不再支持的过时硬件)项目组决定使用新的名字 **Kodi**。不过,除了名字,其他的都会保持原样。或者说除开通常新版本中所期待的大量新改进。这一般不会影响到遥控软件,它应该能在已有的 **XBMC** 系统和新的 Kodi 系统上都能工作。 + +我们目前配置了一个 **XBMC** 系统用于播放音乐,不过我们找到的所有 XBMC 遥控没一个好用的,特别是和媒体中心连接的电视没打开的时候。它们都有点太复杂了,集成了太多功能在手机的小屏幕上。我们希望能有这样的系统,从最开始就是设计成只用于访问音乐库和电台插件,所以我们决定自己实现一个。它不需要用到 XBMC 的所有功能,因为除了音乐以外的任务,我们可以简单地切换使用通用的 XBMC 遥控。我们的测试系统是一个刷了 RaspBMC 发行版的树莓派,但是我们要做的工具并不受限于树莓派或那个发行版,它应该可以匹配任何安装了相关插件的基于 Linux 的 XBMC 系统。 + +首先,遥控程序需要一个用户界面。大多数 XBMC 遥控程序都是独立的 app。不过对于我们要做的这个音乐控制程序,我们希望用户可以不用安装任何东西就可以使用。显然我们需要使用网页界面。XBMC 本身自带网页服务器,但是为了获得更多权限,我们还是使用了独立的网页框架。在同一台电脑上跑两个以上网页服务器没有问题,只不过它们不能使用相同的端口。 + +有几个网页框架可以使用。而我们选用 Bottle 是因为它是一个简单高效的框架,而且我们也确实用不到任何高级功能。Bottle 是一个 Python 模块,所以这也将是我们编写服务器模块的语言。 + +你应该能在软件包管理器里找到 Bottle。在基于 Debian 的系统(包括 RaspBMC)里,你可以通过下面的命令安装: + + sudo apt-get install python-bottle + +遥控程序实际上只是连接用户和系统的中间层。Bottle 提供了和用户交互的方式,而我们将通过 JSON API 来和 **XBMC** 交互。这样可以让我们通过发送 JSON 格式消息的方式去控制媒体播放器。 + +我们将用到一个叫做 xbmcjson 的简单 XBMC JASON API 封装。足够用来发送控制请求,而不需要关心实际的 JSON 格式以及和服务器通讯的无聊事。它没有包含在 PIP 包管理中,所以你得直接从 **GitHub** 安装: + + git clone https://github.com/jcsaaddupuy/python-xbmc.git + cd python-xbmc + sudo python setup.py install + +万事俱备,只欠代码。 + +#### 先从 Bottle 开始 #### + +我们程序的基本结构: + + from xbmcjson import XBMC + from bottle import route, run, template, redirect, static_file, request + import os + xbmc = XBMC(“http://192.168.0.5/jsonrpc”, “xbmc”, “xbmc”) + @route(‘/hello/’) + def index(name): + return template(‘

Hello {{name}}!

’, name=name) + run(host=”0.0.0.0”, port=8000) + +这样程序将连接到 **XBMC**(不过实际上用不到);然后 Bottle 会开始伺服网站。在我们的代码里,它将监听主机 0.0.0.0(意味着允许所有主机连接)的端口 8000。它只设定了一个站点,就是 /hello/XXXX,这里的 XXXX 可以是任何内容。不管 XXXX 是什么都将作为参数名传递给 index()。然后再替换进去 HTML 网页模版。 + +你可以先试着把上面内容写到一个文件(我们取的名字是 remote.py),然后用下面的命令启动: + + python remote.py + +然后你可以在浏览器里访问 localhost:8000/hello/world 看看模版生效的效果。 + +@route() 用来设定网页服务器的路径,而函数 index() 会返回该路径的数据。通常是返回由模版生成的 HTML 页面,但是并不是说只能这样(后面会看到)。 + +随后,我们将给应用添加更多页面入口,让它变成一个全功能的 XBMC 遥控,但仍将采用相同代码结构。 + +XBMC JSON API 接口可以从和 XBMC 机器同网段的任意电脑上访问。也就是说你可以在自己的笔记本上开发,然后再布置到媒体中心上,而不需要浪费时间上传每次改动。 + +模版 - 比如前面例子里的那个简单模版 - 是一种结合 Python 和 HTML 来控制输出的方式。理论上,这俩能做很多很多事,但是会非常混乱。我们将只是用它们来生成正确格式的数据。不过,在开始动手之前,我们先得准备点数据。 + +> ### Paste ### +> +> Bottle 自带网页服务器,就是我们用来测试遥控程序的。不过,我们发现它性能有时不够好。当我们的遥控程序正式上线时,我们希望页面能更快一点显示出来。Bottle 可以和很多不同的网页服务器配合工作,而我们发现 Paste 用起来非常不错。而要使用的话,只要简单地安装(Debian 系统里的 python-paste 包),然后修改一下代码里的 run 调用: +> +> run(host=hostname, port=hostport, server=”paste”) +> +> 你可以在 [http://bottlepy.org/docs/dev/deployment.html][1] 找到如何使用其他服务器的相关细节。 + +#### 从 XBMC 获取数据 #### + +XBMC JSON API 分成 14 个命名空间:JSONRPC, Player, Playlist, Files, AudioLibrary, VideoLibrary, Input, Application, System, Favourites, Profiles, Settings, Textures 和 XBMC。每个都可以通过 Python 的 XBMC 对象访问(Favourites 除外,明显是个疏忽)。每个命名空间都包含许多方法用于对程序的控制。例如,Playlist.GetItems() 可以用来获取某个特定播放列表的内容。服务器会返回给我们 JSON 格式的数据,但 xbmcjson 模块会为我们转化成 Python 词典。 + +我们需要用到 XBMC 里的两个组件来控制播放:播放器和播放列表。播放器带有播放列表并在每首歌结束时从列表里取下一首。为了查看当前正在播放的内容,我们需要获取正在工作的播放器的 ID,然后根据它找到当前播放列表的 ID。这个可以通过下面的代码来实现: + + def get_playlistid(): + player = xbmc.Player.GetActivePlayers() + if len(player[‘result’]) > 0: + playlist_data = xbmc.Player.GetProperties({“playerid”:0, “properties”:[“playlistid”]}) + if len(playlist_data[‘result’]) > 0 and “playlistid” in playlist_data[‘result’].keys(): + return playlist_data[‘result’][‘playlistid’] + return -1 + +如果当前没有播放器在工作(就是说,返回数据的结果部分的长度是 0),或者当前播放器不带播放列表,这样的话函数会返回 -1。其他时候,它会返回当前播放列表的数字 ID。 + +当我们拿到当前播放列表的 ID 后,就可以获取列表的细节内容。按照我们的需求,有两个重要的地方:播放列表里包含的项,以及当前播放所处的位置(已经播放过的项并不会从播放列表移除,只是移动当前播放位置)。 + + def get_playlist(): + playlistid = get_playlistid() + if playlistid >= 0: + data = xbmc.Playlist.GetItems({“playlistid”:playlistid, “properties”: [“title”, “album”, “artist”, “file”]}) + position_data = xbmc.Player.GetProperties({“playerid”:0, ‘properties’:[“position”]}) + position = int(position_data[‘result’][‘position’]) + return data[‘result’][‘items’][position:], position + return [], -1 + +这样可以返回以正在播放的项开始的列表(因为我们并不关心已经播放过的内容),而且也包含了位置信息用来从列表里移除项。 + +![Image](http://www.linuxvoice.com/wp-content/uploads/2015/04/xbmc2-large.jpg) + +API 文档在这里:[http://wiki.xbmc.org/?title=JSON-RPC_API/v6][2]。它列出了所有支持的函数,但是关于具体如何使用的描述有点太简单了。 + +> ### JSON ### +> +> JSON 是 JavaScript Object Notation 的缩写,开始设计用于 JavaScript 对象的序列化。目前仍然起到这个作用,但是它也是用来编码任意数据的一种很好用的方式。 +> +> JSON 对象都是这样的格式: +> +> {property1:value1, property2:value2, property3:value3} +> +> 支持任意数目的属性/值配对。对 Python 程序员来说,看上去和字典数据结构很相似,不过这两个确实很像。 +> +> 在字典数据结构里,值本身可以是另一个 JSON 对象,或者一个列表,所以下面的格式也是正确的: +> +> {“name”:“Ben”, “jobs”:[“cook”, “bottle-washer”], “appearance”: {“height”:195, “skin”:“fair”}} +> +> JSON 通常在网络服务中用来发送和接收数据,并且大多数编程语言都能很好地支持,所以如果你熟悉 Python 的话,你应该可以使用你熟悉的编程语言调用相同的接口来轻松地控制 XBMC。 + +#### 整合到一起 #### + +把之前的功能连接到 HTML 页面很简单: + + @route(‘/juke’) + def index(): + current_playlist, position = get_playlist() + return template(‘list’, playlist=current_playlist, offset = position) + +只需要抓取播放列表(调用我们之前定义的函数),然后将结果传递给负责显示的模版。 + +负责显示列表数据的模版的主要部分是: + +

Currently Playing:

+ % if playlist is not None: + % position = offset + % for song in playlist: + {{song[‘title’]}} + % if song[‘type’] == ‘unknown’: + Radio + % else: + {{song[‘artist’][0]}} + % end + % if position != offset: + remove + % else: + skip + % end +
+ % position += 1 + % end + +可以看到,模版大部分是用 HTML 写的,只有一小部分用来控制输出的其他代码。用两个括号括起来的变量是输出位置(像我们在第一个 ‘hello world’ 例子里看到的)。你也可以嵌入以百分号开头的 Python 代码。因为没有缩进,你需要用一个 % end 来结束当前的代码块(就像循环或 if 语句)。 + +这个模版首先检查列表是否为空,然后遍历里面的每一项。每一项会用粗体显示歌曲名字,然后是艺术家名字,然后是一个是否跳过(如果是当前正在播的歌曲)或从列表移除的链接。所有歌曲的类型都是 ‘song’,如果类型是 ‘unknown’,那就不是歌曲而是网络电台。 + +/remove/ 和 /skip/ 路径只是简单地封装了 XBMC 控制功能,在改动生效后重新加载 /juke: + + @route(‘/skip/’) + def index(position): + print xbmc.Player.GoTo({‘playerid’:0, ‘to’:’next’}) + redirect(“/juke”) + @route(‘/remove/’) + def index(position): + playlistid = get_playlistid() + if playlistid >= 0: + xbmc.Playlist.Remove({‘playlistid’:int(playlistid), ‘position’:int(position)}) + redirect(“/juke”) + +当然,如果不能往列表里添加歌曲的话那这个列表管理功能也不行。 + +因为一旦播放列表结束,它就消失了,所以你需要重新创建一个,这会让事情复杂一些。而且有点让人迷惑的是,播放列表是通过调用 Playlist.Clear() 方法来创建的。这个方法也还用来删除包含网络电台(类型是 unknown)的播放列表。另一个麻烦的地方是列表里的网络电台开始播放后就不会停,所以如果当前在播网络电台,也会需要清除播放列表。 + +这些页面包含了指向 /play/ 的链接来播放歌曲。通过下面的代码处理: + + @route(‘/play/’) + def index(id): + playlistid = get_playlistid() + playlist, not_needed= get_playlist() + if playlistid < 0 or playlist[0][‘type’] == ‘unknown’: + xbmc.Playlist.Clear({“playlistid”:0}) + xbmc.Playlist.Add({“playlistid”:0, “item”:{“songid”:int(id)}}) + xbmc.Player.open({“item”:{“playlistid”:0}}) + playlistid = 0 + else: + xbmc.Playlist.Add({“playlistid”:playlistid, “item”:{“songid”:int(id)}}) + remove_duplicates(playlistid) + redirect(“/juke”) + +最后一件事情是实现 remove_duplicates 调用。这并不是必须的 - 而且还有人并不喜欢这个 - 不过可以保证同一首歌不会多次出现在播放列表里。 + +我们也实现了一些页面用来列出收藏歌曲里所有艺术家,以及列出指定艺术家的歌曲和专辑。这些都非常简单,和 /juke 页面基本类似。 + +![Image](http://www.linuxvoice.com/wp-content/uploads/2015/04/xbmc1-large.jpg) + +还需要处理一下 UI,不过功能已经有了。 + +> ### 日志 ### +> +> 通常拿到 XBMC JSON API 并不清楚能用来做什么,而且它的文档也有点模糊。找出如何使用的一种方式是看别的遥控程序是怎么做的。如果打开日志功能,就可以在使用其他遥控程序的时候看到哪个 API 被调用了,然后就可以应用到在自己的代码里。 +> +> 要打开日志功能,把 XBMC 媒体中心 接到显示器上,再依次进入设置 > 系统 > 调试,打开允许调试日志。在打开日志功能后,还需要登录到 XBMC 机器上(比如通过 SSH),然后就可以查看日志了。日志文件的位置应该显示在 XBMC 界面左上角。在 RaspBMC 系统里,文件位置是 /home/pi/.xbmc/temp/xbmc.log。你可以通过下面的命令实时监视哪个 API 接口被调用了: +> +> cd /home/pi/.xbmc/temp +> tail -f xbmc.log | grep “JSON” + +#### 增加功能 #### + +上面的代码都是用来播放 XBMC 媒体库里的歌曲的,但我们还希望能播放网络电台。每个插件都有自己的独立 URL 可以通过普通的 XBMC JSON 命令来获取信息。举个例子,要从电台插件里获取选中的电台,可以使用; + + @route(‘/radio/’) + def index(): + my_stations = xbmc.Files.GetDirectory({“directory”:”plugin://plugin.audio.radio_de/stations/my/”, “properties”: + [“title”,”thumbnail”,”playcount”,”artist”,”album”,”episode”,”season”,”showtitle”]}) + if ‘result’ in my_stations.keys(): + return template(‘radio’, stations=my_stations[‘result’][‘files’]) + else: + return template(‘error’, error=’radio’) + +这样可以返回一个可以和歌曲一样能添加到播放列表的文件。不过,这些文件能一直播下去,所以(之前说过)在添加其他歌曲的时候需要重新创建列表。 + +#### 共享歌曲 #### + +除了伺服页面模版,Bottle 还支持静态文件。方便用于那些不会因为用户输入而改变的内容。可以是 CSS 文件,一张图片或是一首 MP3 歌曲。在我们的简单遥控程序里(目前)还没有任何用来美化的 CSS 或图片,不过我们增加了一个下载歌曲的途径。这个可以让媒体中心变成一个存放歌曲的 NAS 盒子。在需要传输大量数据的时候,最好还是用类似 Samba 的功能,但只是下几首歌到手机上的话使用静态文件也是很好的方式。 + +通过歌曲 ID 来下载的 Bottle 代码: + + @route(‘/download/’) + def index(id): + data = xbmc.AudioLibrary.GetSongDetails({“songid”:int(id), “properties”:[“file”]}) + full_filename = data[‘result’][‘songdetails’][‘file’] + path, filename = os.path.split(full_filename) + return static_file(filename, root=path, download=True) + +应用的时候,只需要为 /songsby/ 页面里的相应 ID 加个链接。 + +我们已经把所有的代码过了一遍,不过还需要一点工作来把它们集合到一起。可以自己去 GitHub 页面 [https://github.com/ben-ev/xbmc-remote][3] 看下。 + +> ### 设置 ### +> +> 我们的遥控程序已经开发完成,还需要保证让它在媒体中心每次开机的时候都能启动。有几种方式,最简单的是在 /etc/rc.local 里增加一行命令来启动。我们的文件位置在 /opt/xbmc-remote/remote.py,其他文件也和它一起。然后在 /etc/rc.local 最后的 exit 0 之前增加了下面一行。 +> +> cd /opt/xbmc-remote && python remote.py & + +> ### GitHub ### +> +> 这个项目目前还只是个架子,但是 - 我们运营杂志就意味着没有太多自由时间来编程。不过,我们启动了一个 GitHub 项目,希望能持续完善, 而如果你觉得这个项目有用的话,欢迎做出贡献。 +> +> 要查看最新的进展,请访问 [https://github.com/ben-ev/xbmc-remote][4] 看看所处的状态。你可以从页面里获取最新的代码,或者通过命令行复制。 +> +> 如果你希望改善它,可以复制项目到你自己的分支开发,然后在功能完成后发起合并请求。关于如何使用 GitHub 的更多信息,请访问 [https://github.com/features][5]。 + +-------------------------------------------------------------------------------- + +via: http://www.linuxvoice.com/xbmc-build-a-remote-control/ + +作者:[Ben Everard][a] +译者:[zpl1025](https://github.com/zpl1025) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.linuxvoice.com/author/ben_everard/ +[1]:http://bottlepy.org/docs/dev/deployment.html +[2]:http://wiki.xbmc.org/?title=JSON-RPC_API/v6 +[3]:https://github.com/ben-ev/xbmc-remote +[4]:https://github.com/ben-ev/xbmc-remote +[5]:https://github.com/features