def classFilesAll(self, prop): d = {} target = self.filesAll if prop == 'type': for f in target: fi = file.file(f) key = fi.type tmp = d.get(key, []) tmp.append(fi.path) d[key] = tmp elif prop == 'ext': for f in target: fi = file.file(f) key = fi.ext tmp = d.get(key, []) tmp.append(fi.path) d[key] = tmp elif prop == 'month': for f in target: fi = file.file(f) t = time.strftime("%Y-%m", time.localtime(fi.created_at)) key = t tmp = d.get(key, []) tmp.append(fi.path) d[key] = tmp return d
def OrganizeFilesAll(self, ogzType): for k, v in self.classFilesAll(ogzType).items(): if not k == '': kpath = os.path.join(self.path, k) if not os.path.exists(kpath): os.mkdir(kpath) for f in v: file.file(f).move(kpath)
def put_file(service, cache, location, parent_id, std_in): title = os.path.basename(location) if title.startswith('.'): return cache if std_in: try: with open(location, 'w') as f: while True: f.write(input() + '\n') except: pass file_metadata = { 'name': title, 'parents': [ parent_id ] } print('uploading - ' + location) media = MediaFileUpload(location, resumable=True) f = service.files().create(body=file_metadata, media_body=media, fields='id, mimeType').execute() cache.files[f['id']] = file(f['id'], title, f['mimeType'], False, False) cache.directory_tree[f['id']] = [ parent_id ] if std_in: os.remove(title) return cache
def mkdir(service, folder_name, cache): """Create a folder in the current working directory Args: folder_name: name of the folder to be created """ if os.path.dirname(folder_name) != '': parent = name_to_id(os.path.dirname(folder_name), cache)[-1] else: parent = getcwd() folder_name = os.path.basename(folder_name) file_metadata = { 'name' : folder_name, 'mimeType' : 'application/vnd.google-apps.folder', 'parents' : [ parent ] } print_blue('Creating directory - ' + folder_name) f = service.files().create(body=file_metadata).execute() cache.files[f['id']] = file(f['id'], folder_name, 'application/vnd.google-apps.folder', False, False) cache.directory_tree[f['id']] = [ parent ] return cache
def sizeAll(self): for x in self.filesAll: self._sizeAll += file.file(x).size return self._sizeAll
def size(self): for x in self.files: self._size += file.file(x).size return self._size