def enable(self, hookname): # TODO: remove multiple blank lines when writing if self.is_enabled(hookname): return # nothing to do if not self.can_enable(hookname): return # XXX err more gracefully def print_hook(f): print >> f, '%s%s' % (os.linesep, self.marker()) print >> f, command_line(self.env.path, hookname, *self.args()) filename = self.filename(hookname) if os.path.exists(filename): projects = self.projects_enabled(hookname) if projects is None: f = file(filename, 'a') print_hook(f) else: project = os.path.realpath(self.env.path) index, lines, projects = projects projects.append(project) lines[index] = command_line(projects, hookname, *self.args()) f = file(filename, 'w') for line in lines: print >> f, line else: f = self.create(hookname) print_hook(f) f.close()
def enable(self, hookname): # TODO: remove multiple blank lines when writing if self.is_enabled(hookname): return # nothing to do if not self.can_enable(hookname): return # XXX err more gracefully def print_hook(f): print >> f, '%s%s' % (os.linesep, self.marker()) print >> f, command_line(self.env.path, hookname, *self.args()) filename = self.filename(hookname) if os.path.exists(filename): projects = self.projects_enabled(hookname) if projects is None: f = file(filename, 'a') print_hook(f) else: project = os.path.realpath(self.env.path) index, lines, projects = projects projects.append(project) lines[index] = command_line(projects, hookname, *self.args()) f = file(filename, 'w') for line in lines: print >> f, line else: f = self.create(hookname) print_hook(f) f.close()
def disable(self, hookname): if not self.is_enabled(hookname): return index, lines, projects = self.projects_enabled(hookname) projects = [os.path.realpath(project) for project in projects] project = os.path.realpath(self.env.path) projects.remove(project) if projects: lines[index] = command_line(projects, hookname, *self.args()) else: lines.pop(index) # TODO: list bounds checking if lines[index - 1] == self.marker(): index = index - 1 lines.pop(index) if not lines[index - 1].strip(): lines.pop(index - 1) f = file(self.filename(hookname), 'w') for line in lines: print >> f, line f.close()
def disable(self, hookname): if not self.is_enabled(hookname): return index, lines, projects = self.projects_enabled(hookname) projects = [ os.path.realpath(project) for project in projects ] project = os.path.realpath(self.env.path) projects.remove(project) if projects: lines[index] = command_line(projects, hookname, *self.args()) else: lines.pop(index) # TODO: list bounds checking if lines[index-1] == self.marker(): index = index-1 lines.pop(index) if not lines[index-1].strip(): lines.pop(index-1) f = file(self.filename(hookname), 'w') for line in lines: print >> f, line f.close()
def print_hook(f): print >> f, '%s%s' % (os.linesep, self.marker()) print >> f, command_line(self.env.path, hookname, *self.args())
def print_hook(f): print >> f, '%s%s' % (os.linesep, self.marker()) print >> f, command_line(self.env.path, hookname, *self.args())