def g(p): pn = path_join(root, p) res = [] for fn in os.listdir(ut.to_str(pn)): fn = ut.to_unicode(fn) fnp = path_join(pn, fn) if os.path.isdir(ut.to_str(fnp)): if not fnmatch.fnmatch(fn, "_*"): res.extend(g(path_join(p, fn))) elif os.path.isfile(ut.to_str(fnp)): if fnmatch.fnmatch(fn, "*.jpg"): res.append(mk_pic(pn, fn)) return res
def path_join(*args): # The os. routines, as they are implemented on top of Open C # functions, they expect and return UTF-8 encoded strings, while # internally we use the "unicode" type. Hence we must convert back # and forth. ll = [ut.to_str(arg) for arg in args if arg is not None] return ut.to_unicode(apply(os.path.join, ll))
def refresh(self): if not self.dirty: return if os.path.isdir(ut.to_str(self.dir)): self.filelist = list_images(self.dir, self.mk_pic) self.dirty = False self.fs_observe()
def clear(self): self.mood = self.config.db.get("mood", u"") self.sender = self.config.db.get("sender", {}) self.recipient = self.config.db.get("recipient", private_recipient) self.picfile = self.config.db.get("picfile", None) if self.picfile and (not os.path.isfile(ut.to_str(self.picfile))): self.picfile = None self.clear_temporary()
def rename_picfile(self): if self.card.picfile is not None: dirname = ut.dirname(self.card.picfile) old_basename = ut.basename(self.card.picfile) new_basename = appuifw.query(u"Filename:", "text", old_basename) if new_basename is not None: new_picfile = dirname + "\\" + new_basename # Better check since on some platforms the target is # silently clobbered. if os.path.exists(ut.to_str(new_picfile)): appuifw.note(u"File by that name already exists", "error") return try: os.rename(ut.to_str(self.card.picfile), ut.to_str(new_picfile)) except: appuifw.note(u"Failed to rename photo", "error") return self.card.set_picfile(new_picfile)
def clear_temporary(self): """ Retains both sender and recipient. """ self.filedataname = None self.filedata = None self.btprox = None self.gsm = None self.gps = None self.gps_gui = None if os.path.isfile(ut.to_str(test_filedata)): self.filedataname = ut.basename(test_filedata) self.filedata = read_file(test_filedata) self.update_timestamp("all")
def makedirs(self): try: os.makedirs(ut.to_str(self.tn_path)) except: # Strangely throws an exception if the path already exists. pass