Example #1
0
    def testUriGet(self):
        directory = self._getTmpDir();
        uri = "http://cygwin.uib.no/setup.bz2.sig";
        verbose = False;
        utils.uri_get(directory, uri, verbose);
        self.assertTrue(
            os.path.exists(os.path.join(directory, "setup.bz2.sig")),
            "http request"
        );

        self.assertRaises(
            ApplicationException,
            utils.uri_get,
            "",
            "",
            verbose
        );

        uri = "ftp://cygwin.uib.no/pub/cygwin/setup.ini.sig";
        utils.uri_get(directory, uri, verbose);
        self.assertTrue(
            os.path.exists(os.path.join(directory, "setup.ini.sig")),
            "ftp request"
        );

        uri = "rsync://cygwin.uib.no/cygwin/setup-legacy.bz2.sig";
        self.assertRaises(
            ApplicationException,
            utils.uri_get,
            directory,
            uri,
            verbose
        );
Example #2
0
    def testUriGet(self, uri, protocol):
        directory = self._getTmpDir();
        targetPath = os.path.join(directory, os.path.basename(uri));

        try:
            utils.uri_get(directory, uri, False);
        except utils.RequestException:
            self.skipTest("Your network doesn't allow {0} requests.".format(protocol));

        self.assertTrue(os.path.exists(targetPath));
Example #3
0
    def _gpgImport(self, uri):
        if not self.__cygwinPlatform:
            return

        cautils.uri_get(self.__tmpDir, uri, verbose=self.__verbose)
        tmpfile = os.path.join(self.__tmpDir, os.path.basename(uri))
        cmd = ["gpg"]
        cmd.append("--no-secmem-warning")
        cmd += ["--import", tmpfile]
        Process(cmd).mustRun()
Example #4
0
    def _gpgImport(self, uri):
        if not self.__cygwinPlatform:
            return;

        cautils.uri_get(self.__tmpDir, uri, verbose=self.__verbose);
        tmpfile = os.path.join(self.__tmpDir, os.path.basename(uri));
        cmd = ["gpg"];
        cmd.append("--no-secmem-warning");
        cmd += ["--import", tmpfile];
        Process(cmd).mustRun();
Example #5
0
    def _gpgImport(self, uri):
        if not self.__cygwinPlatform:
            return;

        cautils.uri_get(self.__tmpDir, uri, verbose=self.__verbose);
        tmpfile = os.path.join(self.__tmpDir, os.path.basename(uri));
        cmd = "gpg ";
        cmd += "--no-secmem-warning ";
        cmd += "--import {0}".format(tmpfile);
        p = subprocess.Popen(
            cmd,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE
        );
        if p.wait():
            raise ProcessException(p.stderr.readlines());
Example #6
0
 def _doDownload(self):
     url, md5 = self._getUrl()
     directory = os.path.join(self.__downloadDir,
                              os.path.split(url)[0])
     if not os.path.exists(self.getBall()) or not self._checkMd5():
         if not os.path.exists(directory):
             os.makedirs(directory)
         status = cautils.uri_get(directory,
                                  "{0}/{1}".format(self.__rc.mirror, url))
         if status:
             raise PackageCacheException(
                 "didn't find {0} "
                 "on mirror {1}: possible mismatch between setup.ini and "
                 "mirror requiring {2} update?".format(
                     self.__pkgName, self.__rc.mirror, self.__appName))
Example #7
0
 def _doDownload(self):
     url, md5 = self._getUrl();
     directory = os.path.join(self.__downloadDir, os.path.split(url)[0]);
     if not os.path.exists(self.getBall()) or not self._checkMd5():
         if not os.path.exists(directory):
             os.makedirs(directory);
         status = cautils.uri_get(
             directory,
             "{0}/{1}".format(self.__rc.mirror, url)
         );
         if status:
             raise PackageCacheException(
                 "didn't find {0} "
                 "on mirror {1}: possible mismatch between setup.ini and "
                 "mirror requiring {2} update?".format(
                 self.__pkgName,
                 self.__rc.mirror,
                 self.__appName
             ));
Example #8
0
 def testUriGetWithInvalidScheme(self, uri):
     utils.uri_get(self._getTmpDir(), uri, False);
Example #9
0
    def update(self, cyg_apt_rc, verify, main_mirror=None):
        """fetch current package database from mirror"""
        sig_name = None
        self.__rc = cautils.parse_rc(cyg_apt_rc)

        if (not self.__cygwinPlatform):
            self.__pm = PathMapper(self.__rc.ROOT[:-1], False)

        if (main_mirror):
            mirror = main_mirror
        else:
            mirror = self.__rc.mirror

        if not mirror:
            raise UnexpectedValueException(
                "A mirror must be specified on the configuration file \"{0}\" "
                "or with the command line option \"--mirror\". "
                "See cygwin.com/mirrors.html for the list of mirrors."
                "".format(cyg_apt_rc))

        if not mirror[-1] == "/":
            sep = "/"
        else:
            sep = ""

        setup_ini_names = [
            "setup.bz2",
            "setup.ini",
        ]

        bag = zip(setup_ini_names, list(range(len(setup_ini_names))))
        platform_dir = self.__arch + "/"

        for (setup_ini_name, index) in bag:
            setup_ini_url = '{0}{1}{2}{3}'.format(mirror, sep, platform_dir,
                                                  setup_ini_name)
            try:
                cautils.uri_get(self.__tmpDir,
                                setup_ini_url,
                                verbose=self.__verbose)
            except ApplicationException as e:
                # Failed to find a possible .ini
                if index == len(setup_ini_names) - 1:
                    raise e
                else:
                    continue
                    # Not an error to fail to find the first one
            # Take the first one we find
            break

        if setup_ini_name[-4:] == ".bz2":
            bz_file = os.path.join(self.__tmpDir, setup_ini_name)
            f = open(bz_file, "rb")
            compressed = f.read()
            f.close()

            decomp = bz2.decompress(compressed)
            os.remove(bz_file)
            setup_ini_name = "setup.ini"

            f = open(os.path.join(self.__tmpDir, setup_ini_name), "wb")
            f.write(decomp)
            f.close()

        if not self.__cygwinPlatform:
            sys.stderr.write(
                "WARNING can't verify setup.ini outside Cygwin.\n")
            verify = False

        if verify:
            sig_name = "{0}.sig".format(setup_ini_name)
            sig_url = "{0}{1}{2}{3}".format(mirror, sep, platform_dir,
                                            sig_name)
            try:
                cautils.uri_get(self.__tmpDir, sig_url, verbose=self.__verbose)
            except RequestException as e:
                msg = ("Failed to download signature {0} Use -X to ignore "
                       "signatures.".format(sig_url))
                raise RequestException(msg, previous=e)

            if self.__cygwinPlatform:
                gpg_path = "gpg"
            else:
                if self._cygwinVersion() < 1.7:
                    gpg_path = "/usr/bin/gpg"
                else:
                    gpg_path = "/usr/local/bin/gpg"
            cmd = [gpg_path, "--verify", "--no-secmem-warning"]
            cmd.append("{0}/{1}".format(self.__tmpDir, sig_name))
            cmd.append("{0}/{1}".format(self.__tmpDir, setup_ini_name))
            p = Process(cmd)
            p.run()
            verify = p.getErrorOutput()
            if isinstance(verify, bytes):
                marker = self.GPG_GOOD_FINGER.encode()
            else:
                marker = self.GPG_GOOD_FINGER
            if not marker in verify:
                msg = ("{0} not signed by Cygwin's public key. "
                       "Use -X to ignore signatures.".format(setup_ini_url))
                raise SignatureException(msg)

        downloads = os.path.join(
            self.__pm.mapPath(self.__rc.cache),
            urllib.quote(mirror + ('' if mirror.endswith('/') else '/'),
                         '').lower(),
            platform_dir,
        )

        if not os.path.exists(downloads):
            os.makedirs(downloads)

        shutil.copy(os.path.join(self.__tmpDir, setup_ini_name),
                    os.path.join(downloads, setup_ini_name))

        # BC layer for `setup_ini` configuration field
        if self.__rc.setup_ini:
            setup_ini = self.__pm.mapPath(self.__rc.setup_ini)
            if os.path.exists(setup_ini):
                shutil.copy(setup_ini, "{0}.bak".format(setup_ini))
            shutil.copy(os.path.join(downloads, setup_ini_name), setup_ini)

        if os.path.exists(os.path.join(self.__tmpDir, setup_ini_name)):
            os.remove(os.path.join(self.__tmpDir, setup_ini_name))
        if sig_name:
            if os.path.exists(os.path.join(self.__tmpDir, sig_name)):
                os.remove(os.path.join(self.__tmpDir, sig_name))
Example #10
0
    def update(self, cyg_apt_rc, verify, main_mirror=None):
        """fetch current package database from mirror"""
        sig_name = None;
        f = open(cyg_apt_rc);
        lines = f.readlines();
        f.close();
        for i in lines:
            result = self.RC_REGEX.search(i);
            if result:
                k = result.group(1);
                v = result.group(2);
                if k in self.__rc.__dict__:
                    self.__rc.__dict__[k] = eval(v);

        if(not self.__cygwinPlatform):
            self.__pm = PathMapper(self.__rc.ROOT[:-1], False);

        setup_ini = self.__pm.mapPath(self.__rc.setup_ini);
        if (main_mirror):
            mirror = main_mirror;
        else:
            mirror = self.__rc.mirror;
        downloads = os.path.join(
            self.__pm.mapPath(self.__rc.cache),
            urllib.quote(mirror, '').lower()
        );
        if not mirror[-1] == "/":
            sep = "/";
        else:
            sep = "";

        setup_ini_names = [
            os.path.basename(setup_ini).replace(".ini", ".bz2"),
            os.path.basename(setup_ini)
        ];

        bag = zip(setup_ini_names, list(range(len(setup_ini_names))));

        for (setup_ini_name, index) in bag:
            setup_ini_url = '{0}{1}{2}'.format(mirror, sep, setup_ini_name);
            try:
                cautils.uri_get(
                    self.__tmpDir,
                    setup_ini_url,
                    verbose=self.__verbose
                );
            except ApplicationException as e:
                # Failed to find a possible .ini
                if index == len(setup_ini_names) - 1:
                    raise e;
                else:
                    continue;
                    # Not an error to fail to find the first one
            # Take the first one we find
            break;

        if setup_ini_name[-4:] == ".bz2":
            bz_file = os.path.join(self.__tmpDir, setup_ini_name);
            f = open(bz_file, "rb");
            compressed = f.read();
            f.close();

            decomp = bz2.decompress(compressed);
            os.remove(bz_file);
            setup_ini_name =  os.path.basename(setup_ini);

            f = open(os.path.join(self.__tmpDir, setup_ini_name), "wb");
            f.write(decomp);
            f.close();

        if not self.__cygwinPlatform:
            sys.stderr.write("WARNING can't verify setup.ini outside Cygwin.\n");
            verify = False;

        if verify:
            sig_name = "{0}.sig".format(setup_ini_name);
            sig_url = "{0}{1}{2}".format(mirror, sep, sig_name);
            try:
                cautils.uri_get(self.__tmpDir, sig_url, verbose=self.__verbose);
            except RequestException as e:
                msg = (
                    "Failed to download signature {0} Use -X to ignore "
                    "signatures.".format(sig_url)
                );
                raise RequestException(msg, previous=e);

            if self.__cygwinPlatform:
                gpg_path = "gpg ";
            else:
                if self._cygwinVersion() < 1.7:
                    gpg_path = "/usr/bin/gpg ";
                else:
                    gpg_path = "/usr/local/bin/gpg ";
            cmd = gpg_path + "--verify --no-secmem-warning ";
            cmd += "{0}/{1} ".format(self.__tmpDir, sig_name);
            cmd += "{0}/{1} ".format(self.__tmpDir, setup_ini_name);
            p = subprocess.Popen(
                cmd,
                shell=True,
                stderr=subprocess.PIPE
            );
            p.wait();
            verify = p.stderr.read();
            if isinstance(verify, bytes):
                marker = self.GPG_GOOD_FINGER.encode();
            else:
                marker = self.GPG_GOOD_FINGER;
            if not marker in verify:
                msg = (
                    "{0} not signed by Cygwin's public key. "
                    "Use -X to ignore signatures.".format(setup_ini_url)
                );
                raise SignatureException(msg);

        if not os.path.exists(downloads):
            os.makedirs(downloads);

        shutil.copy(
            os.path.join(self.__tmpDir, setup_ini_name),
            os.path.join(downloads, setup_ini_name)
        );
        if os.path.exists(setup_ini):
            shutil.copy(setup_ini, "{0}.bak".format(setup_ini));
        shutil.copy(
            os.path.join(downloads, setup_ini_name),
            setup_ini
        );
        if os.path.exists(os.path.join(self.__tmpDir, setup_ini_name)):
            os.remove(os.path.join(self.__tmpDir, setup_ini_name));
        if sig_name:
            if os.path.exists(os.path.join(self.__tmpDir, sig_name)):
                os.remove(os.path.join(self.__tmpDir, sig_name));
Example #11
0
    def update(self, cyg_apt_rc, verify, main_mirror=None):
        """fetch current package database from mirror"""
        sig_name = None;
        self.__rc = cautils.parse_rc(cyg_apt_rc);

        if(not self.__cygwinPlatform):
            self.__pm = PathMapper(self.__rc.ROOT[:-1], False);

        if (main_mirror):
            mirror = main_mirror;
        else:
            mirror = self.__rc.mirror;

        if not mirror :
            raise UnexpectedValueException(
                "A mirror must be specified on the configuration file \"{0}\" "
                "or with the command line option \"--mirror\". "
                "See cygwin.com/mirrors.html for the list of mirrors."
                "".format(cyg_apt_rc)
            );

        if not mirror[-1] == "/":
            sep = "/";
        else:
            sep = "";

        setup_ini_names = [
            "setup.bz2",
            "setup.ini",
        ];

        bag = zip(setup_ini_names, list(range(len(setup_ini_names))));
        platform_dir = self.__arch+"/";

        for (setup_ini_name, index) in bag:
            setup_ini_url = '{0}{1}{2}{3}'.format(mirror, sep, platform_dir, setup_ini_name);
            try:
                cautils.uri_get(
                    self.__tmpDir,
                    setup_ini_url,
                    verbose=self.__verbose
                );
            except ApplicationException as e:
                # Failed to find a possible .ini
                if index == len(setup_ini_names) - 1:
                    raise e;
                else:
                    continue;
                    # Not an error to fail to find the first one
            # Take the first one we find
            break;

        if setup_ini_name[-4:] == ".bz2":
            bz_file = os.path.join(self.__tmpDir, setup_ini_name);
            f = open(bz_file, "rb");
            compressed = f.read();
            f.close();

            decomp = bz2.decompress(compressed);
            os.remove(bz_file);
            setup_ini_name = "setup.ini";

            f = open(os.path.join(self.__tmpDir, setup_ini_name), "wb");
            f.write(decomp);
            f.close();

        if not self.__cygwinPlatform:
            sys.stderr.write("WARNING can't verify setup.ini outside Cygwin.\n");
            verify = False;

        if verify:
            sig_name = "{0}.sig".format(setup_ini_name);
            sig_url = "{0}{1}{2}{3}".format(mirror, sep, platform_dir, sig_name);
            try:
                cautils.uri_get(self.__tmpDir, sig_url, verbose=self.__verbose);
            except RequestException as e:
                msg = (
                    "Failed to download signature {0} Use -X to ignore "
                    "signatures.".format(sig_url)
                );
                raise RequestException(msg, previous=e);

            if self.__cygwinPlatform:
                gpg_path = "gpg";
            else:
                if self._cygwinVersion() < 1.7:
                    gpg_path = "/usr/bin/gpg";
                else:
                    gpg_path = "/usr/local/bin/gpg";
            cmd = [gpg_path, "--verify", "--no-secmem-warning"];
            cmd.append("{0}/{1}".format(self.__tmpDir, sig_name));
            cmd.append("{0}/{1}".format(self.__tmpDir, setup_ini_name));
            p = Process(cmd);
            p.run();
            verify = p.getErrorOutput();
            if isinstance(verify, bytes):
                marker = self.GPG_GOOD_FINGER.encode();
            else:
                marker = self.GPG_GOOD_FINGER;
            if not marker in verify:
                msg = (
                    "{0} not signed by Cygwin's public key. "
                    "Use -X to ignore signatures.".format(setup_ini_url)
                );
                raise SignatureException(msg);

        downloads = os.path.join(
            self.__pm.mapPath(self.__rc.cache),
            urllib.quote(mirror+('' if mirror.endswith('/') else '/'), '').lower(),
            platform_dir,
        );

        if not os.path.exists(downloads):
            os.makedirs(downloads);

        shutil.copy(
            os.path.join(self.__tmpDir, setup_ini_name),
            os.path.join(downloads, setup_ini_name)
        );

        # BC layer for `setup_ini` configuration field
        if self.__rc.setup_ini :
            setup_ini = self.__pm.mapPath(self.__rc.setup_ini);
            if os.path.exists(setup_ini):
                shutil.copy(setup_ini, "{0}.bak".format(setup_ini));
            shutil.copy(
                os.path.join(downloads, setup_ini_name),
                setup_ini
            );

        if os.path.exists(os.path.join(self.__tmpDir, setup_ini_name)):
            os.remove(os.path.join(self.__tmpDir, setup_ini_name));
        if sig_name:
            if os.path.exists(os.path.join(self.__tmpDir, sig_name)):
                os.remove(os.path.join(self.__tmpDir, sig_name));