From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/overlay/
Date: Tue, 18 Jun 2013 14:12:56 +0000 (UTC) [thread overview]
Message-ID: <1371286696.dea12476091298811456b8c8f6ca596ae195e7ee.dywi@gentoo> (raw)
commit: dea12476091298811456b8c8f6ca596ae195e7ee
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Sat Jun 15 08:58:16 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Sat Jun 15 08:58:16 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=dea12476
overlay: write/update USE_EXPAND description files
---
| 13 ++++
roverlay/overlay/root.py | 168 ++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 171 insertions(+), 10 deletions(-)
--git a/roverlay/overlay/header.py b/roverlay/overlay/header.py
index 6cd1f1f..8c7c05a 100644
--- a/roverlay/overlay/header.py
+++ b/roverlay/overlay/header.py
@@ -29,6 +29,19 @@ class EbuildHeader ( object ):
return self._cached_header
# --- end of get (...) ---
+ def get_use_expand_header ( self, use_expand_name ):
+ if self.default_header:
+ return (
+ self.default_header + '\n'
+ + (
+ '# This file contains descriptions of the {} '
+ 'USE_EXPAND flags.'.format ( use_expand_name )
+ ) + '\n'
+ )
+ else:
+ return None
+ # --- end of get_use_expand_header (...) ---
+
def _make ( self ):
if self.eclasses:
inherit = 'inherit ' + ' '.join ( sorted ( self.eclasses ) )
diff --git a/roverlay/overlay/root.py b/roverlay/overlay/root.py
index 98d0b26..71156df 100644
--- a/roverlay/overlay/root.py
+++ b/roverlay/overlay/root.py
@@ -17,6 +17,7 @@ due do double-linkage between PackageInfo and PackageDir.
__all__ = [ 'Overlay', ]
+import errno
import logging
import os
import shutil
@@ -313,13 +314,18 @@ class Overlay ( object ):
# profiles/desc/<r_suggests>.desc
# !!! (late) config access (FIXME)
+
+ use_expand_name = roverlay.config.get_or_fail (
+ "EBUILD.USE_EXPAND.name"
+ ).rstrip ( "_" )
+
self._write_rsuggests_use_desc (
(
self._profiles_dir + os.sep + 'desc' + os.sep
- + roverlay.config.get_or_fail (
- "EBUILD.USE_EXPAND.name"
- ).rstrip ( "_" ).lower()+ '.desc'
- )
+ + use_expand_name.lower() + '.desc'
+ ),
+ use_expand_name.upper(),
+ roverlay.config.get ( 'OVERLAY.backup_desc', True )
)
# profiles/use.desc
@@ -342,12 +348,154 @@ class Overlay ( object ):
raise
# --- end of _init_overlay (...) ---
- def _write_rsuggests_use_desc ( self, desc_file ):
- # TODO
- #open ( desc_file, "r" ), errno == errno.ENOENT (2)
- self.logger.error (
- "Cannot write {!r}: code is missing ;)".format ( desc_file )
- )
+ def _write_rsuggests_use_desc (
+ self, desc_file, use_expand_name, backup_file, rewrite=False
+ ):
+ """Creates a USE_EXPAND description file.
+
+ Reads the old file (if it exists) and imports its header / flag desc.
+
+ arguments:
+ * desc_file -- path to the file that should be written/read
+ * use_expand_name -- name of the USE_EXPAND variable, e.g. R_SUGGESTS
+ * backup_file -- move desc_file to backup_file before overwriting it
+ This can also be an int i (=> desc_file + '.<i>')
+ or a bool (if True => desc_file + '.bak').
+ * rewrite -- force recreation of the desc file
+ """
+ FLAG_SEPA = ' - '
+ DESC_UNDEF = 'unknown'
+
+ def do_backup ( dest, makedir=False ):
+ self.logger.debug ( "Moving old desc file to {!r}".format ( dest ) )
+ if makedir:
+ roverlay.util.dodir ( os.path.dirname ( dest ), mkdir_p=True )
+ shutil.move ( desc_file, dest )
+ # --- end of do_backup (...) ---
+
+ def read_desc_file():
+ """Reads the old desc file (if it exists).
+ Returns a 3-tuple ( list header, dict flags, bool file_existed ).
+
+ arguments:
+ * @implicit desc_file --
+
+ Passes all exceptions (IOError, ...) but "file does not exist".
+ """
+
+ FH = None
+ header = list()
+ # flags := dict { <flag name> => <desc>|None }
+ flags = dict()
+ fexist = False
+ try:
+ FH = open ( desc_file, 'rt' )
+
+ addto_header = True
+
+ for line in FH.readlines():
+ rsline = line.rstrip()
+ if rsline and rsline [0] != '#':
+ flag, sepa, desc = rsline.partition ( FLAG_SEPA )
+ # <desc> == DESC_UNDEF -- ignore
+ flags [flag] = desc if sepa else None
+ addto_header = False
+ elif addto_header is True:
+ header.append ( rsline )
+ elif rsline:
+ self.logger.warning (
+ "dropping line from {f!r}: {l}".format (
+ f=desc_file, l=rsline
+ )
+ )
+ # -- end for
+
+ FH.close()
+ fexist = True
+ except IOError as ioerr:
+ if ioerr.errno == errno.ENOENT:
+ pass
+ else:
+ raise
+ finally:
+ if FH: FH.close()
+
+ return ( header, flags, fexist )
+ # --- end of read_desc_file ---
+
+ def gen_desc ( header, flags ):
+ """Creates new text lines for the desc file.
+
+ arguments:
+ * @implicit use_expand_name --
+ * header -- header line(s) to use (a default header will be created
+ if this is empty)
+ * flags -- flag=>desc dict
+ """
+ NEWLINE = '\n'
+
+ if header:
+ for line in header:
+ yield line
+ yield NEWLINE
+ #yield NEWLINE
+ else:
+ defheader = self._header.get_use_expand_header ( use_expand_name )
+ if defheader:
+ yield defheader
+ yield NEWLINE
+
+ for flag, desc in sorted ( flags.items(), key=lambda e: e[0] ):
+ if desc:
+ yield flag + FLAG_SEPA + desc
+ else:
+ yield flag + FLAG_SEPA + DESC_UNDEF
+ yield NEWLINE
+ # --- end of gen_desc (...) ---
+
+ header, old_flags, can_backup = read_desc_file()
+
+ if self._incremental:
+ # incremental: add new flags
+ # Create dict flag=>None that contains all new flags
+ # and copy old_flags "over" it.
+ #
+ flags = dict.fromkeys ( self._rsuggests_flags )
+ flags.update ( old_flags )
+ else:
+ # not incremental: discard old flags
+ # Create a dict that contains the new flags only and use desc
+ # from old_flags if available.
+ #
+ flags = {
+ flag: old_flags.get ( flag, None )
+ for flag in self._rsuggests_flags
+ }
+ # -- end if
+
+ # don't rewrite the desc file if nothing has changed
+ if rewrite or (
+ frozenset ( flags.keys() ) != frozenset ( old_flags.keys() )
+ ):
+ if can_backup:
+ if backup_file is True:
+ do_backup ( desc_file + '.bak' )
+ elif isinstance ( backup_file, int ):
+ do_backuo ( desc_file + '.' + str ( backup_file ) )
+ elif backup_file:
+ do_backup ( str ( backup_file ), makedir=True )
+ # -- end if
+
+ self.logger.debug ( "writing desc file {!r}".format ( desc_file ) )
+
+ roverlay.util.dodir ( os.path.dirname ( desc_file ) )
+ with open ( desc_file, 'wt' ) as FH:
+ for line in gen_desc ( header, flags ):
+ FH.write ( line )
+ else:
+ self.logger.debug (
+ "not writing desc file {!r} (nothing changed)".format ( desc_file )
+ )
# --- end of _write_rsuggests_use_desc (...) ---
def add ( self, package_info ):
WARNING: multiple messages have this Message-ID (diff)
From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/overlay/
Date: Sat, 15 Jun 2013 08:59:20 +0000 (UTC) [thread overview]
Message-ID: <1371286696.dea12476091298811456b8c8f6ca596ae195e7ee.dywi@gentoo> (raw)
Message-ID: <20130615085920.VkHJjXFZ7caXWeBl4y5OYYZk3h2qlSvfghl311gg7Uc@z> (raw)
commit: dea12476091298811456b8c8f6ca596ae195e7ee
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Sat Jun 15 08:58:16 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Sat Jun 15 08:58:16 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=dea12476
overlay: write/update USE_EXPAND description files
---
| 13 ++++
roverlay/overlay/root.py | 168 ++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 171 insertions(+), 10 deletions(-)
--git a/roverlay/overlay/header.py b/roverlay/overlay/header.py
index 6cd1f1f..8c7c05a 100644
--- a/roverlay/overlay/header.py
+++ b/roverlay/overlay/header.py
@@ -29,6 +29,19 @@ class EbuildHeader ( object ):
return self._cached_header
# --- end of get (...) ---
+ def get_use_expand_header ( self, use_expand_name ):
+ if self.default_header:
+ return (
+ self.default_header + '\n'
+ + (
+ '# This file contains descriptions of the {} '
+ 'USE_EXPAND flags.'.format ( use_expand_name )
+ ) + '\n'
+ )
+ else:
+ return None
+ # --- end of get_use_expand_header (...) ---
+
def _make ( self ):
if self.eclasses:
inherit = 'inherit ' + ' '.join ( sorted ( self.eclasses ) )
diff --git a/roverlay/overlay/root.py b/roverlay/overlay/root.py
index 98d0b26..71156df 100644
--- a/roverlay/overlay/root.py
+++ b/roverlay/overlay/root.py
@@ -17,6 +17,7 @@ due do double-linkage between PackageInfo and PackageDir.
__all__ = [ 'Overlay', ]
+import errno
import logging
import os
import shutil
@@ -313,13 +314,18 @@ class Overlay ( object ):
# profiles/desc/<r_suggests>.desc
# !!! (late) config access (FIXME)
+
+ use_expand_name = roverlay.config.get_or_fail (
+ "EBUILD.USE_EXPAND.name"
+ ).rstrip ( "_" )
+
self._write_rsuggests_use_desc (
(
self._profiles_dir + os.sep + 'desc' + os.sep
- + roverlay.config.get_or_fail (
- "EBUILD.USE_EXPAND.name"
- ).rstrip ( "_" ).lower()+ '.desc'
- )
+ + use_expand_name.lower() + '.desc'
+ ),
+ use_expand_name.upper(),
+ roverlay.config.get ( 'OVERLAY.backup_desc', True )
)
# profiles/use.desc
@@ -342,12 +348,154 @@ class Overlay ( object ):
raise
# --- end of _init_overlay (...) ---
- def _write_rsuggests_use_desc ( self, desc_file ):
- # TODO
- #open ( desc_file, "r" ), errno == errno.ENOENT (2)
- self.logger.error (
- "Cannot write {!r}: code is missing ;)".format ( desc_file )
- )
+ def _write_rsuggests_use_desc (
+ self, desc_file, use_expand_name, backup_file, rewrite=False
+ ):
+ """Creates a USE_EXPAND description file.
+
+ Reads the old file (if it exists) and imports its header / flag desc.
+
+ arguments:
+ * desc_file -- path to the file that should be written/read
+ * use_expand_name -- name of the USE_EXPAND variable, e.g. R_SUGGESTS
+ * backup_file -- move desc_file to backup_file before overwriting it
+ This can also be an int i (=> desc_file + '.<i>')
+ or a bool (if True => desc_file + '.bak').
+ * rewrite -- force recreation of the desc file
+ """
+ FLAG_SEPA = ' - '
+ DESC_UNDEF = 'unknown'
+
+ def do_backup ( dest, makedir=False ):
+ self.logger.debug ( "Moving old desc file to {!r}".format ( dest ) )
+ if makedir:
+ roverlay.util.dodir ( os.path.dirname ( dest ), mkdir_p=True )
+ shutil.move ( desc_file, dest )
+ # --- end of do_backup (...) ---
+
+ def read_desc_file():
+ """Reads the old desc file (if it exists).
+ Returns a 3-tuple ( list header, dict flags, bool file_existed ).
+
+ arguments:
+ * @implicit desc_file --
+
+ Passes all exceptions (IOError, ...) but "file does not exist".
+ """
+
+ FH = None
+ header = list()
+ # flags := dict { <flag name> => <desc>|None }
+ flags = dict()
+ fexist = False
+ try:
+ FH = open ( desc_file, 'rt' )
+
+ addto_header = True
+
+ for line in FH.readlines():
+ rsline = line.rstrip()
+ if rsline and rsline [0] != '#':
+ flag, sepa, desc = rsline.partition ( FLAG_SEPA )
+ # <desc> == DESC_UNDEF -- ignore
+ flags [flag] = desc if sepa else None
+ addto_header = False
+ elif addto_header is True:
+ header.append ( rsline )
+ elif rsline:
+ self.logger.warning (
+ "dropping line from {f!r}: {l}".format (
+ f=desc_file, l=rsline
+ )
+ )
+ # -- end for
+
+ FH.close()
+ fexist = True
+ except IOError as ioerr:
+ if ioerr.errno == errno.ENOENT:
+ pass
+ else:
+ raise
+ finally:
+ if FH: FH.close()
+
+ return ( header, flags, fexist )
+ # --- end of read_desc_file ---
+
+ def gen_desc ( header, flags ):
+ """Creates new text lines for the desc file.
+
+ arguments:
+ * @implicit use_expand_name --
+ * header -- header line(s) to use (a default header will be created
+ if this is empty)
+ * flags -- flag=>desc dict
+ """
+ NEWLINE = '\n'
+
+ if header:
+ for line in header:
+ yield line
+ yield NEWLINE
+ #yield NEWLINE
+ else:
+ defheader = self._header.get_use_expand_header ( use_expand_name )
+ if defheader:
+ yield defheader
+ yield NEWLINE
+
+ for flag, desc in sorted ( flags.items(), key=lambda e: e[0] ):
+ if desc:
+ yield flag + FLAG_SEPA + desc
+ else:
+ yield flag + FLAG_SEPA + DESC_UNDEF
+ yield NEWLINE
+ # --- end of gen_desc (...) ---
+
+ header, old_flags, can_backup = read_desc_file()
+
+ if self._incremental:
+ # incremental: add new flags
+ # Create dict flag=>None that contains all new flags
+ # and copy old_flags "over" it.
+ #
+ flags = dict.fromkeys ( self._rsuggests_flags )
+ flags.update ( old_flags )
+ else:
+ # not incremental: discard old flags
+ # Create a dict that contains the new flags only and use desc
+ # from old_flags if available.
+ #
+ flags = {
+ flag: old_flags.get ( flag, None )
+ for flag in self._rsuggests_flags
+ }
+ # -- end if
+
+ # don't rewrite the desc file if nothing has changed
+ if rewrite or (
+ frozenset ( flags.keys() ) != frozenset ( old_flags.keys() )
+ ):
+ if can_backup:
+ if backup_file is True:
+ do_backup ( desc_file + '.bak' )
+ elif isinstance ( backup_file, int ):
+ do_backuo ( desc_file + '.' + str ( backup_file ) )
+ elif backup_file:
+ do_backup ( str ( backup_file ), makedir=True )
+ # -- end if
+
+ self.logger.debug ( "writing desc file {!r}".format ( desc_file ) )
+
+ roverlay.util.dodir ( os.path.dirname ( desc_file ) )
+ with open ( desc_file, 'wt' ) as FH:
+ for line in gen_desc ( header, flags ):
+ FH.write ( line )
+ else:
+ self.logger.debug (
+ "not writing desc file {!r} (nothing changed)".format ( desc_file )
+ )
# --- end of _write_rsuggests_use_desc (...) ---
def add ( self, package_info ):
next reply other threads:[~2013-06-18 14:13 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-18 14:12 André Erdmann [this message]
2013-06-15 8:59 ` [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/overlay/ André Erdmann
-- strict thread matches above, loose matches on Subject: below --
2014-08-23 19:03 [gentoo-commits] proj/R_overlay:master " André Erdmann
2014-07-29 18:29 ` André Erdmann
2014-07-18 16:20 André Erdmann
2014-07-18 2:28 [gentoo-commits] proj/R_overlay:wip/addition_control " André Erdmann
2014-07-18 16:20 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2014-07-18 2:28 [gentoo-commits] proj/R_overlay:wip/addition_control " André Erdmann
2014-07-18 16:20 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2014-04-01 16:38 André Erdmann
2013-09-18 14:00 André Erdmann
2013-09-17 13:49 André Erdmann
2013-09-03 15:51 André Erdmann
2013-09-03 13:15 André Erdmann
2013-09-03 8:35 André Erdmann
2013-09-02 16:21 André Erdmann
2013-09-02 16:21 André Erdmann
2013-08-29 12:36 André Erdmann
2013-08-20 21:46 André Erdmann
2013-08-20 21:46 André Erdmann
2013-07-29 14:56 André Erdmann
2013-07-10 15:10 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-10 16:16 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-13 16:34 André Erdmann
2013-04-25 16:44 André Erdmann
2013-04-25 16:44 André Erdmann
2013-02-09 21:28 André Erdmann
2013-02-09 20:45 André Erdmann
2013-02-09 20:45 André Erdmann
2013-01-30 20:16 André Erdmann
2012-08-17 17:26 André Erdmann
2012-08-03 13:38 André Erdmann
2012-08-01 21:10 André Erdmann
2012-07-30 15:53 André Erdmann
2012-07-30 8:52 André Erdmann
2012-07-30 8:52 André Erdmann
2012-07-24 16:59 [gentoo-commits] proj/R_overlay:overlay_wip " André Erdmann
2012-07-30 8:52 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2012-07-05 16:00 André Erdmann
2012-07-04 18:21 André Erdmann
2012-07-03 17:48 André Erdmann
2012-06-27 14:46 André Erdmann
2012-06-26 15:42 André Erdmann
2012-06-22 18:13 André Erdmann
2012-06-21 16:55 André Erdmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1371286696.dea12476091298811456b8c8f6ca596ae195e7ee.dywi@gentoo \
--to=dywi@mailerd.de \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox