Exemple #1
0
def parse_rc(cyg_apt_rc):
    """Parse the user configuration file.

    @param cyg_apt_rc: str The path to the user configuration.

    @return: ConfigStructure The configuration.
    """
    f = open(cyg_apt_rc);
    lines = f.readlines();
    f.close();
    rc_regex = re.compile(r"^\s*(\w+)\s*=\s*(.*)\s*$");
    always_update = False;
    config = ConfigStructure();
    for i in lines:
        result = rc_regex.search(i);
        if result:
            k = result.group(1);
            v = result.group(2);
            if k in config.__dict__ :
                config.__dict__[k] = str(v).rstrip().strip('\'"');
            if 'setup_ini' == k :
                warnings.warn(
                    "The configuration field `setup_ini` is deprecated"
                    " since version 1.1 and will be removed in 2.0.",
                    DeprecationWarning,
                );

    if config.always_update in [True, 'True', 'true', 'Yes', 'yes']:
        always_update = True;
    else:
        always_update = False;

    config.always_update = always_update;

    return config;
Exemple #2
0
def parse_rc(cyg_apt_rc):
    """Parse the user configuration file.

    @param cyg_apt_rc: str The path to the user configuration.

    @return: ConfigStructure The configuration.
    """
    f = open(cyg_apt_rc)
    lines = f.readlines()
    f.close()
    rc_regex = re.compile(r"^\s*(\w+)\s*=\s*(.*)\s*$")
    always_update = False
    config = ConfigStructure()
    for i in lines:
        result = rc_regex.search(i)
        if result:
            k = result.group(1)
            v = result.group(2)
            if k in config.__dict__:
                config.__dict__[k] = str(v).rstrip().strip('\'"')
            if 'setup_ini' == k:
                warnings.warn(
                    "The configuration field `setup_ini` is deprecated"
                    " since version 1.1 and will be removed in 2.0.",
                    DeprecationWarning,
                )

    if config.always_update in [True, 'True', 'true', 'Yes', 'yes']:
        always_update = True
    else:
        always_update = False

    config.always_update = always_update

    return config
Exemple #3
0
    def __init__(self, cygwin_p, verbose, arch="x86"):
        self.__cygwinPlatform = cygwin_p
        self.__verbose = verbose
        self.__appName = os.path.basename(sys.argv[0])
        self.setTmpDir()
        self.setPathMapper()
        self.__setupDir = "/etc/setup"
        self.__rc = ConfigStructure()
        self.__arch = arch

        self.__rc.ROOT = self.__pm.getMountRoot()
Exemple #4
0
    def setUp(self):
        TestCase.setUp(self);

        self._var_verbose = False;
        self._var_cygwin_p = sys.platform.startswith("cygwin");

        if not self._var_cygwin_p:
            self.skipTest("requires cygwin");

        setup = CygAptSetup(self._var_cygwin_p, self._var_verbose);
        setup.setTmpDir(self._dir_tmp);
        setup.setAppName(self._var_exename);
        setup.setSetupDir(self._dir_confsetup);
        setup.getRC().ROOT = self._dir_mtroot;

        setup._gpgImport(setup.GPG_CYG_PUBLIC_RING_URI);
        setup.setup();

        f = open(self._file_setup_ini, 'w');
        f.write(self._var_setupIni.contents);
        f.close();

        f = open(self._file_installed_db, 'w');
        f.write(CygApt.INSTALLED_DB_MAGIC);
        f.close();

        self._var_packagename = self._var_setupIni.pkg.name;
        self._var_files = ["", self._var_packagename];
        self._var_download_p = False;
        self._var_downloads = None;
        self._var_distname = None;
        self._var_nodeps_p = False;
        self._var_regex_search = False;
        self._var_nobarred = False;
        self._var_nopostinstall = False;
        self._var_nopostremove = False;
        self._var_dists = 0;
        self._var_installed = 0;

        self.obj = CygApt(
            self._var_packagename,
            self._var_files,
            self._file_user_config,
            self._var_cygwin_p,
            self._var_download_p,
            self._var_mirror,
            self._var_downloads,
            self._var_distname,
            self._var_nodeps_p,
            self._var_regex_search,
            self._var_nobarred,
            self._var_nopostinstall,
            self._var_nopostremove,
            self._var_dists,
            self._var_installed,
            self._var_exename,
            self._var_verbose
        );

        # set attributes
        rc = ConfigStructure();
        rc.cache = self._dir_execache;
        rc.distname = 'curr';
        rc.setup_ini = self._file_setup_ini;
        rc.ROOT = self._dir_mtroot;
        rc.always_update = False;
        rc.mirror = self._var_mirror;
        self.obj.setRC(rc);

        self.obj.setDownlaodDir(self._dir_downloads);
        self.obj.setInstalledDbFile(self._file_installed_db);
        self.obj.setSetupDir(self._dir_confsetup);

        pm = PathMapper("", False);
        pm.setRoot(self._dir_mtroot[:-1]);
        pm.setMountRoot(self._dir_mtroot);
        pm.setMap({self._dir_mtroot:self._dir_mtroot});

        expected = self._dir_mtroot;
        ret = pm.mapPath(self._dir_mtroot);
        self.assertEqual(ret, expected);
        expected = os.path.join(self._dir_mtroot, "diranme");
        ret = pm.mapPath(expected);
        self.assertEqual(ret, expected);

        self.obj.setPathMapper(pm);

        self.obj.setDists(self._var_setupIni.dists.__dict__);

        self.obj.CYG_POSTINSTALL_DIR = self._dir_postinstall;
        self.obj.CYG_PREREMOVE_DIR = self._dir_preremove;
        self.obj.CYG_POSTREMOVE_DIR = self._dir_postremove;

        self.obj.setDosBash("/usr/bin/bash");
        self.obj.setDosLn("/usr/bin/ln");

        self.obj.setPrefixRoot(self._dir_mtroot[:-1]);
        self.obj.setAbsRoot(self._dir_mtroot);
        self.obj.setInstalled({0:{}});

        self.obj.FORCE_BARRED = [self._var_setupIni.barredpkg.name];
Exemple #5
0
    def _createCygApt(self):
        """Creates a CygApt instance.

        @return: CygApt
        """
        cygapt = CygApt(
            self._var_packagename,
            self._var_files,
            self._file_user_config,
            self._var_cygwin_p,
            self._var_download_p,
            self._var_mirror,
            self._var_downloads,
            self._var_distname,
            self._var_nodeps_p,
            self._var_regex_search,
            self._var_nobarred,
            self._var_nopostinstall,
            self._var_nopostremove,
            self._var_dists,
            self._var_installed,
            self._var_exename,
            self._var_verbose,
            self._var_arch,
            self._dir_confsetup,
        );

        # set attributes
        rc = ConfigStructure();
        rc.cache = self._dir_execache;
        rc.distname = 'curr';

        # BC layer for `setup_ini` configuration field
        del rc.__dict__['setup_ini'];

        rc.ROOT = self._dir_mtroot;
        rc.always_update = False;
        rc.mirror = self._var_mirror;
        cygapt.setRC(rc);

        cygapt.setInstalledDbFile(self._file_installed_db);
        self.assertEqual(self._dir_confsetup, cygapt.getSetupDir());

        pm = PathMapper("", False);
        pm.setRoot(self._dir_mtroot[:-1]);
        pm.setMountRoot(self._dir_mtroot);
        pm.setMap({self._dir_mtroot:self._dir_mtroot});

        expected = self._dir_mtroot;
        ret = pm.mapPath(self._dir_mtroot);
        self.assertEqual(ret, expected);
        expected = os.path.join(self._dir_mtroot, "diranme");
        ret = pm.mapPath(expected);
        self.assertEqual(ret, expected);

        cygapt.setPathMapper(pm);

        cygapt.setDists(self._var_setupIni.dists.__dict__);

        if self._var_cygwin_p :
            cygapt.CYG_POSTINSTALL_DIR = self._dir_postinstall;
            cygapt.CYG_PREREMOVE_DIR = self._dir_preremove;
            cygapt.CYG_POSTREMOVE_DIR = self._dir_postremove;

        # requires bash, ln and xz on PATH
        cygapt.setDosBash("bash");
        cygapt.setDosLn("ln");
        cygapt.setDosXz('xz');
        cygapt.setDosDash('dash');

        cygapt.setPrefixRoot(self._dir_mtroot[:-1]);
        cygapt.setAbsRoot(self._dir_mtroot);
        cygapt.setInstalled({0:{}});

        cygapt.FORCE_BARRED.extend([
            self._var_setupIni.barredpkg.name,
        ]);

        return cygapt;
Exemple #6
0
    def __init__(
        self,
        main_packagename,
        main_files,
        main_cyg_apt_rc,
        main_cygwin_p,
        main_download_p,
        main_mirror,
        main_downloads,
        main_distname,
        main_nodeps_p,
        main_regex_search,
        main_nobarred,
        main_nopostinstall,
        main_nopostremove,
        main_dists,
        main_installed,
        main_scriptname,
        main_verbose,
        arch,
        setupDir="/etc/setup",
    ):

        # Define private properties
        self.__ballTarget = 'install'
        self.__regexSearch = main_regex_search
        self.__noBarred = main_nobarred
        self.__noPostInstall = main_nopostinstall
        self.__noPostRemove = main_nopostremove
        self.__appName = main_scriptname
        self.__files = main_files
        self.__downloadOnly = main_download_p
        self.__downloadDir = main_downloads
        self.__noDeps = main_nodeps_p
        self.__rcFile = main_cyg_apt_rc
        self.__verbose = main_verbose
        self.__setupDir = setupDir
        self.__rc = ConfigStructure()
        self.__setupIniPath = None
        self.__arch = arch

        # Init
        self.setPkgName(main_packagename)
        self.setCygwinPlatform(main_cygwin_p)
        self.setDists(main_dists)
        self.setInstalled(main_installed)

        # Read in our configuration
        self.getRessource(self.__rcFile)

        # Now we have a path mapper, check setup.exe is not running
        self._checkForSetupExe()

        # DOS specific
        if not self.__cygwinPlatform:
            self.__lnExists = os.path.exists("{0}/bin/ln.exe".format(
                self.__prefixRoot))
        else:
            self.__lnExists = True

        # Overrides to the .rc
        if (main_mirror):
            self.__rc.mirror = main_mirror
            self.__downloadDir = os.path.join(
                self.__rc.cache,
                urllib.quote(
                    self.__rc.mirror +
                    ('' if self.__rc.mirror.endswith('/') else '/'),
                    '').lower())

        if (main_distname):
            self.__rc.distname = main_distname

        if not (os.path.isfile(self.__installedDbFile) \
                or os.path.isfile(self.__setupIniPath)):
            msg = "{0} no such file, run {1} setup?".format(
                self.__installedDbFile, self.__appName)
            raise PackageCacheException(msg)
        else:
            self._getSetupIni()
            self.getInstalled()
Exemple #7
0
    def _createCygApt(self):
        """Creates a CygApt instance.

        @return: CygApt
        """
        cygapt = CygApt(
            self._var_packagename,
            self._var_files,
            self._file_user_config,
            self._var_cygwin_p,
            self._var_download_p,
            self._var_mirror,
            self._var_downloads,
            self._var_distname,
            self._var_nodeps_p,
            self._var_regex_search,
            self._var_nobarred,
            self._var_nopostinstall,
            self._var_nopostremove,
            self._var_dists,
            self._var_installed,
            self._var_exename,
            self._var_verbose,
            self._var_arch,
            self._dir_confsetup,
        )

        # set attributes
        rc = ConfigStructure()
        rc.cache = self._dir_execache
        rc.distname = 'curr'

        # BC layer for `setup_ini` configuration field
        del rc.__dict__['setup_ini']

        rc.ROOT = self._dir_mtroot
        rc.always_update = False
        rc.mirror = self._var_mirror
        cygapt.setRC(rc)

        cygapt.setInstalledDbFile(self._file_installed_db)
        self.assertEqual(self._dir_confsetup, cygapt.getSetupDir())

        pm = PathMapper("", False)
        pm.setRoot(self._dir_mtroot[:-1])
        pm.setMountRoot(self._dir_mtroot)
        pm.setMap({self._dir_mtroot: self._dir_mtroot})

        expected = self._dir_mtroot
        ret = pm.mapPath(self._dir_mtroot)
        self.assertEqual(ret, expected)
        expected = os.path.join(self._dir_mtroot, "diranme")
        ret = pm.mapPath(expected)
        self.assertEqual(ret, expected)

        cygapt.setPathMapper(pm)

        cygapt.setDists(self._var_setupIni.dists.__dict__)

        if self._var_cygwin_p:
            cygapt.CYG_POSTINSTALL_DIR = self._dir_postinstall
            cygapt.CYG_PREREMOVE_DIR = self._dir_preremove
            cygapt.CYG_POSTREMOVE_DIR = self._dir_postremove

        # requires bash, ln and xz on PATH
        cygapt.setDosBash("bash")
        cygapt.setDosLn("ln")
        cygapt.setDosXz('xz')
        cygapt.setDosDash('dash')

        cygapt.setPrefixRoot(self._dir_mtroot[:-1])
        cygapt.setAbsRoot(self._dir_mtroot)
        cygapt.setInstalled({0: {}})

        cygapt.FORCE_BARRED.extend([
            self._var_setupIni.barredpkg.name,
        ])

        return cygapt