소스 검색

allow subdirs in cache path

Tobias Simetsreiter 5 년 전
부모
커밋
e36ccf6b27
1개의 변경된 파일27개의 추가작업 그리고 8개의 파일을 삭제
  1. 27 8
      abe_setup.py

+ 27 - 8
abe_setup.py

@@ -15,11 +15,17 @@ def main():
 
     source_url = sane_origin_url( args.source_url, args.output_dir )
 
-    clone_repo_cached( args.output_dir, source_url.geturl(), args.tag,
-        cache_dir=args.cache_dir, fetch_origin=(not args.no_fetch_origin))
-    for ret in recurse_abe_submodules( args.output_dir, source_url, args.tag):
-        clone_repo_cached( ret.path, ret.remote, ret.ref,
+    if args.execute_command:
+        executeAbeCommand( args.output_dir, args.execute_command )
+    else:
+        clone_repo_cached( args.output_dir, source_url.geturl(), args.tag,
             cache_dir=args.cache_dir, fetch_origin=(not args.no_fetch_origin))
+    for ret in recurse_abe_submodules( args.output_dir, source_url, args.tag):
+        if args.execute_command:
+            executeAbeCommand( ret.path, args.execute_command )
+        else:
+            clone_repo_cached( ret.path, ret.remote, ret.ref,
+                cache_dir=args.cache_dir, fetch_origin=(not args.no_fetch_origin))
 
 
 def parser():
@@ -32,11 +38,21 @@ def parser():
     p.add_argument('-n', '--no_fetch_origin', action='store_true')
     p.add_argument('-t', '--tag', default='master')
     p.add_argument('-s', '--source_url', default=None)
+    p.add_argument('-x', '--execute_command', default=None)
     return p
 
+def executeAbeCommand( repo_path, command_name ):
+    import os
+    from subprocess import run
+    commandFileRel = os.path.join('.abe', 'commands', command_name)
+    commandFile = os.path.join(repo_path, commandFileRel)
+    if os.path.isfile(commandFile):
+        run([ commandFileRel ], check=True, cwd=repo_path)
 
 def recurse_abe_submodules(path, remote, ref, parent=None):
+    import os
     from urllib.parse import urlparse
+
     url = sane_origin_url( remote, path )
 
     sub = AbeSubmodule([path, url.geturl(), ref], AbeSubType.SUBMODULE, parent)
@@ -44,7 +60,6 @@ def recurse_abe_submodules(path, remote, ref, parent=None):
 
     subm = get_abe_tree( path )
 
-    import os
     for su in subm:
         newpath = os.path.normpath(os.path.join( sub.path, su.path))
         newurl = su.urlparse(url)
@@ -74,14 +89,18 @@ def origin_url(path):
     from urllib.parse import urlparse
     repo = Repo(path)
     for url in repo.remotes.origin.urls:
-        print("WOLOLO")
         return url
 
 def cache_path(cache, remote):
     import os.path
+    from urllib.parse import urlparse
     for url in remote:
-        sane_url = str(url).replace('/','_').replace( '@', '_').replace(':', '_')
-        return os.path.join( cache, sane_url)
+        sane_url = urlparse(url)
+        sane_url = sane_url._replace(
+            path = str(sane_url.path).lstrip('/'),
+            netloc = str(sane_url.netloc).replace('/','_').replace( '@', '_').replace(':', '_')
+        )
+        return os.path.join( cache, sane_url.netloc, sane_url.path)
 
 def real_relpath(dest, source='.'):
     import os.path