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
def download_and_extract(self): if not self.download_project(): Log("There was a problem downloading the update..", "warning") Log.press_enter() return False if not self.extract_project(): Log("There was a problem extracting the project..", "warning") Log.press_enter() return False return True
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
def get(key): data = Dev._get_data() if key in data: if "DEVELOPMENT" in data and not data["DEVELOPMENT"]: return False if data[key] and key != "DEVELOPMENT": Log(f'Development Mode: {key}', "warning") Log.press_enter() return data[key] else: data[key] = False File.set_json(FILEPATH, data) return False
def extract(filepath, destination): filepath = Path(filepath) destination = Path(destination) Log(f'Extracting "{filepath.stem}"..') if not Dev.get("NO_EXTRACT"): try: os.system( f"tar -xzf {filepath.absolute()} -C {destination.absolute()}" ) except Exception as e: Log(f'Failed to extract "{filepath.stem}"') Log(f'\n\n{e}\n\n', None) Log.press_enter() exit() Log(f'Finished extracting "{filepath.stem}!"')
def dialog_copy_new_name(self): dialog = Dialog( title=f'Make Duplicate of "{self.entry.name}"', body="Please enter a new name for your duplicate project.") new_name = dialog.get_result("New Name").lower() project_names = [ x.name.lower() for x in Folder.ls_folders(self.get_root_dir().parent) ] if not new_name in project_names: return new_name Log("That project name already exists.. Please try again!") Log.press_enter() return self.dialog_copy_new_name()
def compress(folderpath, destination): folderpath = Path(folderpath) destination = Path(destination) cwd = Path.cwd() Log(f'Compressing "{folderpath.stem}"..') if not Dev.get("NO_COMPRESS"): try: os.system( f'cd "{folderpath.parent}" && tar -czf "{destination.absolute()}" "{folderpath.name}" && cd "{cwd.absolute()}"' ) except Exception as e: Log(f'Failed to compress "{folderpath.stem}"') Log(f'\n\n{e}\n\n', None) Log.press_enter() exit() Log(f'Finished compressing "{folderpath.stem}!"')
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
def is_remote(self): # If the project exists on the cloud # Must check if remote "id" AND "hash" both exist if self.entry.data["id"]: if not self.entry.data["hash"]: Log( f'Project "{self.entry.name}" has remote ID but not remote hash!', "warning") Log.press_enter() return False return True else: if self.entry.data["hash"]: Log( f'Project "{self.entry.name}" does not have remote ID but has remote cache!', "warning") Log.press_enter() return False
def extract_project(self): Log("Extracting project..") # Create required folders in 'extracted_songs' self.create_required_folders() # Extract cache to 'temp' folder Log("Extracting project") Tar.extract(self.get_cache_file(), self.get_temp_dir().parent) # Copy and convert from 'temp' to 'extracted_songs' if not self.move_temp_to_extracted_songs(): # If function fails, remove broken extracted project # to prevent issues trying again. Folder.delete(self.get_root_dir()) Log("Could not move project from 'temp' to 'extracted_songs'..", "warning") Log.press_enter() return False return True
def get_result(self): ans = input(f' : ').lower() if ans == "b" and self.back: Log(f'Menu Answer: "back"', 'sub', quiet=True) print(f'') return "back" elif ans.isnumeric() and int(ans) <= len(self.options): result = (int(ans) -1) Log(f'Menu Answer: "{self.options[result]}"', 'sub', quiet=True) print(f'') return result print(f'') print(f'"{ans}" is not a valid option!') print(f'') Log(f'Menu Answer Not Valid!: "{ans}"', 'sub', quiet=True) Log.press_enter() return self.create_stack().run().get_result()
def run_migrations(): migrations = glob("migrations/*") migrations.sort() migrations = [Path(x) for x in migrations] current_version = Settings.get_version() result = True for migration in migrations: migration_version = Decimal(migration.stem.replace("_", ".")) if migration_version > current_version: Update.install_pip_packages() ans = Run.prg("python", migration.absolute(), useSubprocess=True) if ans == 0: Slack.upload_log() Log( f'There was a problem loading this migration file!\n "{migration.absolute()}"', "warning") Log.press_enter() # If there was an issue upgrading the migration, we don't want to set the new version return False elif ans != 1: Log("You must restart the program to finish the update!", "notice") Log.press_enter() result = False Settings.set_version(migration_version) # Push a notification to Slack Slack( f'{Settings.get_username(capitalize=True)} has upgraded to V{migration_version}!' ) return result
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 press_enter(self): Log.press_enter() Log(f'Dialog Press Enter', 'sub', quiet=True) return self
f'\n', f'\n', f'For more information, please refer to the repository commits and/or the slack channel.', f'\n', f'\n', ]) dialog.press_enter() # Rename src/dev.py to src/Dev.py File.rename("src/dev.py", "src/Dev.py") Log("A restart is needed to update the core!", "notice") Log( "Please ignore the following error message and restart the program.", "sub") Log.press_enter() # 0 = there was a problem upgrading # 1 = do not restart core # 2 = restart core is necessary sys.exit(0) dialog = Dialog( title="Upgrading to V1.3!", body=[ f'Lets go ahead and finish this dang update, shall we?!', f'\n', f'\n', ]) dialog.press_enter() # Now that we have updated the core, we can continue with the rest of the update!
def open_project(self): Log(f'Opening project "{self.entry.name}"..') # - Download any new updates / Download new project if not self.is_up_to_date(): Log("Project Update Available!") if not self.download_and_extract(): return False # Check for mutex lock mutex = self.is_locked() if mutex and mutex != Settings.get_username(capitalize=True): # Provide dialog to alert user that they can't save if not self.dialog_project_locked(): return True else: # Lets mutex lock this beach self.set_lock() # - Open Studio One Project if not self.open_studio_one(): return False if not self.is_remote(): # Lets ask if user wants to upload project if self.dialog_upload_new_project(): if not self.upload_project(): Log("An error occurred when trying to upload the project!","warning") Log.press_enter() return False elif self.is_dirty(): # Check for mutex lock mutex = self.is_locked() if mutex and mutex != Settings.get_username(capitalize=True): # Project was locked by someone else # Remove any saved changes Log("Resetting project.. Undoing changes..") self.extract_project() else: ans = self.dialog_upload_clear_cancel() if ans == "y": # Lets upload our changes! if not self.upload_project(): Log("An error occurred when trying to upload the project!","warning") Log.press_enter() self.remove_lock() return False # Remove our name from the dirty list if it exists self.remove_dirty() elif ans == "clear": self.extract_project() # Remove our name from the dirty list if it exists self.remove_dirty() else: # The user is not uploading new changes.. # Make sure to set the project to dirty! self.set_dirty() # Remove the lock we placed on when opening the project self.remove_lock() return True