def run(self, fd): result = [] for i in self.datastore.collection_list(): result.append(dump_collection(self.datastore, i)) with os.fdopen(fd.fd, mode='w', closefd=False) as f: dump(result, f)
def run(self, fd): result = [] for i in self.datastore.collection_list(): result.append(dump_collection(self.datastore, i)) try: with os.fdopen(fd.fd, mode='w', closefd=False) as f: dump(result, f) except OSError as err: raise TaskException(err.errno, err.strerror)
def change_password(self, username, password): try: with open(self.passwd_filename, 'r') as f: passwd = load(f) user = first_or_default(lambda u: u['username'] == username, passwd) if not user: raise OSError(errno.ENOENT, os.strerror(errno.ENOENT)) user.update({ 'unixhash': crypted_password(password), 'smbhash': nt_password(password), 'password_changed_at': datetime.datetime.utcnow() }) with open(self.passwd_filename + '.tmp', 'w') as f: dump(passwd, f, indent=4) os.rename(self.passwd_filename + '.tmp', self.passwd_filename) shutil.copy(self.passwd_filename, os.path.join('/conf/base', self.passwd_filename[1:])) self.__load() except (IOError, ValueError) as err: logger.warn('Cannot change password: {0}'.format(str(err))) raise