-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
89 lines (73 loc) · 2.6 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# https://github.com/jitpack/jitpack.io/issues/5337#issuecomment-1363329648
# File name: gradle_cache_to_repo.py
# Author by: ksh ([email protected])
# Modifed by: Daehoon Kim ([email protected])
# History:
# [2019/05/31 11:27 AM] Created.
# [2020/12/25 10:22 AM] "Cannot create a file when that file already exists" error fix.
# [2022/04/07 20:24 PM] Windows file path length limitation error fix.
#
# Function: Convert android gradle cache into local maven repository.
# This local maven repository can be used in gradle offline build directly instead of gradle cache.
import os
from shutil import copyfile
from pathlib import Path
logging = False
src = str(Path( "~/.gradle/caches/modules-2/files-2.1" ).expanduser()) + "/"
dst = "./packages/"
group_count = 0
artifect_count = 0
def getTransformedPath(path):
transformedPath = path.replace("/", "\\")
transformedPath = "\\\\?\\" + transformedPath
return transformedPath
def makedirs(path):
if not os.path.exists(path):
os.makedirs(path)
return
def processGroup(group):
global group_count
group_count = group_count + 1
group_dir = group.replace(".", "/")
if (logging):
print(group_dir)
makedirs(dst + group_dir)
artifects = os.listdir(src + group)
for artifect in artifects:
processArtifect(group, group_dir, artifect)
return
def processArtifect(group, group_dir, artifect):
global artifect_count
artifect_count = artifect_count + 1
artifect_dir = dst + group_dir + "/" + artifect
makedirs(artifect_dir)
if (logging):
print(artifect)
src_artifect_dir = src + group + "/" + artifect
versions = os.listdir(src_artifect_dir)
for version in versions:
processVersion(group, artifect, artifect_dir, version)
return
def processVersion(group, artifect, artifect_dir, version):
version_dir = artifect_dir + "/" + version
makedirs(version_dir)
if (logging):
print(version)
src_version_dir = src + group + "/" + artifect + "/" + version
hashs = os.listdir(src_version_dir)
for hash in hashs:
hash_dir = src_version_dir + "/" + hash
files = os.listdir(hash_dir)
for file in files:
src_file_path = hash_dir + "/" + file
dst_file_path = version_dir + "/" + file
src_file_path = src_file_path
dst_file_path = dst_file_path
copyfile(src_file_path, dst_file_path)
return
groups = os.listdir(src)
for group in groups:
processGroup(group)
print("Done!")
print("Total %d groups"%(group_count))
print("Total %d artifects"%(artifect_count))