From 0ee00536e6c1a64dadc4da17a545d3c17165fa64 Mon Sep 17 00:00:00 2001 From: Victor Häggqvist Date: Mon, 18 May 2015 19:12:50 +0200 Subject: update to support python 3 --- README.md | 16 +++++++------- setup.py | 10 ++++----- xboomx/bin/web_xboomx | 13 ----------- xboomx/bin/xboomx | 53 ++++++++++++++++++++++++--------------------- xboomx/bin/xboomx_path.py | 22 +++++++++++-------- xboomx/bin/xboomx_sort.py | 35 +++++++++++++++--------------- xboomx/bin/xboomx_update.py | 34 ++++++++++++++++------------- xboomx/bin/xboomx_urls.py | 15 ------------- xboomx/db.py | 13 ----------- xboomx/sqlitemgr.py | 38 ++++++++++++++++++++++++++++++++ 10 files changed, 128 insertions(+), 121 deletions(-) delete mode 100644 xboomx/bin/web_xboomx mode change 100644 => 100755 xboomx/bin/xboomx_sort.py delete mode 100644 xboomx/bin/xboomx_urls.py delete mode 100644 xboomx/db.py create mode 100644 xboomx/sqlitemgr.py diff --git a/README.md b/README.md index a5749f4..f6aa3d3 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ -xboomx -====== +# xboomx xboomx is wrapper around the dmenu. It is also a launcher. All the things it done is just sorting commands to launch according to their launch frequency. In other words - if you launch emacs and lxterminal all the time - they will appear in the list of commands first. -#Installation +## Installation ```sh git clone https://github.com/victorhaggqvist/xboomx cd xboomx @@ -13,7 +12,7 @@ mkdir ~/.xboomx cp etc/config ~/.xboomx/config ``` -#Config +## Config The config file, which if you followed the instructions above is located at `~/.xboomx/config`, contains the following a json object. ```json { @@ -29,9 +28,10 @@ man dmenu The `ignorelist` to prevent stuff that is in your path for showing up as suggestions. Like if you type `x` then `X` might show up before `xbmc`. -#License - xboomx - Copyright (C) 2014 Victor Häggqvist +## License + + xboomx + Copyright (C) 2014-2015 Victor Häggqvist This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -47,6 +47,6 @@ The `ignorelist` to prevent stuff that is in your path for showing up as suggest with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -For original license see the file`LICENSE.org` +For original license see the file `LICENSE.org` This is a fork of https://bitbucket.org/dehun/xboomx diff --git a/setup.py b/setup.py index 8acc2e3..99a63e6 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,17 @@ # -*- coding: utf-8 -*- -from setuptools import setup +from setuptools import setup, find_packages setup( name='xboomx', - version='0.60', + version='0.7.0', packages=['xboomx'], scripts=['xboomx/bin/xboomx_path.py', 'xboomx/bin/xboomx_sort.py', 'xboomx/bin/xboomx_update.py', - 'xboomx/bin/xboomx_urls.py', - 'xboomx/bin/web_xboomx', 'xboomx/bin/xboomx'], - license='GPLv2', - long_description='wrapper for most common occurences in dmenu', + license='GPL-2.0', + long_description='A wrapper for most common occurrences in dmenu', install_requires=[], include_package_data=True, package_data={'shared': ["etc/config"]}, diff --git a/xboomx/bin/web_xboomx b/xboomx/bin/web_xboomx deleted file mode 100644 index 67baba3..0000000 --- a/xboomx/bin/web_xboomx +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/python - -import subprocess -from xboomx.config import config - - -DMENU_LAUNCHER = 'dmenu ' + config.get("dmenu_params", "") - -subprocess.call("""xboomx_urls.py | xboomx_sort.py urls | \ - """ + DMENU_LAUNCHER + """| \ - xboomx_update.py urls | \ - xargs -I {} sh -c \'exec firefox {} &\'""", - shell=True) diff --git a/xboomx/bin/xboomx b/xboomx/bin/xboomx index c8865dc..98641ee 100755 --- a/xboomx/bin/xboomx +++ b/xboomx/bin/xboomx @@ -1,35 +1,38 @@ -#!/usr/bin/python +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +__author__ = 'Victor Häggqvist, Yuriy Netesov' +__copyright__ = 'Copyright 2014-2015, Victor Häggqvist' +__credits__ = ['Victor Häggqvist', 'Yuriy Netesov'] +__license__ = 'GPL-2.0' +__version__ = '0.7.0' +__maintainer__ = 'Victor Häggqvist ' + import subprocess from xboomx.config import config -import xboomx.db +from xboomx.sqlitemgr import get_session, PathItem import sys +def main(): + if len(sys.argv) > 1 and sys.argv[1] == "--stats": + session = get_session() + items = session.query(PathItem).order_by(PathItem.count.desc()) -if len(sys.argv) > 1 and sys.argv[1] == "--stats": - db = xboomx.db.open_shelve('') - - items = [] - - keys = db.keys() - - for x in keys: - items.append([x, db.get(x, "")]) - - db.close() + print('Application\tLaunches') + for item in items: + if item.count < 3: + continue - # sort items - items.sort(key=lambda x: x[1], reverse=True) + if len(item.name) < 8: + print('%s\t\t%s' % (item.name, item.count)) + else: + print('%s\t%s' % (item.name, item.count)) - # print items - print "Application\tLaunches" - for item in items: - if len(item[0]) < 8: - print item[0]+"\t\t"+str(item[1]) - else: - print item[0]+"\t"+str(item[1]) + exit(0) - exit(0) + dmenu_launcher = 'dmenu ' + config.get("dmenu_params", "") -DMENU_LAUNCHER = 'dmenu ' + config.get("dmenu_params", "") + subprocess.call('xboomx_path.py | xboomx_sort.py | ' + dmenu_launcher + "| xboomx_update.py | xargs -I {} sh -c \'exec {} &\'", shell=True) -subprocess.call("xboomx_path.py | xboomx_sort.py | " + DMENU_LAUNCHER + "| xboomx_update.py | xargs -I {} sh -c \'exec {} &\'", shell=True) +if __name__ == '__main__': + main() diff --git a/xboomx/bin/xboomx_path.py b/xboomx/bin/xboomx_path.py index 56779b3..4a5e87c 100755 --- a/xboomx/bin/xboomx_path.py +++ b/xboomx/bin/xboomx_path.py @@ -1,23 +1,27 @@ -#!/usr/bin/python +#!/usr/bin/env python3 +# coding=utf-8 import os from xboomx.config import config +__author__ = 'Victor Häggqvist' + def main(): - pathes = os.environ['PATH'].split(':') + paths = os.environ['PATH'].split(':') items = [] - for path in pathes: + for path in paths: if os.path.isdir(path): for f in os.listdir(path): items.append(f) - uniqeitems = list(set(items)) + unique_items = list(set(items)) - ignorelist = config.get("ignorelist",""); - for item in uniqeitems: - if item not in ignorelist: - print item + ignore_list = config.get("ignorelist", "") + for item in unique_items: + if item not in ignore_list: + print(item) -main() \ No newline at end of file +if __name__ == '__main__': + main() diff --git a/xboomx/bin/xboomx_sort.py b/xboomx/bin/xboomx_sort.py old mode 100644 new mode 100755 index a30c362..3b78d83 --- a/xboomx/bin/xboomx_sort.py +++ b/xboomx/bin/xboomx_sort.py @@ -1,36 +1,37 @@ -#!/usr/bin/python +#!/usr/bin/env python3 import fileinput -import sys -import xboomx.db +from xboomx.sqlitemgr import get_session, PathItem def main(): + session = get_session() + dbitems = session.query(PathItem).all() - # get db type - db_type = '' - if len(sys.argv) > 1: - db_type = sys.argv[1] - - # open shelve - db = xboomx.db.open_shelve(db_type) + items = {} + for i in dbitems: + items[i.name] = i.count # read lines and set weight according to db items = [] - for input_item in fileinput.input([]): input_item = input_item.strip('\n') - items.append((db.get(input_item, 0), input_item)) + + try: + count = items[input_item] + items.append((count, input_item)) + except KeyError: + items.append((0, input_item)) # sort items items.sort(key=lambda x: x[0], reverse=True) - # print items + # print items to be shown on dmenu for item in items: - print item[1] + print(item[1]) - # clean up - db.close() + session.close() -main() +if __name__ == '__main__': + main() diff --git a/xboomx/bin/xboomx_update.py b/xboomx/bin/xboomx_update.py index 708c0b8..4b5d98e 100644 --- a/xboomx/bin/xboomx_update.py +++ b/xboomx/bin/xboomx_update.py @@ -1,7 +1,9 @@ -#!/usr/bin/python +#!/usr/bin/env python3 +from pprint import pprint import sys import fileinput -import xboomx.db +from sqlalchemy.orm.exc import NoResultFound +from xboomx.sqlitemgr import get_session, PathItem def main(): @@ -10,22 +12,24 @@ def main(): if len(sys.argv) > 1 and sys.argv[1] != "--stats": db_type = sys.argv[1] - # open db - db = xboomx.db.open_shelve(db_type) + item = fileinput.input()[0] + pprint(item) - # get item to update - item = fileinput.input([]).next() item = item.strip('\n') - # update item - db[item] = db.get(item, 0) + 1 + session = get_session() + try: + dbitem = session.query(PathItem).filter_by(name=item).one() + dbitem.count = dbitem.count + 1 + session.add(dbitem) + except NoResultFound: + dbi = PathItem(name=item, couunt=0) + session.add(dbi) - # print it - print item + session.commit() + session.close() - # clean up - db.sync() - db.close() + print(item) - -main() +if __name__ == '__main__': + main() diff --git a/xboomx/bin/xboomx_urls.py b/xboomx/bin/xboomx_urls.py deleted file mode 100644 index 211c98c..0000000 --- a/xboomx/bin/xboomx_urls.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/python - -import xboomx.db -DB_TYPE = 'urls' - - -def main(): - db = xboomx.db.open_shelve(DB_TYPE) - for url in db.keys(): - print url - - db.close() - - -main() diff --git a/xboomx/db.py b/xboomx/db.py deleted file mode 100644 index fd099e3..0000000 --- a/xboomx/db.py +++ /dev/null @@ -1,13 +0,0 @@ -import shelve -import os - - -def open_shelve(db_type=''): - # create dir if not exists - try: - os.makedirs(os.getenv("HOME") + '/.xboomx') - except: - pass - - # open shelve - return shelve.open(os.getenv("HOME") + '/.xboomx/xboomx%s.db' % db_type) diff --git a/xboomx/sqlitemgr.py b/xboomx/sqlitemgr.py new file mode 100644 index 0000000..6e05bb2 --- /dev/null +++ b/xboomx/sqlitemgr.py @@ -0,0 +1,38 @@ +# coding=utf-8 +import os +from sqlalchemy import create_engine +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker +from sqlalchemy import Column, Integer, String + +__author__ = 'Victor Häggqvist' + +# create dir if not exists +try: + os.makedirs(os.getenv("HOME") + '/.xboomx') +except: + pass + +dbname = 'xboomx_sqlite.db' +dbpath = os.path.join(os.getenv("HOME"), '.xboomx', dbname) +dsn = 'sqlite:///%s' % dbpath + +engine = create_engine(dsn, echo=False) +Base = declarative_base() + + +class PathItem(Base): + __tablename__ = 'pathitems' + id = Column(Integer, primary_key=True) + name = Column(String) + count = Column(Integer) + + def __repr__(self): + return "" % (self.name, self.count) + + +def get_session(): + Base.metadata.create_all(engine) + Session = sessionmaker(bind=engine) + session = Session() + return session -- cgit v1.2.3