Single Column rpm command output - ruby

I have an application where I want to get the RPM info of several packages and format it in a pleasing and eye-catching way. *boom*.
My problem is that rpm wants to format the data into two columns, which is annoying.
Command
rpm -qi ruby
Result
Name : ruby Relocations: (not relocatable)
Version : 1.8.6.36 Vendor: (none)
Release : 2 Build Date: Thu 18 Sep 2008 10:50:30 AM EDT
Install Date: Thu 25 Sep 2008 12:12:53 PM EDT Build Host: kickbench
Group : Development/Languages Source RPM: ruby-1.8.6.36-2.src.rpm
Size : 1664035 License: Ruby License/GPL - see COPYING
Signature : (none)
URL : http://www.ruby-lang.org/
Summary : An interpreter of object-oriented scripting language.
Description : [truncated]
What I want
Name : ruby
Relocations : (not relocatable)
Version : 1.8.6.36
Vendor : (none)
Release : 2
Build Date : Thu 18 Sep 2008 10:50:30 AM EDT
Install Date: Thu 25 Sep 2008 12:12:53 PM EDT
Build Host : kickbench
Group : Development/Languages
Source RPM : ruby-1.8.6.36-2.src.rpm
Size : 1664035
License : Ruby License/GPL - see COPYING
Signature : (none)
URL : http://www.ruby-lang.org/
Summary : An interpreter of object-oriented scripting language.
Description : [truncated]
Is there any way to get this formatting without manually specifying a reaally long --queryformat?
Alternatively, any way to do this native to Ruby would be fine.

pairs = %x{rpm -qi ruby}
.split(/(?<!:)\s{2,}(?![\s:])|#$//)
.map{|line| line.split(/\s*:\s+/, 2)}
width = pairs.map{|pair| pair.first.length}.max
pairs.each{|k, v| puts "#{k.ljust(width)}: #{v}"}

Related

Bash script for switching wallpaper in XFCE4

Can you help me with writing a bash script for switching wallpaper between day and night version under XFCE? I want to set a cron job for running it so it will switch automatically based on the time of the day.
I wrote a script:
#!/bin/bash
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/workspace0/last-image -s /home/maciek/Pictures/day.jpg
It works when I run it from a terminal. But when I set it up in cron it doesn't work. I get an error:
Failed to init libxfconf: Using X11 for dbus-daemon autolaunch was disabled at compile time, set your DBUS_SESSION_BUS_ADDRESS instead.
Some info:
Name : xfce4-session
Version : 4.12.1-7
Description : A session manager for Xfce
Architecture : x86_64
URL : http://www.xfce.org/
Licenses : GPL2
Groups : xfce4
Provides : None
Depends On : libxfce4ui libwnck libsm polkit xorg-iceauth xorg-xinit xorg-xrdb
polkit-gnome hicolor-icon-theme
Optional Deps : gnome-keyring: for keyring support when GNOME compatibility is enabled
xscreensaver: for locking screen with xflock4
gnome-screensaver: for locking screen with xflock4
xlockmore: for locking screen with xflock4
slock: for locking screen with xflock4
Required By : None
Optional For : None
Conflicts With : None
Replaces : xfce-utils
Installed Size : 1972.00 KiB
Packager : Evangelos Foutras <evangelos#foutrelis.com>
Build Date : Tue 27 Jun 2017 05:48:04 AM CEST
Install Date : Fri 21 Jul 2017 11:49:41 PM CEST
Install Reason : Explicitly installed
Install Script : No
Validated By : Signature
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

How to Backup & Restore ElasticSearch

I have been trying the following methods to Backup & Restore an ElasticSearch cluster from one server to another with little success. I have not used a backup process thus far and I would like to move my whole ElasticSearch cluster from a small 2GB cluster to 15GB cluster. I used the following methods.
Using taskrabit/elasticsearch-dump - I was successfully able to export the complete database to backup.json file, however when restoring the backup.json, it gave me the following output. After researching the output further I understood that the bulk input of the plug-in was not fully developed.
./bin/elasticdump --all=true --input=/home/user/backup.json --output=http://192.168.0.213:9200/ --type=data
Thu, 09 Feb 2017 06:43:29 GMT | starting dump
Thu, 09 Feb 2017 06:43:29 GMT | got 61 objects from source file (offset: 0)
Thu, 09 Feb 2017 06:43:29 GMT | sent 61 objects to destination elasticsearch, wrote 0
Thu, 09 Feb 2017 06:43:29 GMT | got 0 objects from source file (offset: 61)
Thu, 09 Feb 2017 06:43:29 GMT | Total Writes: 0
Thu, 09 Feb 2017 06:43:29 GMT | dump complete
Using elasticsearch-tools (es-export-bulk & es-import bulk) I again was able to backup the json successfully. But the import failed once again with an error:
"statusCode":400,"response":"{"error":{
I used the examples from es-bulk-export
Using the ElasticSearch built-in Snapshot & Restore.
curl -XPUT 'http://localhost:9200/_snapshot/my_backup' -d '{
"type": "fs",
"settings": {"location": "/home/shawn/backup", "compress": true}
}'
I believe I'm missing something as the execution gives me the following error. Do I need to create /_snapshot/my_backup? If so how?
{"error":{"root_cause":[
{"type":"repository_exception",
"reason":"[my_backup] location [/home/shawn/backup] doesn't match any of the locations specified by path.repo because this setting is empty"
}],
"type":"repository_exception","reason":"[my_backup] failed to create repository",
"caused_by":
{"type":"creation_exception","reason":"Guice creation errors:\n\n1) Error injecting constructor, RepositoryException[[my_backup] location [/home/shawn/backup] doesn't match any of the locations specified by path.repo because this setting is empty]\n at org.elasticsearch.repositories.fs.FsRepository.<init>(Unknown Source)\n while locating org.elasticsearch.repositories.fs.FsRepository\n while locating org.elasticsearch.repositories.Repository\n\n1 error","caused_by":{"type":"repository_exception","reason":"[my_backup] location [/home/shawn/backup] doesn't match any of the locations specified by path.repo because this setting is empty"}}},"status":500}
You are creating your _snapshot/my_backup just fine, You only need to add line to /etc/elasticsearch/elasticsearch.yml:
path.repo: ["/home/shawn/backup"]
Which is actual location of your snapshot. Then restart Elasticsearch.

Create patch under Windows

I want to create a patch for a header in order to fix my appveyor build. I used WinMerge to create the following file:
--- C:/Qt/5.3/mingw482_32/include/QtGui/qopengl.h Thu Jun 19 11:08:06 2014
+++ C:/Qt/5.3/mingw482_32/include/QtGui/qopengl2.h Sat Nov 08 11:20:32 2014
## -49,6 +49,7 ##
// Windows always needs this to ensure that APIENTRY gets defined
#if defined(Q_OS_WIN)
# include <QtCore/qt_windows.h>
+# undef MemoryBarrier
#endif
// Note: Mac OSX is a "controlled platform" for OpenGL ABI so we
When running the patch command I get the following result:
C:\Users\Martin\dev\TravisTest>patch -u patch_qopengl c:\Qt\5.3\mingw482_32\include\QtGui\qopengl.h
patch: **** Only garbage was found in the patch input.
What's wrong?

l10n support in ruby

I am able to parse localized dates using python locale module and posix localization database:
import locale, datetime
locale.setlocale(locale.LC_TIME, 'tr_TR.UTF-8')
print datetime.datetime.strptime("1 Haziran 2014", "%d %B %Y")
===
Edit
This example loads the locale and datetime modules, parses the localized date to create an instance of python's datetime class. I'm looking specifically for Ruby code that can parse localized dates using posix database.
===
Is there any equivalent of this in ruby? If there is a ruby library like python's locale module or Boost.Locale in C++, can you give example code? I tried the gettext gem and locale gem (I set current locale and tried Time.strptime, which failed).
I do not expect to do custom gsub or an i18n config file parsing. I am asking for code that uses posix database to parse dates.
You will need 2 custom gems in your Gemfile
Chronic:
$ git clone git://github.com/mojombo/chronic.git
$ cd chronic && gem build chronic.gemspec
$ gem install chronic-*.gem
Chronic-l10n:
$ git clone git://github.com/luan/chronic-l10n.git
$ cd chronic-l10n && gem build chronic-l10n.gemspec
$ gem install chronic-l10n-*.gem
Usage:
require 'chronic'
require 'chronic-l10n'
Time.now #=> Sun Aug 27 23:18:25 PDT 2006
Chronic.locale = :'pt-BR'
Chronic.parse('amanhã')
#=> Mon Aug 28 12:00:00 PDT 2006
Chronic.parse('segunda', :context => :past)
#=> Mon Aug 21 12:00:00 PDT 2006
Chronic.parse('essa terça 5:00')
#=> Tue Aug 29 17:00:00 PDT 2006
Chronic.parse('essa terça 5:00', :ambiguous_time_range => :none)
#=> Tue Aug 29 05:00:00 PDT 2006
Chronic.parse('27 de maio', :now => Time.local(2000, 1, 1))
#=> Sat May 27 12:00:00 PDT 2000
Chronic.parse('27 de maio', :guess => false)
#=> Sun May 27 00:00:00 PDT 2007..Mon May 28 00:00:00 PDT 2007
Chronic.parse('6/4/2012', :endian_precedence => :little)
#=> Fri Apr 06 00:00:00 PDT 2012
It seems there is currently no ruby gem or code that can load posix database and parse dates using strptime style flags. (copy-paste answer is not accepted)

How do I use the sed command to remove all lines between 2 phrases (including the phrases themselves)

I am generating a log from which I want to remove X startup output which looks like this:
X.Org X Server 1.7.6
Release Date: 2010-03-17
X Protocol Version 11, Revision 0
Build Operating System: Linux 2.6.31-607-imx51 armv7l Ubuntu
Current Operating System: Linux nvidia 2.6.33.2 #1 SMP PREEMPT Mon May
31 21:38:29 PDT 2010 armv7l
Kernel command line: mem=448M#0M nvmem=64M#448M mem=512M#512M
chipuid=097c81c6425f70d7 vmalloc=320M video=tegrafb
console=ttyS0,57600n8 usbcore.old_scheme_first=1 tegraboot=nand
root=/dev/nfs ip=:::::usb0:on rw tegra_ehci_probe_delay=5000 smp dvfs
tegrapart=recovery:1b80:a00:800,boot:2680:1000:800,environment:3780:40:800,system:38c0:2bc00:800,cache:2f5c0:4000:800,userdata:336c0:c840:800
envsector=3080
Build Date: 23 April 2010 05:19:26PM
xorg-server 2:1.7.6-2ubuntu7 (Bryce Harrington <bryce#ubuntu.com>)
Current version of pixman: 0.16.4
Before reporting problems, check http://wiki.x.org
to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
(++) from command line, (!!) notice, (II) informational,
(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Wed Jun 16 19:52:00 2010
(==) Using config file: "/etc/X11/xorg.conf"
(==) Using config directory: "/usr/lib/X11/xorg.conf.d"
Is there any way to do this without manually checking pattern for each line?
Possibly:
sed '1,/^(==) Using config directory: "/d'
Or, possibly:
sed '/^X.Org X Server /,/^(==) Using config directory: "/d'

Resources