Skip to content

Commit

Permalink
1.1b2 release:
Browse files Browse the repository at this point in the history
- Preserve paces after newline in config.
- More compliant with XDG Base Directory Specifications.
  • Loading branch information
tsufeki committed Jul 23, 2013
1 parent 4c1e145 commit f16bf34
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 20 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,9 @@
qygmy (1.1~b2-1) unstable; urgency=low

* New release.

-- tsufeki <tsufeki@ymail.com> Tue, 23 Jul 2013 20:27:33 +0200

qygmy (1.1~b1-1) unstable; urgency=low qygmy (1.1~b1-1) unstable; urgency=low


* New release. * New release.
Expand Down
2 changes: 1 addition & 1 deletion qygmy/__version__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime import datetime
import subprocess import subprocess


version_info = (1, 1, 0, 'beta', 1) version_info = (1, 1, 0, 'beta', 2)


def _get_version(): def _get_version():
v = '%s.%s' % version_info[:2] v = '%s.%s' % version_info[:2]
Expand Down
70 changes: 55 additions & 15 deletions qygmy/dialogs.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,11 +38,42 @@ def exec_(self, name, info, title):
super().exec_() super().exec_()




class QygmyConfigParser(configparser.ConfigParser):

def __init__(self, **kwargs):
super().__init__(interpolation=None, **kwargs)

def write(self, fp, space_around_delimiters=True):
for sn, s in self.items():
for k, v in s.items():
if '\n' in v or '\r' in v:
s[k] = (''.join(('"', v.replace('\\', '\\\\')
.replace('\n', '\\n').replace('\r', '\\r'), '"')))
super().write(fp, space_around_delimiters)
self._unescape_nl()

def read(self, filenames, encoding=None):
r = super().read(filenames, encoding)
self._unescape_nl()
return r

def read_file(self, f, source=None):
super().read_file(f, source)
self._unescape_nl()

def _unescape_nl(self):
for sn, s in self.items():
for k, v in s.items():
if len(v) > 2 and v[0] == v[-1] == '"':
s[k] = (v[1:-1].replace('\\n', '\n').replace('\\r', '\r')
.replace('\\\\', '\\'))


class Settings(QDialog): class Settings(QDialog):


PATH = os.path.expanduser(os.path.join(os.environ.get('XDG_CONFIG_HOME', '~/.config'), 'qygmy')) directory = 'qygmy'
FILENAME = 'qygmy.conf' cfg_file = 'qygmy.conf'
PLUGINS = 'tmplplugin_*.py' plugins_glob = 'tmplplugin_*.py'


def __init__(self, main): def __init__(self, main):
super().__init__(main) super().__init__(main)
Expand All @@ -52,11 +83,18 @@ def __init__(self, main):
self.ui.setupUi(self) self.ui.setupUi(self)
self.retranslate() self.retranslate()


self.conf = configparser.ConfigParser(interpolation=None) self.conf = QygmyConfigParser()
self.conf.read_dict(self.defaults, '<defaults>') self.conf.read_dict(self.defaults, '<defaults>')
self.conf.read_dict(self.environ_conf(), '<MPD_HOST>') self.conf.read_dict(self.environ_conf(), '<MPD_HOST>')
self.cfg_dirs = [os.path.expanduser(os.environ.get('XDG_CONFIG_HOME', '~/.config'))]
more = os.environ.get('XDG_CONFIG_DIRS', '')
if more == '':
more = '/etc/xdg'
self.cfg_dirs.extend(d for d in more.split(':') if d and d[0] == '/')
self.cfg_dirs = [os.path.join(d, self.directory) for d in self.cfg_dirs]
cfg_files = [os.path.join(d, self.cfg_file) for d in self.cfg_dirs]
try: try:
self.conf.read(os.path.join(self.PATH, self.FILENAME), 'utf-8') self.conf.read(cfg_files, 'utf-8')
except (configparser.Error, ValueError, OSError) as e: except (configparser.Error, ValueError, OSError) as e:
log.error('{}: {}'.format(e.__class__.__name__, e)) log.error('{}: {}'.format(e.__class__.__name__, e))
self.conf._join_multiline_values() self.conf._join_multiline_values()
Expand Down Expand Up @@ -124,14 +162,15 @@ def environ_conf(self):


def load_tmplplugins(self): def load_tmplplugins(self):
self.tmplplugins = [] self.tmplplugins = []
for plugin in sorted(glob.glob(os.path.join(self.PATH, self.PLUGINS))): for d in self.cfg_dirs:
try: for f in sorted(glob.glob(os.path.join(d, self.plugins_glob))):
name = os.path.split(plugin)[1][:-3] try:
mod = importlib.machinery.SourceFileLoader(name, plugin).load_module() name = os.path.split(f)[1][:-3]
if mod: mod = importlib.machinery.SourceFileLoader(name, f).load_module()
self.tmplplugins.append(mod) if mod:
except Exception as e: self.tmplplugins.append(mod)
logger.error('{}: {}'.format(e.__class__.__name__, e)) except Exception as e:
logger.error('{}: {}'.format(e.__class__.__name__, e))


def __getitem__(self, section): def __getitem__(self, section):
return self.conf[section] return self.conf[section]
Expand Down Expand Up @@ -221,8 +260,9 @@ def ui_to_conf(self):


def save(self): def save(self):
try: try:
os.makedirs(self.PATH, exist_ok=True) cfg_dir = self.cfg_dirs[0]
with open(os.path.join(self.PATH, self.FILENAME), 'w', encoding='utf-8') as f: os.makedirs(cfg_dir, exist_ok=True)
with open(os.path.join(cfg_dir, self.cfg_file), 'w', encoding='utf-8') as f:
self.conf.write(f) self.conf.write(f)
except OSError as e: except OSError as e:
log.error('{}: {}'.format(e.__class__.__name__, e)) log.error('{}: {}'.format(e.__class__.__name__, e))
Expand Down
8 changes: 4 additions & 4 deletions qygmy/translations/qygmy_pl.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -328,22 +328,22 @@
<context> <context>
<name>Settings</name> <name>Settings</name>
<message> <message>
<location filename="../dialogs.py" line="79"/> <location filename="../dialogs.py" line="117"/>
<source>Qygmy$if(%playing%, / $if(%artist%,%artist% u2014 )$if2(%title%,%filename%))</source> <source>Qygmy$if(%playing%, / $if(%artist%,%artist% u2014 )$if2(%title%,%filename%))</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../dialogs.py" line="88"/> <location filename="../dialogs.py" line="126"/>
<source>$if3(%playing%%paused%,$time(%elapsed%)$if($and(%total%,$gt(%total%,0)), / $time(%total%)),%stopped%,Stopped,%connected%,Connected,Disconnected)</source> <source>$if3(%playing%%paused%,$time(%elapsed%)$if($and(%total%,$gt(%total%,0)), / $time(%total%)),%stopped%,Stopped,%connected%,Connected,Disconnected)</source>
<translation>$if3(%playing%%paused%,$time(%elapsed%)$if($and(%total%,$gt(%total%,0)), / $time(%total%)),%stopped%,Zatrzymany,%connected%,Połączony,Rozłączony)</translation> <translation>$if3(%playing%%paused%,$time(%elapsed%)$if($and(%total%,$gt(%total%,0)), / $time(%total%)),%stopped%,Zatrzymany,%connected%,Połączony,Rozłączony)</translation>
</message> </message>
<message> <message>
<location filename="../dialogs.py" line="93"/> <location filename="../dialogs.py" line="131"/>
<source>&lt;span style=&quot;font-size: large; font-weight: bold&quot;&gt;$if2(%title%,%filename%)&lt;/span&gt;&lt;br&gt;%artist%$if(%album%, u2014 %album%)</source> <source>&lt;span style=&quot;font-size: large; font-weight: bold&quot;&gt;$if2(%title%,%filename%)&lt;/span&gt;&lt;br&gt;%artist%$if(%album%, u2014 %album%)</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../dialogs.py" line="97"/> <location filename="../dialogs.py" line="135"/>
<source>$if(%artist%,%artist% u2014 )$if2(%title%,%filename%)</source> <source>$if(%artist%,%artist% u2014 )$if2(%title%,%filename%)</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
Expand Down

0 comments on commit f16bf34

Please sign in to comment.