Example #1
0
    def _initialize_project(self):
        # Initialize a desktop
        if len(desktops.all_desktops) == 0:
            sys.exit(
                "Can't find any desktops for your OS. Contact the developer.")
        print('Available desktops are:')
        for i, desktop in enumerate(desktops.all_desktops):
            print("%d. %s" % (i + 1, desktop.HUMAN_READABLE_NAME))
        desktop_index = int(
            input('Please select the desktop you want to use: ')) - 1
        try:
            desktop = desktops.all_desktops[desktop_index]
        except IndexError:
            sys.exit('Please select a valid desktop!')
        self.used_desktop = desktop.CODE_NAME
        self._initialize_desktop_obj()

        # Initialize the programs
        print("Please say y if you want to use a program, n if you don't")
        for program in programs.all_programs:
            if askyn(program.HUMAN_READABLE_NAME):
                self.used_programs.append(program.CODE_NAME)

        self._initialize_program_objects()
        # Set everything up
        self.setup()
        # Save the project
        self.save()
        print("Project successfully initialized.")
        if askyn("Do you want to open the project?"):
            self.launch_project()
Example #2
0
    def create_project(self):
        """ Creates a new project. See _initialize_project for how to
        initialize a project.
        """
        if not self.project_name or self.project_name == DEFAULT_PROJECT_NAME:
            self.project_name = input('Please enter a name for your project: ')

        warnings = (
            "\nWARNING:\n"
            "Before creating a project, make sure that you have followed the install instructions.\n"
            "They can be found at: https://github.com/dorukkilitcioglu/persistd#getting-started\n"
            "Specifically, make sure you edit the settings to have BASE_PATH pointing to a folder\n"
            "and the program paths pointing to their relevant executables\n"
            "If any operation files due to permissions, make sure you run the script with admin rights.\n"
        )
        print(warnings)

        if os.path.exists(self.project_path):
            # Path exists, see if a persistd project has been initialized there
            if os.path.exists(self.persister_folder_path):
                # Project has been initialized before
                sys.exit("Error: project with the name %s already exists" %
                         self.project_name)
            elif askyn(
                    "Folder %s already exists, do you want to turn it into a persistd project?"
                    % self.project_name):
                return self._initialize_project()
            else:
                sys.exit(
                    "I don't think you really want to create this project...")
        else:
            os.makedirs(self.persister_folder_path)
            return self._initialize_project()
Example #3
0
def main(args):
    persister = Persister(SETTINGS.base_path, args.project_name)

    # First, take care of options that don't need the project_name
    if args.interactive:
        interactive()
    elif args.list_open:
        projects = list_projects(project_status='open')
        if askyn("Do you want to close the project?"):
            project_name = choose_project(projects)
            print('Closing %s' % project_name)
            persister = Persister(SETTINGS.base_path, project_name)
            persister.close_project()

    elif args.list_projects:
        project_name = get_project()
        print('Launching %s' % project_name)
        persister = Persister(SETTINGS.base_path, project_name)
        persister.launch_project()
    elif args.settings:
        get_setting()
    elif args.new:
        persister.create_project()
    # Then, check if project_name is set
    elif args.project_name and args.project_name != DEFAULT_PROJECT_NAME:
        if args.close:
            persister.close_project()
        elif args.persist:
            persister.persist_project()
        elif args.delete:
            if askyn("Deleting a project cannot be undone. Are you sure you want to delete %s?" % args.project_name):
                persister.delete_project()
            else:
                print("Project not deleted.")
        elif args.add:
            persister.add_program_to_project(args.add)
        elif args.remove:
            persister.remove_program_from_project(args.remove)
        else:
            persister.launch_project()
    # If we reach this, an incorrect configuration was given
    else:
        print('Error: project_name is required')
        args.parser.print_help()
        sys.exit(1)
Example #4
0
 def delete_project(self):
     """ Deletes a project, given user input
     """
     if not os.path.exists(self.project_path):
         sys.exit("Error: project with the name %s does not exist" %
                  self.project_name)
     elif os.path.exists(self.persister_folder_path) and askyn(
             "Do you want to keep the project files?"):
         # only delete persistd files
         self.destroy()
         shutil.rmtree(self.persister_folder_path)
         print("Deleted project files.")
     elif askyn(
             "Are you sure you want to delete all files? This action cannot be undone!"
     ):
         # delete all files
         self.destroy()
         shutil.rmtree(self.project_path)
         print("Deleted all files.")
     else:
         # chickened out
         print("Project not deleted.")
Example #5
0
    def launch_project(self):
        """ Opens a project
        """
        if os.path.exists(self.persister_folder_path):
            self.used_desktop_obj.create_desktop()
            self.used_desktop_obj.switch_to_desktop()
            for program_name, program_obj in self.used_program_objs.items():
                program_obj.start()
            self.save()
            SETTINGS.add_open_project(self.project_name)
        elif os.path.exists(self.project_path):
            if askyn(
                    "Folder %s already exists, do you want to turn it into a persistd project?"
                    % self.project_name):
                return self._initialize_project()
            else:
                print("Not turning %s into a persistd project." %
                      self.project_name)

        else:
            sys.exit("Error: project with the name %s does not exist" %
                     self.project_name)