-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadproject.py
More file actions
89 lines (77 loc) · 2.09 KB
/
loadproject.py
File metadata and controls
89 lines (77 loc) · 2.09 KB
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
# -*- coding: utf-8 -*-
import os,codecs
from project import *
class LoadProjects(object):
def __init__(self,collection="default"):
self.collection=collection
projects,self.path=self.check_files()
self.projects={}
for i in projects:
if i!="":
pr=Project(i)
pr.notes=self.getList("notes",i)
pr.documents=self.getList("documents",i)
pr.jobs=self.getList("jobs",i)
pr.links=self.getList("links",i)
self.projects[i]=pr
def getList(self,what,i):
list={}
try:
f=codecs.open(self.path+"/"+i+"/"+what+".list",'r', 'utf-8')
lines=unicode(f.read()).split("\n")
for i in lines:
if what=="jobs":
line=i.split("|",3)
try:
note=line[3]
except:
note=None
list[line[0]]=[line[1],line[2],note]
else:
line=i.split("|",1)
list[line[0]]=line[1]
except:
pass
return list
def check_files(self):
workpath=os.environ['HOME']+"/.lbpm/"
collection_path=workpath+self.collection
if not os.path.isdir(workpath):
os.makedirs(workpath)
if not os.path.isdir(collection_path):
os.makedirs(collection_path)
try:
f=open(collection_path+"/projects.list",'r')
projects=f.read().split("\n")
except:
f=open(collection_path+"/projects.list",'w')
projects=[]
f.close()
return projects,collection_path
def create_project(self,name):
workpath=os.environ['HOME']+"/.lbpm/"
path=workpath+self.collection+"/"+name
if os.path.isdir(path):
import guihelpers
guihelpers.message("Warning","Project directory already exists - using it.",True)
else:
os.makedirs(path)
pr=Project(name)
pr.notes=self.getList("notes",name)
pr.documents=self.getList("documents",name)
pr.jobs=self.getList("jobs",name)
pr.links=self.getList("links",name)
self.projects[name]=pr
self.save_project_list()
def save_project_list(self):
file=""
for i in self.projects:
file+=i+"\n"
workpath=os.environ['HOME']+"/.lbpm/"
path=workpath+self.collection
f=open(path+"/projects.list",'w')
f.write(file)
f.close()
def delete_project(self,name):
del self.projects[name]
self.save_project_list()