forked from emanuelez/PySynergy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileObject.py
121 lines (90 loc) · 3.44 KB
/
FileObject.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
# encoding: utf-8
"""
FileObject.py
Created by Emanuele Zattin and Aske Olsson on 2011-01-26.
Copyright (c) 2011 Nokia. All rights reserved.
"""
import SynergyObject
from datetime import datetime
class FileObject(SynergyObject.SynergyObject):
""" This class wraps a Synergy object with information about author, create time, tasks, status etc. """
def __init__(self, objectname, delimiter, owner, status, create_time, task):
super(FileObject, self).__init__(objectname, delimiter, owner, status, create_time, task)
self.content = None
self.commit_message = None
self.integrate_time = None
self.predecessors = None
self.successors = None
self.path = None
self.dir_changes = None
def get_integrate_time(self):
return self.integrate_time
def set_integrate_time(self, time):
self.integrate_time = time
def get_predecessors(self):
return self.predecessors
def set_predecessors(self, predecessors):
self.predecessors = predecessors
def add_predecessor(self, predecessor):
if self.predecessors is None:
self.predecessors = [predecessor]
else:
self.predecessors.append(predecessor)
def set_successors(self, successors):
self.successors = successors
def add_successor(self, successor):
if self.successors is None:
self.successors = [successor]
else:
self.successors.append(successor)
def get_successors(self):
return self.successors
def get_path(self):
return self.path
def set_path(self, path):
self.path = path
def get_content(self):
return self.content
def set_content(self, content):
self.content = content
def set_dir_changes(self, dir_changes):
self.dir_changes = dir_changes
def get_dir_changes(self):
return self.dir_changes
def add_dir_changes(self, dir_changes):
if self.dir_changes:
#append new changes
for k in dir_changes:
l1 = dir_changes[k]
l2 = self.dir_changes[k]
l1.extend(l2)
self.dir_changes[k] = list(set(l1))
else:
self.dir_changes = dir_changes
def set_attributes(self, attributes):
self.attributes = attributes
self.integrate_time = self.find_status_time('integrate', self.attributes['status_log'])
#self.content = self.attributes['source']
#self.commit_message = self.find_commit_message_from_content()
def get_attributes(self):
return attributes
def find_status_time(self, status, status_log):
earliest = datetime.today()
for line in status_log.splitlines():
if status in line and 'ccm_root' not in line:
time = datetime.strptime(line.partition(': Status')[0], "%a %b %d %H:%M:%S %Y")
if time < earliest:
earliest = time
return earliest
def find_commit_message_from_content(self):
start = self.content.find('REASON')
newline_end = self.content.find('\n\n', start)
version_end = self.content.find('VERSION', start)
if newline_end != -1 and version_end != -1 and newline_end < version_end:
end = newline_end
else:
end = version_end
if start != -1 and end != -1:
return self.content[start:end]
return ''