Ejemplo n.º 1
0
 def print_usage_help(self):
     printout(
         _("Usage: con-admin </path/to/project> "
           "[command [subcommand] [option ...]]\n"))
     printout(
         _("Invoking con-admin without command starts "
           "interactive mode."))
Ejemplo n.º 2
0
 def print_usage_help(self):
     printout(
         _("Usage: <appname> </path/to/projenv> "
           "[command [subcommand] [option ...]]\n"))
     printout(
         _("Invoking <appname> without command starts "
           "interactive mode."))
Ejemplo n.º 3
0
 def print_line(self):
     """
     Print a line :P
     """
     printout(
         _("""--------------------------------------------------------------------------"""
           ))
Ejemplo n.º 4
0
    def print_interactive_header(self):
        printout(
            _("""[Generic CMD App]
Copyright (c) 2014 Moritz Wundke

Type:  '?' or 'help' for help on commands.
        """))
Ejemplo n.º 5
0
 def do_plugin(self, line):
     args = self.unicod_safe_split(line)
     if args[0] == 'list':
         printout(_("TODO: register plugins"))
     elif args[0] == 'setapp' and len(args) == 2:
         printout(_("TODO: set app to life in env"))
     else:
         self.do_help('plugin')
Ejemplo n.º 6
0
    def print_interactive_header(self):
        printout(
            _("""[Welcome to Concurrent Environment Admin] %(version)s
Copyright (c) 2014 Moritz Wundke

Type:  '?' or 'help' for help on commands.
        """,
              version=CONCURRENT_VERSION))
Ejemplo n.º 7
0
 def do_plugin(self, line):
     args = self.unicod_safe_split(line)
     if args[0] == 'list':
         printout(_("TODO: register plugins"))
     elif args[0] == 'setapp' and len(args)==2:
         printout(_("TODO: set app to life in env"))
     else:
         self.do_help ('plugin')
Ejemplo n.º 8
0
    def delete(self):
        """
        Delete an environment is like uninstalling it
        """

        printout(_(" Uninstalling Components"))
        for deleter in self.delete_components:
            deleter.env_delete()

        printout(_(" Environment successfully uninstalled"))
Ejemplo n.º 9
0
    def delete(self):
        """
        Delete an environment is like uninstalling it
        """

        printout(_(" Uninstalling Components"))
        for deleter in self.delete_components:
            deleter.env_delete()

        printout(_(" Environment successfully uninstalled"))
Ejemplo n.º 10
0
    def do_delete(self, line):
        def delete_error(msg):
            printerr(_("Delete for '%(env)s' failed:", env=self.envname), "\n",
                     msg)

        # get arguments
        env_dir = None
        args = self.unicod_safe_split(line)

        # Interactive or not
        interactive_delete = False

        if len(args) == 1 and not args[0]:
            returnvals = self.get_delete_data()
            env_dir = returnvals[0]
            interactive_delete = True
        elif len(args) != 1:
            delete_error('Wrong number of arguments: %d' % len(args))
            return 2
        else:
            env_dir = args[0]

        # Set the right env dir
        self.envname = env_dir

        if self.__env and self.__env.basepath == self.envname:
            delete_error(
                "Can not delete currently open environment! Close and open the admin!"
            )
            return 2

        # Open env
        if not self.ceck_env():
            delete_error("Environment not created or corrupted!")
            return 2

        if interactive_delete:
            no_option = "no"
            value = raw_input(
                _("Delete Environment? [%(default)s]> ",
                  default=no_option)).strip() or no_option
            # Ask again if we want to delete the env!
            value = value.lower() in get_true_values()
            if not value:
                printout(_("Delete Canceled!"))
                return

        # Delete it!
        printout(_("Starting Delete Process"))
        self.__env.delete()

        # Close environment!
        self.__env.shutdown()

        # It's deleted, so purge it!
        printout(
            _(" Purge env directory %(purge_dir)s", purge_dir=self.envname))
        purge_dir(self.envname)
        printout(_("Environment successfully deleted"))
Ejemplo n.º 11
0
    def get_delete_data(self):
        returnvals = []
        # Basic instructions
        self.print_line()
        printout(_("""Starting Interactive environment deletion at <%(envname)s>""",
                   envname=self.envname))
        self.print_line()

        # Env path
        printout(_(""" Now enter the absolute path to the environment that will be deleted."""))
        path = self.envname
        returnvals.append(raw_input(_("</path/to/project> [%(default)s]> ",
                                      default=path)).strip() or path)
        self.print_line()
        return returnvals
Ejemplo n.º 12
0
    def do_delete(self, line):
        def delete_error(msg):
            printerr(_("Delete for '%(env)s' failed:", env=self.envname),
                     "\n", msg)

        # get arguments
        env_dir = None
        args = self.unicod_safe_split(line)

        # Interactive or not
        interactive_delete = False

        if len(args) == 1 and not args[0]:
            returnvals = self.get_delete_data()
            env_dir = returnvals[0]
            interactive_delete = True
        elif len(args) != 1:
            delete_error('Wrong number of arguments: %d' % len(args))
            return 2
        else:
            env_dir = args[0]

        # Set the right env dir
        self.envname = env_dir

        if self.__env and self.__env.basepath == self.envname:
            delete_error("Can not delete currently open environment! Close and open the admin!")
            return 2

        # Open env
        if not self.ceck_env():
            delete_error("Environment not created or corrupted!")
            return 2

        if interactive_delete:
            no_option = "no"
            value = raw_input(_("Delete Environment? [%(default)s]> ",
                                default=no_option)).strip() or no_option
            # Ask again if we want to delete the env!
            value = value.lower() in get_true_values()
            if not value:
                printout(_("Delete Canceled!"))
                return

        # Delete it!
        printout(_("Starting Delete Process"))
        self.__env.delete()

        # Close environment!
        self.__env.shutdown()

        # It's deleted, so purge it!
        printout(_(" Purge env directory %(purge_dir)s", purge_dir=self.envname))
        purge_dir(self.envname)
        printout(_("Environment successfully deleted"))
Ejemplo n.º 13
0
    def get_delete_data(self):
        returnvals = []
        # Basic instructions
        self.print_line()
        printout(
            _("""Starting Interactive environment deletion at <%(envname)s>""",
              envname=self.envname))
        self.print_line()

        # Env path
        printout(
            _(""" Now enter the absolute path to the environment that will be deleted."""
              ))
        path = self.envname
        returnvals.append(
            raw_input(_("</path/to/project> [%(default)s]> ",
                        default=path)).strip() or path)
        self.print_line()
        return returnvals
Ejemplo n.º 14
0
    def get_createenv_data(self):
        returnvals = []

        # Basic instructions
        self.print_line()
        printout(
            _("""Starting Interactive environment creation at <%(envname)s>

This is the interactive guide on environment creation.
Just follow the instructions.""",
              envname=self.envname))
        self.print_line()

        # Env path
        printout(
            _(""" Now enter the absolute path where your environment should be created."""
              ))
        path = self.envname
        returnvals.append(
            raw_input(_("</path/to/project> [%(default)s]> ",
                        default=path)).strip() or path)
        self.print_line()

        # Environment app
        printout(
            _(""" Enter the name of the project you are about to create"""))
        path = "My Project"
        returnvals.append(
            raw_input(_("project_name [%(default)s]> ", default=path)).strip()
            or path)
        self.print_line()
        return returnvals
Ejemplo n.º 15
0
    def get_createenv_data(self):
        returnvals = []

        # Basic instructions
        self.print_line()
        printout(_("""Starting Interactive environment creation at <%(envname)s>

This is the interactive guide on environment creation.
Just follow the instructions.""",
                   envname=self.envname))
        self.print_line()

        # Env path
        printout(_(""" Now enter the absolute path where your environment should be created."""))
        path = self.envname
        returnvals.append(raw_input(_("</path/to/project> [%(default)s]> ",
                                      default=path)).strip() or path)
        self.print_line()

        # Environment app
        printout(_(""" Enter the name of the project you are about to create"""))
        path = "My Project"
        returnvals.append(raw_input(_("project_name [%(default)s]> ",
                                      default=path)).strip() or path)
        self.print_line()
        return returnvals
Ejemplo n.º 16
0
    def get_backup_data(self):
        returnvals = []
        # Basic instructions
        self.print_line()
        printout(
            _("""Starting Interactive environment backup at <%(envname)s>

Follow the instructions to backup the environment!""",
              envname=self.envname))
        self.print_line()

        # Env path
        printout(
            _(""" Now enter the absolute path to the environment that you will backup."""
              ))
        path = self.envname
        returnvals.append(
            raw_input(_("</path/to/project> [%(default)s]> ",
                        default=path)).strip() or path)
        self.print_line()

        # Environment app
        printout(_(""" Destination file for tghe backup"""))
        dest = self.__env.backup_get_default_file_name()
        returnvals.append(
            raw_input(_("</dest/file> [%(default)s]> ", default=dest)).strip()
            or dest)

        return returnvals
Ejemplo n.º 17
0
    def get_recover_data(self):
        returnvals = []
        # Basic instructions
        self.print_line()
        printout(
            _("""Starting Interactive environment recovering at <%(envname)s>

Follow the instructions to recover environment!""",
              envname=self.envname))
        self.print_line()

        # Env path
        printout(
            _(""" Now enter the absolute path where your environment should be created."""
              ))
        path = self.envname
        returnvals.append(
            raw_input(_("</path/to/project> [%(default)s]> ",
                        default=path)).strip() or path)
        self.print_line()

        # Environment app
        printout(_(""" Enter path where the backup file is locates"""))
        prompt = _("Backup File [</path/to/file>]> ")
        returnvals.append(raw_input(prompt).strip())

        return returnvals
Ejemplo n.º 18
0
def zip_create_from_folder( source_dir, dest_file='', exclude_dirs=[], include_root=True ):
    """
    Method that just.
    Inpired by: http://stackoverflow.com/questions/458436/adding-folders-to-a-zip-file-using-python
    @param source_dir: The folder that will be zipped
    @param dest_file: Destination zip file. If not set `source_dir` base name will be used
    @param exclude_dirs: List of directories that should be excluded 
    @param include_root: If True `source_dir` will be included in the resulting zip   
    """  
    # Build right dest_file name and verify if source exists
    if dest_file is '':
        dest_file = os.path.join(os.path.basename(source_dir),'.zip')
        
    if not os.path.isdir(source_dir):
        raise OSError("source_folder argument must point to a valid directory.")
    
    base_dir, root_dir = os.path.split(source_dir)
    
    #Little nested function to prepare the proper archive path
    def trim_path(path):
        archive_dir = path.replace(base_dir, "", 1)
        if base_dir:
            archive_dir = archive_dir.replace(os.path.sep, "", 1)
        if not include_root:
            archive_dir = archive_dir.replace(root_dir + os.path.sep, "", 1)
        return os.path.normcase(archive_dir)
    
    # nested function to exclude a file from beeing added to the zip file
    def should_be_excluded( dir ):
        for excluded_dir in exclude_dirs:
            if root.rfind(excluded_dir) > 0:
                return True
        return False
    
    # Create file
    out_file = zip_open(dest_file)
    
    printout(_( "Creating Zip %(NewZip)s", NewZip=dest_file))
    
    for root, dirs, files in os.walk(source_dir):
        for file_name in files:
            # Check excluded dirs!
            if not should_be_excluded( root ):                
                # Write the file
                file_path = os.path.join(root, file_name)
                printout(_( " - Adding %(file_path)s", file_path=trim_path(file_path)))
                out_file.write(file_path, trim_path(file_path))
        
        # Empty folder needs to be added too       
        if not files and not dirs:
            zipInfo = zipfile.ZipInfo(trim_path(root) + "/")
            out_file.writestr(zipInfo, "")
    
    out_file.close()
    printout(_( "Zip file created successfully!"))
Ejemplo n.º 19
0
    def recover_env(self, backupfile, dest_env=None, ):
        """
        recreate an env from a backup file
        """
        if zip_is_valid( backupfile ):
            if not dest_env:
                dest_env = self.envname
            self.print_line()
            printout(_("Starting recovery"))
            printout(_("\trecovery file: \t%(backupfile)s",backupfile=backupfile))
            printout(_("\tenv path: \t%(dest_env)s",dest_env=dest_env))

            #TODO: call self.__env.restored() on the recovered env!
        else:
            raise RecoverBackupFileError(_("Invalid zip file for recovery!"))
Ejemplo n.º 20
0
    def recover_env(
        self,
        backupfile,
        dest_env=None,
    ):
        """
        recreate an env from a backup file
        """
        if zip_is_valid(backupfile):
            if not dest_env:
                dest_env = self.envname
            self.print_line()
            printout(_("Starting recovery"))
            printout(
                _("\trecovery file: \t%(backupfile)s", backupfile=backupfile))
            printout(_("\tenv path: \t%(dest_env)s", dest_env=dest_env))

            #TODO: call self.__env.restored() on the recovered env!
        else:
            raise RecoverBackupFileError(_("Invalid zip file for recovery!"))
Ejemplo n.º 21
0
    def get_recover_data(self):
        returnvals = []
        # Basic instructions
        self.print_line()
        printout(_("""Starting Interactive environment recovering at <%(envname)s>

Follow the instructions to recover environment!""",
                   envname=self.envname))
        self.print_line()

        # Env path
        printout(_(""" Now enter the absolute path where your environment should be created."""))
        path = self.envname
        returnvals.append(raw_input(_("</path/to/project> [%(default)s]> ",
                                      default=path)).strip() or path)
        self.print_line()

        # Environment app
        printout(_(""" Enter path where the backup file is locates"""))
        prompt = _("Backup File [</path/to/file>]> ")
        returnvals.append(raw_input(prompt).strip())

        return returnvals
Ejemplo n.º 22
0
    def get_backup_data(self):
        returnvals = []
        # Basic instructions
        self.print_line()
        printout(_("""Starting Interactive environment backup at <%(envname)s>

Follow the instructions to backup the environment!""",
                   envname=self.envname))
        self.print_line()

        # Env path
        printout(_(""" Now enter the absolute path to the environment that you will backup."""))
        path = self.envname
        returnvals.append(raw_input(_("</path/to/project> [%(default)s]> ",
                                      default=path)).strip() or path)
        self.print_line()

        # Environment app
        printout(_(""" Destination file for tghe backup"""))
        dest = self.__env.backup_get_default_file_name()
        returnvals.append(raw_input(_("</dest/file> [%(default)s]> ",
                                      default=dest)).strip() or dest)

        return returnvals
Ejemplo n.º 23
0
 def print_help_header(self):
     printout(_("Concurrent - Environment Admin"))
Ejemplo n.º 24
0
    def print_interactive_header(self):
        printout(_("""[Welcome to Concurrent Environment Admin] %(version)s
Copyright (c) 2014 Moritz Wundke

Type:  '?' or 'help' for help on commands.
        """, version=CONCURRENT_VERSION))
Ejemplo n.º 25
0
def zip_print_info( zip_file_name ):
    zf = zipfile.ZipFile( zip_file_name )
    for info in zf.infolist():
        printout(_(info.filename))
        printout(_("tComment:t",info.comment))
        printout(_("tModified:t", datetime.datetime(*info.date_time)))
        printout(_("tSystem:tt", info.create_system, '(0 = Windows, 3 = Unix)'))
        printout(_("tZIP version:t", info.create_version))
        printout(_("tCompressed:t", info.compress_size, 'bytes'))
        printout(_("tUncompressed:t", info.file_size, 'bytes'))
Ejemplo n.º 26
0
 def do_quit(self, line):
     printout(_("\nSee you soon!"))
     sys.exit()
Ejemplo n.º 27
0
 def print_help_header(self):
     printout(_("Concurrent - Console application"))
Ejemplo n.º 28
0
 def print_help_header(self):
     printout(_("Concurrent - Console application"))
Ejemplo n.º 29
0
    def do_createenv(self, line):
        """
        Create environment by passed arguments or interactively
        """
        def createenv_error(msg):
            printerr(_("Createenv for '%(env)s' failed:", env=self.envname),
                     "\n", msg)

        if self.ceck_env():
            createenv_error("Environment already created in specified path!")
            return 2

        if os.path.exists(self.envname) and os.listdir(self.envname):
            createenv_error("Target folder not empty!")
            return 2

        project_name = None
        # get arguments
        args = self.unicod_safe_split(line)
        if len(args) == 1 and not args[0]:
            returnvals = self.get_createenv_data()
            path, project_name = returnvals
        elif len(args) != 2:
            createenv_error('Wrong number of arguments: %d' % len(args))
            return 2
        else:
            path, project_name = args[:2]

        try:
            # Uppdate promt and internal stuff
            self.set_env(path)

            # Start env creation
            printout(_("Creating and Initializing Environment"))
            options = [
                ('env', 'path', self.envname),
                ('project', 'name', project_name),
            ]

            # OVER-WRITE THESE OPTIONS from a file

            try:
                self.__env = Environment(self.envname,
                                         create=True,
                                         args=options)
            except Exception as e:
                # Bad thing happened!
                createenv_error(
                    'Failed to create environment. Created files will be deleted'
                )
                printerr(e)
                traceback.print_exc()
                purge_dir(path)
                sys.exit(1)

        except Exception as e:
            createenv_error(to_unicode(e))
            traceback.print_exc()
            return 2

        # Close environment!
        self.__env.shutdown()

        self.print_line()
        printout(
            _("""Project environment for '%(project_name)s' created.

You may now configure the environment by editing the file:

  %(config_path)s

Have a nice day!
""",
              project_name=project_name,
              project_path=self.envname,
              project_dir=os.path.basename(self.envname),
              config_path=os.path.join(self.__env.get_configs_dir(),
                                       _INI_FILENAME)))
Ejemplo n.º 30
0
 def print_version(self):
     """
     Print version of app
     """
     printout(os.path.basename(sys.argv[0]), '0')
Ejemplo n.º 31
0
    def do_createenv(self, line):
        """
        Create environment by passed arguments or interactively
        """
        def createenv_error(msg):
            printerr(_("Createenv for '%(env)s' failed:", env=self.envname),
                     "\n", msg)

        if self.ceck_env():
            createenv_error("Environment already created in specified path!")
            return 2

        if os.path.exists(self.envname) and os.listdir(self.envname):
            createenv_error("Target folder not empty!")
            return 2

        project_name = None
        # get arguments
        args = self.unicod_safe_split(line)
        if len(args) == 1 and not args[0]:
            returnvals = self.get_createenv_data()
            path, project_name = returnvals
        elif len(args) != 2:
            createenv_error('Wrong number of arguments: %d' % len(args))
            return 2
        else:
            path, project_name = args[:2]

        try:
            # Uppdate promt and internal stuff
            self.set_env(path)

            # Start env creation
            printout(_("Creating and Initializing Environment"))
            options = [
                ('env', 'path', self.envname),
                ('project', 'name', project_name),
            ]

            # OVER-WRITE THESE OPTIONS from a file

            try:
                self.__env = Environment(self.envname, create=True, args=options)
            except Exception as e:
                # Bad thing happened!
                createenv_error('Failed to create environment. Created files will be deleted')
                printerr(e)
                traceback.print_exc()
                purge_dir( path )
                sys.exit(1)

        except Exception as e:
            createenv_error(to_unicode(e))
            traceback.print_exc()
            return 2

        # Close environment!
        self.__env.shutdown()

        self.print_line()
        printout(_("""Project environment for '%(project_name)s' created.

You may now configure the environment by editing the file:

  %(config_path)s

Have a nice day!
""", project_name=project_name, project_path=self.envname,
           project_dir=os.path.basename(self.envname),
           config_path=os.path.join(self.__env.get_configs_dir(), _INI_FILENAME)))
Ejemplo n.º 32
0
 def print_version(self):
     """
     Print version of app
     """
     printout(os.path.basename(sys.argv[0]), '0')
Ejemplo n.º 33
0
 def print_help_header(self):
     printout(_("Concurrent - Environment Admin"))
Ejemplo n.º 34
0
    def print_interactive_header(self):
        printout(_("""[Generic CMD App]
Copyright (c) 2014 Moritz Wundke

Type:  '?' or 'help' for help on commands.
        """))
Ejemplo n.º 35
0
 def do_quit(self, line):
     printout(_("\nSee you soon!"))
     sys.exit()
Ejemplo n.º 36
0
 def print_version(self):
     """
     Print version of app
     """
     printout(os.path.basename(sys.argv[0]), CONCURRENT_VERSION)
Ejemplo n.º 37
0
 def print_version(self):
     """
     Print version of app
     """
     printout(os.path.basename(sys.argv[0]), CONCURRENT_VERSION)
Ejemplo n.º 38
0
 def print_usage_help(self):
     printout(_("Usage: con-admin </path/to/project> "
                "[command [subcommand] [option ...]]\n")
         )
     printout(_("Invoking con-admin without command starts "
                "interactive mode."))
Ejemplo n.º 39
0
 def print_usage_help(self):
     printout(_("Usage: <appname> </path/to/projenv> "
                "[command [subcommand] [option ...]]\n")
         )
     printout(_("Invoking <appname> without command starts "
                "interactive mode."))
Ejemplo n.º 40
0
 def print_line(self):
     """
     Print a line :P
     """
     printout(_("""--------------------------------------------------------------------------"""))