Created
February 28, 2012 16:55
-
-
Save bussiere/1933629 to your computer and use it in GitHub Desktop.
liste models.py in django arborescence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
chemin = "D:\Documents\Projets_Perso\jackpoint\jackpoint" | |
def liste_app(chemin): | |
listfile = os.listdir(chemin) | |
listeapp = [] | |
for f in listfile : | |
if os.path.isdir(os.path.join(chemin, f)): | |
listindir = os.listdir(os.path.join(chemin, f)) | |
for f2 in listindir : | |
if f2 == "models.py": | |
listeapp.append(f) | |
return listeapp | |
def open_model(chemin): | |
listfile = os.listdir(chemin) | |
listemodel = [] | |
for f in listfile : | |
if os.path.isdir(os.path.join(chemin, f)): | |
listindir = os.listdir(os.path.join(chemin, f)) | |
for f2 in listindir : | |
if f2 == "models.py": | |
listemodel.append(chemin+"\\"+f+"\\models.py") | |
return listemodel | |
def liste_class_models(liste) : | |
listemodeles = {} | |
for l in liste : | |
f = open(l, 'r') | |
model = l.split("\\")[-2] | |
listeclasse = traitementligne(f) | |
listemodeles[model] = listeclasse | |
f.close() | |
return listemodeles | |
def traitementligne(f): | |
listeclasse = {} | |
classe = "" | |
for ligne in f.readlines(): | |
if ligne.find("class") != -1 and ligne.find("(") != -1 : | |
ligne = ligne.replace(" (","(") | |
classe = ligne.split("(")[0].split(" ")[-1] | |
listeclasse[classe] = [] | |
else : | |
if ligne.find("=") != -1 : | |
if classe != "" and classe != "=": | |
listeclasse[classe].append(ligne) | |
return listeclasse | |
def createdesign(chemin): | |
models = open_model(chemin) | |
for m in models : | |
listemodels = liste_class_models([m]) | |
print listemodels | |
m = m.replace("models.py","") | |
model = m.split("\\")[-2] | |
print model | |
print m | |
# os.mkdir(m+"_design") | |
# os.mkdir(m+"_design\\views") | |
# os.mkdir(m+"_design\\views\\all") | |
temp = """function(doc) { """ | |
for mod in listemodels.keys() : | |
temp += """ | |
if (doc.doc_type == "%s") | |
emit(doc._id, doc); \r\n | |
"""%mod | |
temp+= """\r\n}""" | |
f = open(m+"_design\\views\\all\\map.js", 'w') | |
f.write(temp) | |
f.close() | |
apps = liste_app(chemin) | |
print apps | |
models = open_model(chemin) | |
print models | |
print liste_class_models(models) | |
#createdesign(chemin) | |
for app in apps : | |
#os.system("python D:\Documents\Projets_Perso\jackpoint\jackpoint\manage.py schemamigration %s --initial"%app) | |
#os.system("python D:\Documents\Projets_Perso\jackpoint\jackpoint\manage.py migrate %s"%app) | |
#print """('jackpoint.%s', 'http://127.0.0.1:5984/%s'),"""%(app,app) | |
print """'jackpoint.%s',"""%(app) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment