Switch to using pyxdg, update README

This commit is contained in:
Kai Huuhko 2014-07-10 23:12:24 +03:00
parent 3cfbcc1841
commit c40f6d2e76
6 changed files with 94 additions and 57 deletions

18
README
View File

@ -2,9 +2,10 @@
REQUIREMENTS
============
* libtorrent-rasterbar 0.16.0 or later, tested and developed with 0.16.16
* libtorrent-rasterbar 0.16.0 or later, currently tested and developed with
version 0.16.16
http://www.rasterbar.com/products/libtorrent/
http://www.libtorrent.org/
* Enlightenment Foundation Libraries 1.8 or later
@ -24,6 +25,12 @@ REQUIREMENTS
* dbus-python
http://www.freedesktop.org/wiki/Software/DBusBindings/#dbus-python
* python-xdg / pyxdg
http://www.freedesktop.org/wiki/Software/pyxdg/
=======
INSTALL
=======
@ -34,6 +41,7 @@ sudo ./setup.py install
CONTACT/BUGS
============
Launchpad: https://launchpad.net/epour
Email: kai.huuhko@gmail.com
Forums: http://forums.bodhilinux.com/index.php?/topic/7722-epour/
Email: kai.huuhko@gmail.com
Mailing list: enlightenment-users@lists.sourceforge.net
Forums: http://forums.bodhilinux.com/index.php?/topic/7722-epour/
Launchpad: https://launchpad.net/epour

13
TODO
View File

@ -70,6 +70,19 @@ Misc:
☐ Save resume data periodically
http://libtorrent.org/reference-Core.html#save_resume_data()
http://libtorrent.org/reference-Core.html#need_save_resume_data()
Error handling:
☐ Torrent errors
http://libtorrent.org/reference-Alerts.html#torrent_error_alert
☐ Tracker errors
http://libtorrent.org/reference-Alerts.html#tracker_error_alert
☐ Display authentication dialog when tracker requires it
☐ Performance notifications
http://libtorrent.org/reference-Alerts.html#performance_alert
☐ File errors
http://libtorrent.org/reference-Alerts.html#file_error_alert
☐ Listen failed/succeeded
http://libtorrent.org/reference-Alerts.html#listen_failed_alert
http://libtorrent.org/reference-Alerts.html#listen_succeeded_alert
I18N:
This should wait until most of the features are in and the strings are stable.
☐ Make strings localizable

View File

@ -59,12 +59,10 @@ else:
import os
from ConfigParser import SafeConfigParser
from Globals import conf_dir, conf_path, data_dir
import logging
for d in conf_dir, data_dir:
if not os.path.exists(d):
os.mkdir(d, 0700)
from xdg.BaseDirectory import save_data_path, save_config_path, \
load_config_paths
from session import Session
from gui import MainInterface
@ -120,7 +118,9 @@ class Epour(object):
ch.setLevel(log_level)
log.addHandler(ch)
fh = logging.FileHandler(os.path.join(data_dir, "epour.log"))
fh = logging.FileHandler(
os.path.join(save_data_path("epour"), "epour.log")
)
fh_formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
@ -146,7 +146,9 @@ class Epour(object):
"listen_high": str(0),
})
conf.read(conf_path)
for p in load_config_paths("epour"):
if conf.read(os.path.join(p, "epour.conf")):
break
if not conf.has_section("Settings"):
conf.add_section("Settings")
@ -154,6 +156,7 @@ class Epour(object):
return conf
def save_conf(self):
conf_path = os.path.join(save_config_path("epour"), "epour.conf")
with open(conf_path, 'wb') as configfile:
self.conf.write(configfile)

View File

@ -1,6 +1 @@
import os
version = "0.6.0"
conf_dir = os.path.expanduser(os.path.join("~", ".config", "epour"))
conf_path = os.path.join(conf_dir, "epour.conf")
data_dir = os.path.expanduser(os.path.join("~", ".local", "share", "epour"))

View File

@ -32,11 +32,14 @@ import libtorrent as lt
from efl.ecore import Timer
from Globals import data_dir
from xdg.BaseDirectory import save_data_path, load_data_paths
def torrent_path_get(ihash):
return os.path.join(data_dir, "{}.torrent".format(ihash))
for p in load_data_paths("epour"):
path = os.path.join(p, "{0}.torrent".format(ihash))
if os.path.isfile(path):
return path
class Session(lt.session):
@ -118,15 +121,19 @@ class Session(lt.session):
self.torrents[ihash]["ti"] = lt.bencode(t)
def load_state(self):
try:
with open(os.path.join(data_dir, "session"), 'rb') as f:
state = lt.bdecode(f.read())
lt.session.load_state(self, state)
except Exception as e:
self.log.debug("Could not load previous session state.")
self.log.debug(e)
else:
self.log.info("Session restored from disk.")
for p in load_data_paths("epour"):
path = os.path.join(p, "session")
if os.path.isfile(path):
try:
with open(path, 'rb') as f:
state = lt.bdecode(f.read())
lt.session.load_state(self, state)
except Exception as e:
self.log.debug("Could not load previous session state.")
self.log.debug(e)
else:
self.log.info("Session restored from disk.")
break
settings = self.settings()
from Globals import version
@ -139,15 +146,20 @@ class Session(lt.session):
def save_state(self):
state = lt.session.save_state(self)
with open(os.path.join(data_dir, "session"), 'wb') as f:
path = os.path.join(save_data_path("epour"), "session")
with open(path, 'wb') as f:
f.write(lt.bencode(state))
self.log.debug("Session state saved.")
def load_torrents(self):
torrents_path = os.path.join(data_dir, "torrents")
if not os.path.exists(torrents_path):
self.log.debug("No list of torrents found.")
for p in load_data_paths("epour"):
torrents_path = os.path.join(p, "torrents")
if os.path.isfile(torrents_path):
break
if not torrents_path:
self.info.debug("No previous list of torrents found.")
return
try:
@ -219,7 +231,8 @@ class Session(lt.session):
resume_data = lt.bencode(h.write_resume_data())
t_dict["resume_data"] = resume_data
with open(os.path.join(data_dir, "torrents"), 'wb') as f:
path = os.path.join(save_data_path("epour"), "torrents")
with open(path, 'wb') as f:
cPickle.dump(self.torrents, f, protocol=2)
self.log.debug("List of torrents saved.")
@ -258,21 +271,23 @@ class Session(lt.session):
def remove_torrent(self, h, with_data=False):
ihash = str(h.info_hash())
fr_path = os.path.join(
data_dir, "{}.fastresume".format(ihash)
)
#t_dict = self.torrents[ihash]
del self.torrents[ihash]
lt.session.remove_torrent(self, h, option=with_data)
try:
with open(fr_path):
pass
except IOError:
self.log.debug("Could not remove fast resume data.")
else:
os.remove(fr_path)
for p in load_data_paths("epour"):
fr_path = os.path.join(
p, "{0}.fastresume".format(ihash)
)
try:
with open(fr_path):
pass
except IOError:
self.log.debug("Could not remove %s", fr_path)
else:
os.remove(fr_path)
try:
with open(torrent_path_get(ihash)):
@ -310,22 +325,23 @@ class Session(lt.session):
add_dict["ti"] = info
rd = None
try:
with open(os.path.join(
data_dir, "{}.fastresume".format(info.info_hash())
), "rb"
) as f:
rd = f.read()
except Exception:
self.log.debug("Invalid resume data")
else:
add_dict["resume_data"] = rd
fr_file_name = "{}.fastresume".format(info.info_hash())
for p in load_data_paths("epour"):
path = os.path.join(p, fr_file_name)
if os.path.isfile(path):
try:
with open(path, "rb") as f:
rd = f.read()
except Exception:
self.log.debug("Invalid resume data")
else:
add_dict["resume_data"] = rd
break
ihash = str(info.info_hash())
new_uri = os.path.join(
data_dir, "{}.torrent".format(ihash)
)
path = save_data_path("epour")
new_uri = os.path.join(path, "{0}.torrent".format(ihash))
if t_uri == new_uri:
pass

View File

@ -11,9 +11,9 @@ setup(
author_email='kai.huuhko@gmail.com',
maintainer='Kai Huuhko',
maintainer_email='kai.huuhko@gmail.com',
description='A torrent client',
description='A BitTorrent client',
long_description=(
'Epour is a torrent client based on EFL and rb-libtorrent.'
'Epour is a BitTorrent client based on EFL and rb-libtorrent.'
),
#url='',
#download_url='',
@ -22,6 +22,8 @@ setup(
requires=[
'libtorrent',
'efl',
'xdg',
'dbus',
],
provides=[
'epour',