Exemple #1
0
    def delete_project(self):
        options = []
        if self.is_local():
            options.append("local")
        if self.is_remote():
            options.append("remote")
        if self.is_local() and self.is_remote():
            options.append("both")
        options.append("back")

        dialog = Dialog(
            title=f'Deleting Project "{self.entry.name}"',
            body=[
                f'Would you like to delete the local or remote version?',
                f'\n',
                f'\n',
                f'Warning: This is not reversible!',
            ])

        ans = dialog.get_mult_choice(options)

        if ans == "back":
            return True

        if ans == "local" or ans == "both":
            # Remove extracted folder and cached file
            File.delete(self.get_cache_file())
            Folder.delete(self.get_root_dir())

            # Remove hash from local db
            Hash.remove_project_hash(self)

            Menu.notice = f'Project "{self.entry.name}" deleted locally!'

        if ans == "remote" or ans == "both":
            if self.is_remote():
                # Delete compressed file
                project_id = self.entry.data["id"]
                if project_id:
                    Drive.delete(project_id)

                # Delete folder with scratch tracks and mixdowns
                folder_id = Drive.get_id(self.entry.name)
                if folder_id:
                    Drive.delete(folder_id)

                # Remove entry from remote db
                self.entry.destroy()

                Menu.notice = f'Project "{self.entry.name}" deleted remotely!'

        if ans == "both":
            Menu.notice = f'Project "{self.entry.name}" completely deleted!'

        return True
    def get_cloud_id():
        result = Drive.get_id(DATABASE_FILENAME)

        if not result:
            result = Database.create_database()

        # Something is wrong, can not get id of database nor create
        #  a new database on the cloud..
        if not result:
            raise Exception("Database.cloud_id can not be found!")

        return result
Exemple #3
0
    def upload_project(self):
        # Make sure our project is the most up-to-date
        if not self.is_up_to_date():
            Log(
                "There are updates for this project on the cloud!.. can not upload!",
                "warning")
            Log.press_enter()
            return False

        # Make sure we set the category if it's never been uploaded before
        if not self.is_remote():
            self.change_category(back=False)

        if not Dev.get("NO_OPEN_STUDIO_ONE"):
            if self.dialog_remove_unused_audio_files():
                if not self.open_studio_one():
                    return False

        # Create folder for mixdowns on cloud if it doesnt exist
        if not Drive.get_id(self.entry.name):
            Drive.mkdir(self.entry.name)

        # We will need to set the local hash on our own incase of failure
        #  to upload
        if not self.compress_project(set_hash=False):
            return False

        # Upload compressed project
        Log("Uploading.. please be patient", "notice")

        if not Dev.get("NO_LOF_UPLOAD"):
            result = Drive.upload(filepath=self.get_cache_file(),
                                  mimeType=Drive.mimeType['zip'])

            if not result:
                Log("Drive upload could not complete..", "warning")
                Log.press_enter()
                return False

            # Update local hash
            Hash.set_project_hash(self, Hash.create_hash_from_project(self))

            # Update remote hash if file was successfully uploaded
            self.entry.data["id"] = result
            self.entry.data["hash"] = Hash.get_project_hash(self)
            self.entry.update()

            Slack(
                f'{Slack.get_nice_username()} uploaded a new version of {Slack.make_nice_project_name(self.entry.name)}'
            )

            # Remove name from dirty list
            self.remove_dirty()

            # Since we successfully uploaded to the drive, we can now get
            #  rid of the *original song file
            File.recursive_overwrite(self.get_song_file(),
                                     self.get_song_file(version="original"))

        Log("Compression and upload complete!", "notice")

        return True
    def move_extracted_song_to_temp(self):
        # Make sure we don't have any dummy files
        self.remove_dummy_files()

        for location in ["Media", "Bounces"]:
            # Remove unused cached audio from location
            # Garbage collector for unused audio files
            mp3s = Folder.ls_files(self.get_temp_dir() / location, "mp3")
            wav_names = [
                x.stem
                for x in Folder.ls_files(self.get_root_dir() / location, "wav")
            ]
            for mp3 in mp3s:
                if mp3.stem not in wav_names:
                    File.delete(mp3)

            # Convert and move wavs to mp3s
            Log(f'Converting "{location}" wav\'s to mp3\'s')
            if not Audio.folder_to_mp3(self.get_root_dir() / location,
                                       self.get_temp_dir() / location):
                return False

            # Copy over dummy.json
            Log(f'Copying over "{location}" dummy.json')
            if self.get_dummy_db(location, temp=False).exists():
                File.recursive_overwrite(
                    self.get_dummy_db(location, temp=False),
                    self.get_dummy_db(location, temp=True),
                )

        # Upload scratch files and mixdowns to the cloud
        mp3s = Folder.ls_files(self.get_temp_dir() / "Media", "mp3",
                               "Scratch*")
        mp3s.extend(
            Folder.ls_files(self.get_temp_dir() / "Media", "mp3", "SCRATCH*"))
        mp3s.extend(Folder.ls_files(self.get_root_dir() / "Mixdown", "mp3"))

        for mp3 in mp3s:
            mix_folder_id = Drive.get_id(self.entry.name)

            if not Drive.get_id(mp3.name, mix_folder_id):
                Log(f'Uploading "{mp3.name}" to the cloud', "sub")
                mp3_id = Drive.upload(filepath=mp3,
                                      mimeType=Drive.mimeType["mp3"],
                                      parent=mix_folder_id)

                audio_type = "Scratch" if mp3.parent.name == "Media" else "#MIXDOWN#"
                Slack.send_link(
                    link_name=
                    f'{audio_type} for {self.entry.name}, "{mp3.name}"',
                    ID=mp3_id)
            else:
                Log(f'Audio file "{mp3.name}" already exists on the cloud!',
                    "sub")

        # Copy over mixdowns to temp
        Log("Copying over 'Mixdown' mp3's")
        Folder.copy(self.get_root_dir() / "Mixdown",
                    self.get_temp_dir() / "Mixdown")

        # Lastly, copy over the song file
        File.recursive_overwrite(self.get_song_file(temp=False),
                                 self.get_song_file(temp=True))

        return True