[arch-commits] Commit in eclipse/trunk (PKGBUILD commonify)

Jan Steffens heftig at archlinux.org
Tue Jul 17 19:09:03 UTC 2018


    Date: Tuesday, July 17, 2018 @ 19:09:03
  Author: heftig
Revision: 361138

4.8-2: rust

Modified:
  eclipse/trunk/PKGBUILD
  eclipse/trunk/commonify

-----------+
 PKGBUILD  |   30 +++++++++++-------
 commonify |   97 ++++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 75 insertions(+), 52 deletions(-)

Modified: PKGBUILD
===================================================================
--- PKGBUILD	2018-07-17 19:04:32 UTC (rev 361137)
+++ PKGBUILD	2018-07-17 19:09:03 UTC (rev 361138)
@@ -7,9 +7,9 @@
 # Contributor: Marco Crosio <marco.crosio at gmail.com>
 
 pkgbase=eclipse
-pkgname=(eclipse-{common,java,jee,cpp,php,javascript})
+pkgname=(eclipse-{common,java,jee,cpp,php,javascript,rust})
 pkgver=4.8
-pkgrel=1
+pkgrel=2
 _release=photon-R
 pkgdesc="Highly extensible IDE"
 license=(EPL)
@@ -16,30 +16,38 @@
 arch=(x86_64)
 url="https://eclipse.org"
 makedepends=(python3)
-options=(!emptydirs)
 source=(commonify)
 noextract=()
 
+_sourcename() {
+  case $1 in
+    eclipse-common*) return 1 ;;
+    eclipse-rust   ) echo $1-$_release-incubation-linux-gtk-x86_64.tar.gz ;;
+    *              ) echo $1-$_release-linux-gtk-x86_64.tar.gz ;;
+  esac
+}
+
 for _pkg in ${pkgname[@]}; do
-  [[ $_pkg == 'eclipse-common' ]] && continue
-  source+=(http://ftp-stud.fht-esslingen.de/pub/Mirrors/eclipse/technology/epp/downloads/release/${_release/-//}/$_pkg-$_release-linux-gtk-x86_64.tar.gz)
-  noextract+=($_pkg-$_release-linux-gtk-x86_64.tar.gz)
+  _src=$(_sourcename $_pkg) || continue
+  source+=(http://ftp-stud.fht-esslingen.de/pub/Mirrors/eclipse/technology/epp/downloads/release/${_release/-//}/$_src)
+  noextract+=($_src)
   eval "package_$_pkg() { _package $_pkg; }"
 done
 
-sha256sums=('da1eaf6239cb0c2b5009cd8c261e96e7b17a7536b12fe60fcb1e903f5e67dbdc'
+sha256sums=('70ae1934385b0b7c25e5a76bfcd6d092bfd8d19ce451c3d909afa3cf2448452e'
             'd6f5ee4e5ced59d2cf6a9b7a992b7d01eb71480cd2353844ba47eb5c55a41816'
             '3bd00147fe545d1263dd10cdba9850d1fbeaed463582162bb15ddd0d6cfbd3ee'
             'aa6addf9748156402075db28d6fe839bc63e996075c3894550ca367b68e51b01'
             'adec5f5a676486d06ad6d2df40c83a754a498f022501b4b055573f7e56549615'
-            'e267b7b52ed16e858f938a4f2a145a422582543d619e4ccba2744a499c6a0a0a')
+            'e267b7b52ed16e858f938a4f2a145a422582543d619e4ccba2744a499c6a0a0a'
+            'cf4bb11a656eb4b5002bf51e6bc2841e710571250e97f0671897c18d61308dff')
 
 prepare() {
-  local pkg
+  local pkg src
   for pkg in ${pkgname[@]}; do
     mkdir $pkg
-    [[ $pkg == eclipse-common ]] && continue
-    bsdtar -xf "$pkg-$_release-linux-gtk-x86_64.tar.gz" -C $pkg --strip-components 1
+    src=$(_sourcename $pkg) || continue
+    bsdtar -xf $src -C $pkg --strip-components 1
   done
 }
 

Modified: commonify
===================================================================
--- commonify	2018-07-17 19:04:32 UTC (rev 361137)
+++ commonify	2018-07-17 19:09:03 UTC (rev 361138)
@@ -4,9 +4,9 @@
 from asyncio import (get_event_loop, gather, BoundedSemaphore, create_subprocess_exec,
                      IncompleteReadError)
 from enum import Enum, auto
-from logging import getLogger, basicConfig, INFO
-from os import cpu_count
-from pathlib import Path
+from logging import getLogger, basicConfig, INFO, DEBUG
+from os import cpu_count, renames, remove, removedirs
+from os.path import isdir, join as pjoin, split as psplit, relpath
 from sys import exit
 
 
@@ -27,11 +27,12 @@
                            help=f'extract {m.name} common files')
 
     parser.add_argument('-n', '--dry-run', action='store_true', help='Dry run (do nothing)')
+    parser.add_argument('-v', '--verbose', action='store_true', help='Raise verbosity')
     parser.add_argument('common_dir', metavar='COMMON_DIR',
                         help='common files directory to move to')
     parser.add_argument('targets', nargs='+', metavar='INPUT_DIR', help='directory to move from')
 
-    return parser.parse_args(args)
+    return parser.prog, parser.parse_args(args)
 
 
 class bounded_exec:
@@ -62,7 +63,7 @@
 
 
 async def diff(file1, file2):
-    async with bounded_exec('diff', '-q', str(file1), str(file2),
+    async with bounded_exec('diff', '-q', file1, file2,
                             stdin=DEVNULL, stdout=DEVNULL, stderr=DEVNULL) as p:
         ret = await p.wait()
 
@@ -84,26 +85,26 @@
     finally:
         fut.cancel()
 
+
+def removes(path):
+    remove(path)
+    head, tail = psplit(path)
+    if head and tail:
+        try:
+            removedirs(head)
+        except OSError:
+            pass
+
+
 def commonify_file(common_file, files):
-    common_file.parent.mkdir(parents=True, exist_ok=True)
     first, *rest = files
-    first.rename(common_file)
+    renames(first, common_file)
     for f in rest:
-        f.unlink()
+        removes(f)
 
 
-async def commonify_identical(common_file, files, *, dry_run=False):
-    if await identical(files):
-        if not dry_run:
-            commonify_file(common_file, files)
-        return 1
-    else:
-        logger.info('Divergent file: %s', common_file)
-        return 0
-
-
 async def find_files(path):
-    async with bounded_exec('find', str(path), '-type', 'f', '-print0',
+    async with bounded_exec('find', path, '-type', 'f', '-print0',
                             stdin=DEVNULL, stdout=PIPE, stderr=DEVNULL) as p:
         while True:
             try:
@@ -113,45 +114,59 @@
                 if not line:
                     break
                 raise
-            yield Path(line[:-1].decode())
+            yield line[:-1].decode()
 
 
-async def scan(target, files_targetfiles):
+async def scan_one(target, files):
     n = 0
     async for f in find_files(target):
-        files_targetfiles.setdefault(f.relative_to(target), []).append(f)
+        files.setdefault(relpath(f, target), []).append(target)
         n += 1
-    logger.info('%s: Found %d files', target, n)
+    logger.info('Found %d files in %r', n, target)
 
 
+async def scan(targets):
+    files = {}
+    await gather(*[scan_one(t, files) for t in targets])
+    return files
+
+
 def arg_dir(s):
-    p = Path(s)
-    if not p.is_dir():
+    if not isdir(s):
         raise ValueError(f'{s!r} is not a directory')
-    return p
+    return s
 
 
-async def main(settings):
-    ignore_len = settings.mode == Mode.nonconflicting
-    common_dir = arg_dir(settings.common_dir)
-    targets = [arg_dir(t) for t in settings.targets]
+async def commonify(settings, common_file, targets):
+    files = [pjoin(t, common_file) for t in targets]
 
-    files_targetfiles = {}
-    await gather(*[scan(t, files_targetfiles) for t in targets])
+    if not await identical(files):
+        logger.info("Divergent file %r", common_file)
+        return False
 
-    results = await gather(*[
-        commonify_identical(common_dir / f, tf, dry_run=settings.dry_run)
-        for f, tf in files_targetfiles.items()
-        if ignore_len or len(tf) == len(targets)
-    ])
+    if len(files) == len(settings.targets):
+        logger.debug("Identical file %r", common_file)
+    elif settings.mode == Mode.nonconflicting:
+        logger.debug("Nonconflicting file %r in %r", common_file, targets)
+    else:
+        logger.debug("Partly identical file %r in %r", common_file, targets)
+        return False
 
-    logger.info('%s: %d %s files',
-                common_dir, sum(results), settings.mode.name)
+    if not settings.dry_run:
+        commonify_file(pjoin(settings.common_dir, common_file), files)
+
+    return True
+
+
+async def main(settings):
+    files = await scan(arg_dir(t) for t in settings.targets)
+    results = await gather(*[commonify(settings, *ft) for ft in files.items()])
+    logger.info('%d %s files in %r', sum(results), settings.mode.name, settings.common_dir)
     return 0
 
 
 if __name__ == '__main__':
-    basicConfig(level=INFO)
-    settings = parse_args()
+    prog, settings = parse_args()
+    basicConfig(level=DEBUG if settings.verbose else INFO, format=f"{prog}: %(message)s")
     loop = get_event_loop()
     exit(loop.run_until_complete(main(settings)))



More information about the arch-commits mailing list