Пример #1
0
    def compress_project(self, set_hash=True):
        Log("Compressing project..", "notice")

        # Clean out temp project if it exists
        Log("Cleaning out temp folder")
        Folder.delete(self.get_temp_dir())

        # Extract cache if it exists
        if self.is_cached():
            Tar.extract(filepath=self.get_cache_file(),
                        destination=self.get_temp_dir().parent)
        else:
            Folder.create(self.get_temp_dir())

        # Create folders if they dont exist
        self.create_required_folders(temp=True, clean=False)

        # Copy from 'extracted_songs' to 'temp'
        if not self.move_extracted_song_to_temp():
            Log("Could not move project from 'extracted_songs' to 'temp'..",
                "warning")
            Log.press_enter()
            return False

        # Compress project to *.lof
        Tar.compress(folderpath=self.get_temp_dir(),
                     destination=self.get_cache_file())

        if set_hash:
            # Set new local hash
            Hash.set_project_hash(self, Hash.create_hash_from_project(self))

        return True
Пример #2
0
 def test_ubuntu_hash(self):
     path = "../ubuntu-20.04.2.0-desktop-amd64.iso"
     h = Hash()
     result = h.hashFile(path)
     self.assertEqual(
         result,
         "93bdab204067321ff131f560879db46bee3b994bf24836bb78538640f689e58f")
Пример #3
0
 def test_hashing(self):
     text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore " \
            "et dolore magna aliqua. "
     h = Hash()
     result = h.hashing(text)
     self.assertIn("md5", result)
     self.assertNotIn("shake_256", result)
Пример #4
0
 def test_file_hashing(self):
     path = "../ubuntu-18.04.5-desktop-amd64.iso"
     h = Hash()
     result = h.file_hashing(path)
     self.assertEqual(
         result,
         "f295570badb09a606d97ddfc3421d7bf210b4a81c07ba81e9c040eda6ddea6a0")
Пример #5
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
Пример #6
0
    def download_project(self):
        Log("Downloading project..")

        # Download new cache
        if not Drive.download(self.entry.data["id"], self.get_cache_file()):
            Log("An error occurred when trying to download the project..")
            Log.press_enter()
            # something went wrong while downloading
            return False

        # Update local cache 'db.json' with new hash
        Hash.set_project_hash(self, self.entry.data["hash"])

        return True
Пример #7
0
    def is_cached(self):
        # If the project has a *.lof file in 'compressed_songs' directory
        #  Must check if cache AND "hash" exist
        if self.get_cache_file().exists():
            if not Hash.get_project_hash(self):
                Log(f'Project "{self.entry.name}" is cached but not hashed!',
                    "warning")
                Log.press_enter()
                return False
            Log(f'Project "{self.entry.name}" is locally cached')
            return True
        else:
            if Hash.get_project_hash(self):
                Log(f'Project "{self.entry.name}" is hashed but not cached!',
                    "warning")
                Log.press_enter()

        Log(f'Project "{self.entry.name}" is not locally cached')
        return False
Пример #8
0
def clear_all_local_projects():
    result = Dialog("Clear Local Projects", [
        f'This will clear all locally cached projects to save',
        f'space on your hard drive.',
        f'\n',
        f'This will NOT:',
        f'\n',
        f'  - Delete any songs on the cloud',
        f'\n',
        f'  - Delete any dirty projects on your computer',
        f'\n',
        f'    that have not been uploaded yet',
        f'\n',
        f'  - Remove any projects that have never been',
        f'\n',
        f'    uploaded to the cloud yet',
        f'\n',
    ]).confirm()

    if result:
        for project in ProjectIndex.get_all_projects():
            if not project.is_dirty() and project.is_remote():
                # Just in case we have it locked
                project.remove_lock()

                # Remove extracted folder and cached file
                File.delete(project.get_cache_file())
                Folder.delete(project.get_root_dir())

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

            Menu.notice = f'Local projects cleared!'
    else:
        Menu.notice = f'No local projects were cleared..'
    return True
Пример #9
0
    def is_up_to_date(self):
        # This function checks to see if the locally extracted project
        #  is the most up-to-date project
        Log("Checking for updates..")

        # If this project is no extracted, then we are not up-to-date
        if not self.is_local():
            Log("Project is not extracted")
            return False

        ## If this project is dirty, then we are up-to-date.
        ##  We don't want to accidentally overwrite our changes!
        #if self.is_dirty():
        #    Log("Project is dirty")
        #    return True

        # If there is no remote, then it is up-to-date
        if not self.is_remote():
            Log("Project is not remote")
            return True

        # If there IS remote but not local cache, we are NOT up-to-date
        if not self.is_cached():
            Log("Project is not cached")
            return False

        # If we ARE extracted, AND remote, AND cached..
        #  Lets check if the two hashes compare
        local_hash = Hash.get_project_hash(self)
        if not local_hash:
            # We will need to re-download if local hash doesnt exist still
            #  If we reach this, something went wrong and we have to re-download
            return False

        # If local and remote hashes match, we are up-to-date
        if local_hash == self.entry.data["hash"]:
            return True

        # default return
        return False
Пример #10
0
 def test_create_table(self):
     tab = []
     h = Hash()
     result = h.createHashTable()
     self.assertEqual(type(tab), type(result))
Пример #11
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
Пример #12
0
from src.Hash import Hash

if __name__ == '__main__':
    text = "Nobody inspects the spammish repetition"
    h = Hash()
    result = h.hashing(text)
    print(result)
Пример #13
0
from src.Hash import Hash

if __name__ == '__main__':
    h = Hash()
    text = input("Enter some text: ")
    result1 = h.hashing(text)
    result2= h.hashFile("file.txt")
    result3=h.createPlot()