def play_song(self, stup): group, title = stup f = self.music[group][title] pygame.mixer.music.load(f) ext = get_ext(f) # Can take a start time from the music's metadata! pygame.mixer.music.play(0, float(loaders[ext](f).get('gstart', [0])[0]))
def __build_map__(self, fn, modlines): """ Determine if import is local, if it is: add it to the depenedency struct. This method calls the appropriate method for the language based on the file extension. **Positional Arguments:** fn: - The file name to be added to the dependency struct modlines: - The lines containing "import" module statements """ if get_ext(fn).startswith(".py"): self.__python_build_map__(fn, modlines) else: raise NotImplementedError("File type {} not yet " "supported".format(get_ext(fn)))
def read(self, fn): """ Generic code reader to extract deps from a file. NOTE: The file extension is very important as it determines A LOT! ** Positional Arguments ** fn: - The filename to be read """ ext = get_ext(fn) if ext not in supported_fileexts: raise NotImplementedError("Cannot read file type " "{} yet".format(ext)) if ext == ".json": self.__json_build_map__(fn) return self.comm = comment[ext] self.ml_comm = ml_comment[ext] self.ml_cl_comm = close_ml_comment[ext] with open(fn, "rb") as f: dep_encoding_lines = [] ml_comm_flag = False lineno = -1 while True: lineno += 1 line = f.readline().strip() if not line: break if line.startswith(self.comm): continue elif not ml_comm_flag and line.startswith(self.ml_comm): ml_comm_flag = True continue elif line.startswith(self.ml_cl_comm) or \ line.endswith(self.ml_cl_comm): if not ml_comm_flag: raise ParsingException("Multiline " "comment closing block without opening block line {}: " "{}".format(lineno, fn)) ml_comm_flag = False # look for import statements for kywd in module_keywords[ext]: if line.startswith(kywd): dep_encoding_lines.append(line) if (dep_encoding_lines): # Ignore empty dep files self.__build_map__(fn, dep_encoding_lines)
def guess_type(fl): ext = get_ext(fl) if ext in IMAGE_TYPES: return T_IMAGE elif ext in ['wav']: return T_SOUND elif ext in ['mp3']: return T_MUSIC elif ext in ['ogg']: tag = loaders[ext](fl).get('gtype') if tag != None: # trump the 100 KB rule by setting the gtype tag in metadata return int(tag) elif os.path.getsize(fl) > 1024 * 100: # 100 KB return T_MUSIC else: return T_SOUND elif ext in ['py', 'pyc']: return T_CODE elif ext in ['pms']: return T_PLAYLIST else: return T_OTHER