def cwd(self, dir_name): path = normpath_url(join_url(self.cur_dir, dir_name)) if not path.startswith(self.root_dir): raise RuntimeError("Tried to navigate outside root %r: %r" % (self.root_dir, path)) self.cur_dir_meta = None self.cur_dir = path return self.cur_dir
def cwd(self, dir_name): path = normpath_url(join_url(self.cur_dir, dir_name)) if not path.startswith(self.root_dir): # paranoic check to prevent that our sync tool goes berserk raise RuntimeError("Tried to navigate outside root %r: %r" % (self.root_dir, path)) self.ftp.cwd(dir_name) self.cur_dir = path self.cur_dir_meta = None return self.cur_dir
def get_notices(website: str, access_token: str, as_dicts=False) -> List[Message]: response = requests.post( join_url(website, "api/3/komens/messages/noticeboard"), headers={"Authorization": "Bearer " + access_token}, ) data = json.loads(response.text) if as_dicts: return data return [ Message( title=message["Title"], sender=message["Sender"]["Name"], text=message["Text"], time_sent=parse_datetime(message["SentDate"]).timestamp(), attachments=[ Attachment(id_=attachment["Id"], name=attachment["Name"]) for attachment in message["Attachments"] ], ) for message in data["Messages"] ]
def get_homework(website: str, access_token: str, as_dicts=False) -> List[Homework]: response = requests.get( join_url(website, "api/3/homeworks"), headers={"Authorization": "Bearer " + access_token}, ) data = json.loads(response.text) if as_dicts: return data return [ Homework( id_=homework["ID"], subject=homework["Subject"]["Name"], teacher=homework["Teacher"], content=homework["Content"], time_start=parse_datetime(homework["DateStart"]).timestamp(), time_end=parse_datetime(homework["DateEnd"]).timestamp(), attachments=[ Attachment(id_=attachment["Id"], name=attachment["Name"]) for attachment in homework["Attachments"] ], ) for homework in data["Homeworks"] ]
def rmdir(self, dir_name): """Remove cur_dir/name.""" self.check_write(dir_name) path = normpath_url(join_url(self.cur_dir, dir_name)) # print("REMOVE %r" % path) shutil.rmtree(path)
def mkdir(self, dir_name): self.check_write(dir_name) path = normpath_url(join_url(self.cur_dir, dir_name)) os.mkdir(path)
def get_rel_path(self): path = relpath_url(self.target.cur_dir, self.target.root_dir) return normpath_url(join_url(path, self.name))