Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # grub2_music_maker.py
- import sys
- def midi_to_notes(file_name):
- with open(file_name, "rb") as file:
- midi_data = file.read()
- notes = []
- for i in range(len(midi_data)):
- notes.append(str(midi_data[i]))
- return " ".join(notes)
- def play_notes(notes):
- for note in notes.split():
- sys.stdout.write("\x07") # Beep through the PC speaker
- sys.stdout.flush()
- time.sleep(0.1)
- def save_to_grub(notes):
- with open("/etc/default/grub", "r") as file:
- lines = file.readlines()
- for i in range(len(lines)):
- if "GRUB_INIT_TUNE=" in lines[i]:
- lines[i] = "GRUB_INIT_TUNE=\"" + notes + "\"\n"
- with open("/etc/default/grub", "w") as file:
- file.writelines(lines)
- if __name__ == "__main__":
- file_name = sys.argv[1]
- notes = midi_to_notes(file_name)
- choice = input("Do you want to play the notes (p) or save them to GRUB (g)? ")
- if choice == "p":
- play_notes(notes)
- elif choice == "g":
- save_to_grub(notes)
- print("Notes saved to GRUB. Please run 'sudo update-grub' to apply changes.")
- else:
- print("Invalid choice.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement