-
Notifications
You must be signed in to change notification settings - Fork 2
/
android-jumpstart.py
103 lines (84 loc) · 3.4 KB
/
android-jumpstart.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import shutil
import distutils
from subprocess import call
from distutils.dir_util import copy_tree
# Dev Notes
# Only use built in python libraries to keep configuration to minimum
# TODO
# 1. Refactor this code into classes
# 2. Auto push to newly created repo
# 3. build.gradle processor which allows to add/remove libraries on the fly
# and other stuff
# 4. Add a logger/silent mode
package=""
projectName=""
# Jumpstart Project Configuration
jumpstartPackage = "com.moldedbits.android"
jumpstartDirectoryName = "android-jumpstart"
jumpstartRepoURL = "https://github.com/moldedbits/android-jumpstart.git"
srcRelativeRoot = "/app/src/<srcSet>/java/"
def cloneJumpstartRepo():
call(["git", "clone", jumpstartRepoURL])
def createNewDirectories():
global projectName
while (not projectName):
projectName = raw_input("Enter new app name: ")
if(projectName == ""):
print("Project name cannot be empty")
# Keeping for testing purposes
# if(os.path.exists(projectName)):
# shutil.rmtree(projectName)
print("Copying stuff from " + jumpstartDirectoryName + " to " + projectName)
shutil.copytree(jumpstartDirectoryName, projectName)
print("Done Copying")
def changeSourcePackage(srcSet):
relativeRoot = srcRelativeRoot.replace("<srcSet>", srcSet)
print (srcSet + ": " + relativeRoot)
srcPath = projectName + relativeRoot + jumpstartPackage.replace(".", "/")
if(os.path.exists(srcPath)):
print("creating directory structure for new package: " + package)
packagePath = package.replace(".", "/")
currentPath = projectName + relativeRoot + "temp/" + packagePath
print("Copying stuff from " + srcPath + " to " + currentPath)
shutil.copytree(srcPath, currentPath)
print("Copying Done! Now removing old stuff")
shutil.rmtree(projectName + relativeRoot + "com")
print("Deleting Done!")
print("Moving new things where they belong!")
# copying things in a temp folder first in order to avoid same name clashes
print projectName + relativeRoot + "temp/" + " to " + projectName + relativeRoot
copy_tree(projectName + relativeRoot + "temp/", projectName + relativeRoot)
print("Removing temporary directory")
shutil.rmtree(projectName + relativeRoot + "temp")
else:
print "Path does not exist " + srcPath
def replacePackageInSource():
# traverse root directory, and list directories as dirs and files as files
for root, dirs, files in os.walk("./" + projectName):
for file in files:
filePath = root + "/" + file
if(".git/" in filePath):
print "Skipping: " + filePath
continue
else:
print(filePath)
fileText = ""
with open(filePath) as f:
fileText = f.read().replace(jumpstartPackage, package)
with open(filePath, "w") as f:
f.write(fileText)
cloneJumpstartRepo()
createNewDirectories()
while (not package):
package = raw_input("Enter new app package: ")
if(package == ""):
print("Package name cannot be empty")
# TODO this can be improved. Iterate the directory instead
changeSourcePackage("main")
changeSourcePackage("androidTest")
changeSourcePackage("debug")
changeSourcePackage("debugProd")
changeSourcePackage("release")
changeSourcePackage("test")
replacePackageInSource()