def get_expiring_file(self, dt=None, rel=None): """ Create a temp file, which expires at a given time. The temp file is stored under user's proximate directory. The file will expire (be deleted) after the given time. The actual deletion time is not very accurate. dt is a point in time, which is an instance of datetime.datetime. If dt == None, it is assumed to be now. If rel == None, it is assumed to be zero. Otherwise it is assumed to be a relative delay with respect to dt. rel is an instance of datetime.timedelta. Hint: Use scheduler.DAY and scheduler.SECOND to specify relative times """ assert(dt == None or isinstance(dt, datetime)) assert(rel == None or isinstance(rel, timedelta)) if dt == None: dt = datetime.now() if rel != None: dt = dt + rel # ISO date: YYYY-MM-DD-s, where s is a number of seconds in the day isodate = str(dt.date()) seconds = str(dt.hour * 3600 + dt.minute * 60 + dt.second) prefix = '%s-%s-%s-' % (self.EXPIRE_PREFIX, isodate, seconds) directory = self.community.get_user_dir() try: (fd, fname) = mkstemp(prefix=prefix, dir=directory) except OSError: warning('expiring_file: mkstemp() failed\n') return None xclose(fd) return fname
def compress_jpeg(self, pixbuf): (fd, filename) = tempfile.mkstemp(prefix = 'proximate-tmp-profile-pic-') xclose(fd) if not compress_jpeg(pixbuf, filename, TP_FACE_SIZE): return False self.remove_temp() self.tempfile = filename self.set_picture(filename) return True
def sym_dec(self, ciph, passphrase): """ Decrypts message with AES using given passphrase """ (rfd, wfd) = xpipe() os.write(wfd, passphrase + '\n') plain = xsystem([self.sslname, self.symmetric, '-d', '-pass', 'fd:' + str(rfd)], ciph) xclose(wfd) xclose(rfd) if not plain: warning('keymanagement: Unable to decrypt because %s does not exist\n' %(self.sslname)) return None return plain