-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from FrostyX/develop
Version 0.2
- Loading branch information
Showing
12 changed files
with
416 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ How does he do it? He simply finds all packages you have modified since you boot | |
- Python [psutil](https://code.google.com/p/psutil/) module. Available [here](https://admin.fedoraproject.org/pkgdb/acls/name/python-psutil) and [here](https://packages.gentoo.org/package/dev-python/psutil). Please use testing version on gentoo. | ||
|
||
## Usage | ||
### Basics | ||
Clone tracer from GitHub | ||
|
||
git clone [email protected]:FrostyX/tracer.git | ||
|
@@ -20,6 +21,48 @@ And simply run it | |
|
||
_Yeah, you really have to run it as root._ | ||
|
||
### Symlink in PATH | ||
Since there is no installation method so far, you can make symlink of `bin/tracer.py` to your `PATH` directory by yourself. Then you can use `tracer` just by calling its name. | ||
|
||
# Make symlink | ||
sudo ln -s tracer/bin/tracer.py /usr/local/bin/tracer | ||
|
||
# And then just run | ||
sudo tracer | ||
|
||
### Arguments and pipes | ||
You can also specify packages that *only* should be traced. Just pass them as arguments [1] or pipe them into `tracer` [2] \(or combine them\) | ||
|
||
# [1] | ||
sudo tracer mpd ncmpcpp vim | ||
|
||
# [2] | ||
echo mpd ncmpcpp vim | sudo tracer | ||
|
||
|
||
## Integration with package managers | ||
### DNF | ||
Make symlink of `integration/dnf/plugins/tracer.py` file to your [dnf plugin directory](http://akozumpl.github.io/dnf/api_conf.html#dnf.conf.Conf.pluginpath) | ||
|
||
Tracer is called after every successful transaction. | ||
|
||
$[FrostyX ~]-> sudo dnf update vim-X11 | ||
... | ||
Running transaction | ||
Upgrading : vim-common-2:7.4.179-1.fc20.i686 1/6 | ||
Upgrading : vim-X11-2:7.4.179-1.fc20.i686 2/6 | ||
Upgrading : vim-enhanced-2:7.4.179-1.fc20.i686 3/6 | ||
... | ||
|
||
Upgraded: | ||
vim-X11.i686 2:7.4.179-1.fc20 vim-common.i686 2:7.4.179-1.fc20 | ||
vim-enhanced.i686 2:7.4.179-1.fc20 | ||
|
||
Calling tracer | ||
vim-X11 | ||
|
||
Done! | ||
|
||
|
||
## Feedback | ||
Please report any bugs or feature requests right [here](https://github.com/FrostyX/tracer/issues) on GitHub. Pull requests are also welcome. If you rather want a talk or something, you can find me on `#gentoo.cs` or `fedora-cs` `@freenode` or you can [mail me](mailto:[email protected]). | ||
Please report any bugs or feature requests to [issues](https://github.com/FrostyX/tracer/issues) on this repository. Pull requests are also welcome. If you rather want a talk or something, you can find me on `#gentoo.cs` or `#fedora-cs` `@freenode` or you can [mail me](mailto:[email protected]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#-*- coding: utf-8 -*- | ||
# tracer.py, calls tracer after every successful transaction. | ||
# Also supplies the 'tracer' command. | ||
# | ||
# Copyright (C) 2014 Jakub Kadlčík | ||
# | ||
# This copyrighted material is made available to anyone wishing to use, | ||
# modify, copy, or redistribute it subject to the terms and conditions of | ||
# the GNU General Public License v.2, or (at your option) any later version. | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY expressed or implied, including the implied warranties of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. You should have received a copy of the | ||
# GNU General Public License along with this program; if not, write to the | ||
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
# 02110-1301, USA. | ||
# | ||
|
||
import dnf | ||
import subprocess | ||
|
||
class Tracer(dnf.Plugin): | ||
"""DNF plugin for `tracer` command""" | ||
name = 'tracer' | ||
|
||
def __init__(self, base, cli): | ||
self.base = base | ||
self.cli = cli | ||
if self.cli is not None: | ||
self.cli.register_command(TracerCommand) | ||
|
||
def transaction(self): | ||
""" | ||
Call after successful transaction | ||
Warning, this code uses undocummented parts. See https://bugzilla.redhat.com/show_bug.cgi?id=1067156 | ||
""" | ||
items = [] | ||
for transaction_item in self.base.transaction: | ||
item = transaction_item.installed.name if transaction_item.installed else transaction_item.erased.name | ||
items.append(item) | ||
|
||
args = ['tracer', '-n'] + items | ||
p = subprocess.Popen(args, stdout=subprocess.PIPE) | ||
out, err = p.communicate() | ||
|
||
print 'Calling tracer' | ||
print out | ||
|
||
|
||
class TracerCommand(dnf.cli.Command): | ||
"""DNF tracer plugin""" | ||
aliases = ['tracer'] | ||
activate_sack = True | ||
|
||
def run(self, args): | ||
"Call after running `dnf tracer ...`" | ||
for arg in args: | ||
print arg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#-*- coding: utf-8 -*- | ||
"""Module to work with DNF package manager class | ||
Copyright 2013 Jakub Kadlčík""" | ||
|
||
from rpm import Rpm | ||
|
||
class Dnf(Rpm): | ||
|
||
@property | ||
def history_path(self): return '/var/lib/dnf/history/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#-*- coding: utf-8 -*- | ||
"""Base RPM package manager class | ||
Copyright 2013 Jakub Kadlčík""" | ||
|
||
from os import listdir | ||
from ipackageManager import IPackageManager | ||
from resources.package import Package | ||
import sqlite3 | ||
import subprocess | ||
import re | ||
|
||
class Rpm(IPackageManager): | ||
|
||
def packages_newer_than(self, unix_time): | ||
""" | ||
Returns list of packages which were modified between unix_time and present | ||
Requires root permissions. | ||
""" | ||
|
||
sql = """ | ||
SELECT pkgtups.name | ||
FROM trans_data_pkgs JOIN pkgtups ON trans_data_pkgs.pkgtupid=pkgtups.pkgtupid | ||
WHERE trans_data_pkgs.tid = ? | ||
ORDER BY pkgtups.pkgtupid | ||
""" | ||
|
||
packages = [] | ||
sqlite = self._database_file() | ||
conn = sqlite3.connect(sqlite) | ||
conn.row_factory = sqlite3.Row | ||
c = conn.cursor() | ||
|
||
for t in self._transactions_newer_than(unix_time): | ||
c.execute(sql, [t['tid']]) | ||
for p in c.fetchall(): | ||
packages.append(Package(p['name'], t['end'])) | ||
|
||
return packages | ||
|
||
def package_files(self, pkg_name): | ||
""" | ||
Returns list of files provided by package | ||
See also: http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch04s02s03.html | ||
""" | ||
|
||
p = subprocess.Popen(['rpm', '-ql', pkg_name], stdout=subprocess.PIPE) | ||
files, err = p.communicate() | ||
return files.split('\n')[:-1] | ||
|
||
def _transactions_newer_than(self, unix_time): | ||
""" | ||
Returns list of transactions which ran between unix_time and present. | ||
Requires root permissions. | ||
""" | ||
|
||
sql = """ | ||
SELECT trans_beg.tid, trans_beg.timestamp AS beg, trans_end.timestamp AS end | ||
FROM trans_beg JOIN trans_end ON trans_beg.tid=trans_end.tid | ||
WHERE beg > ? | ||
ORDER BY trans_beg.tid | ||
""" | ||
|
||
sqlite = self._database_file() | ||
conn = sqlite3.connect(sqlite) | ||
conn.row_factory = sqlite3.Row | ||
c = conn.cursor() | ||
c.execute(sql, [unix_time]) | ||
return c.fetchall() | ||
|
||
def _database_file(self): | ||
""" | ||
Returns path to yum history database file | ||
Requires root permissions. | ||
""" | ||
|
||
for file in listdir(self.history_path): | ||
if file.startswith("history-") and file.endswith(".sqlite"): | ||
return self.history_path + file | ||
|
Oops, something went wrong.