Exemple #1
0
def check_upgrade():
        server_file = curl(PIFM_HOST + '/client_agent/pifm_agent.py')
        server_sum = awk(
                        md5sum(
                            grep(server_file, '-v', '^PIFM_HOST')
                        ), '{print $1}'
        )

        local_sum = awk(
                        md5sum(
                            grep('-v', '^PIFM_HOST', OUR_SCRIPT)
                        ), '{print $1}'
        )

        if str(server_sum) != str(local_sum):
            logging.info(
                "server: {server}, local: {local}, should update.".format(
                    server=server_sum,
                    local=local_sum
                )
            )
            with open(TMP_SCRIPT, 'w') as f:
                f.write(str(server_file))
            sed('-i',
                "0,/def/ s#http://pi_director#{myhost}#".format(myhost=PIFM_HOST),
                OUR_SCRIPT
                )
            status = python('-m', 'py_compile', TMP_SCRIPT)
            if (status.exit_code == 0):
                shutil.copy(TMP_SCRIPT, OUR_SCRIPT)
                os.chmod(OUR_SCRIPT, 0755)
                sys.exit(0)
Exemple #2
0
    def send(self, releaseArchive, serverReleaseArchive):
        md5 = str(md5sum(releaseArchive)).split(" ")[0]
        with open(releaseArchive + ".md5", "w") as md5file:
            md5file.write(md5)

        if sendFile(releaseArchive + ".md5", serverReleaseArchive +
                    ".md5") and sendFile(releaseArchive, serverReleaseArchive):
            return True
        return False
Exemple #3
0
	def compress(self, buildDir, archive):
		msgcmd("Compress archive", archive)
		try:
			tar("-Jvcf", archive, "-C", buildDir + "/bin", ".", _env={"XZ_OPT" : "-9e"}, _out=debugSh)
			md5 = str(md5sum(archive)).split(" ")[0]
			msgstat("Archive md5 ", md5)
			with open(archive + ".md5", "w") as md5file:
				md5file.write(md5)
		except:
			msgerr("Failed compress archive", archive)
			return False

		msgstat("Finished compress archive", archive)
		return True
def compile_worker_func(cmd):
    '''Worker function for child processed in multiprocess run'''
    full_path, options = cmd
    fname = os.path.basename(full_path)
    _, ext = os.path.splitext(fname)
    if ext not in LANG_BY_PREPROC:
        return False
    lang = LANG_BY_PREPROC[ext]
    compiler = compilers[lang]
    options.append(full_path)
    try:
        res = md5sum(compiler(*options))
        sys.stdout.write('.')
        sys.stdout.flush()
        return res.split()[0].strip()
    except:
        return False
Exemple #5
0
def compile_worker_func(cmd):
    '''Worker function for child processed in multiprocess run'''
    full_path, options = cmd
    fname = os.path.basename(full_path)
    _, ext = os.path.splitext(fname)
    if ext not in LANG_BY_PREPROC:
        return False
    lang = LANG_BY_PREPROC[ext]
    compiler = compilers[lang]
    options.append(full_path)
    try:
        res = md5sum(compiler(*options))
        sys.stdout.write('.')
        sys.stdout.flush()
        return res.split()[0].strip()
    except:
        return False
Exemple #6
0
    def _set_image_ready(self, image_name):
        """Update the image named 'image_name' with a ready status. This SHOULD only
		be called once the image has been imported, initially configured, and then
		successfully shutdown.

		:image_name: The name of the image to update to ready status
		"""
        self._log.info(
            "operation for image {!r} completed successfully!".format(
                image_name))

        images = master.models.Image.objects(id=image_name)
        if len(images) == 0:
            self._log.warn(
                "Could not set image named {!r} as ready, not found in database!"
                .format(image_name))
            return

        self._log.debug("images: {} ({!r})".format(images, image_name))
        image = images[0]
        self._log.debug("image: {}".format(image))
        image.status = {"name": "ready"}

        path = "/var/lib/libvirt/images/{}_vagrant_box_image_0.img".format(
            str(image.id))
        if not os.path.exists(path):
            path = os.path.join(os.path.expanduser("~"), ".vagrant.d", "boxes",
                                str(image.id), "0", "libvirt", "box.img")

        self._log.info("recalculating md5 of image found at {}".format(path))

        if not os.path.exists(path):
            self._log.warn(
                "Could not find valid path for image {} to update md5".format(
                    str(image.id)))
            return

        md5, _ = md5sum(path).split()

        self._log.info("new md5: {}".format(md5))
        image.md5 = md5
        image.timestamps["modified"] = time.time()
        image.save()

        self._log.info("updated md5 for image {!r}".format(image_name))
Exemple #7
0
    def get_md5(self, path):
        """Get the md5 of the file at ``path``. A cache will be used
		based on last modified time of the file. If the file does not
		exist, None will be returned.
		"""
        path = os.path.realpath(os.path.abspath(path))
        if not os.path.exists(path):
            self._log.debug(
                "could not get md5, path does not exist: {}".format(path))
            return None

        if path in self._cache and os.path.getmtime(
                path) == self._cache[path]["modtime"]:
            self._log.debug("path was in cache ({}), md5: {}".format(
                path, self._cache[path]["md5"]))
            return self._cache[path]["md5"]

        md5ing_already = False
        with self._calc_md5_images_lock:
            md5ing_already = (path in self._calc_md5_images)
            if not md5ing_already:
                e = self._calc_md5_images[path] = threading.Event()
                e.clear()

        if md5ing_already:
            self._log.debug(
                "already calculating md5, waiting for it to finish")
            self._calc_md5_images[path].wait()
            self._log.debug("image md5 done")
            return self._cache[path]["md5"]

        self._log.info("path not in cache ({}), calculating".format(path))
        output = md5sum(path).split()[0]
        self._log.info("calculated md5: " + output)
        self._cache[path] = {
            "md5": output,
            "modtime": os.path.getmtime(path),
        }

        self._calc_md5_images[path].set()
        del self._calc_md5_images[path]

        return output
Exemple #8
0
    def get_md5(self, path):
        """Get the md5 of the file at ``path``. A cache will be used
        based on last modified time of the file. If the file does not
        exist, None will be returned.
        """
        path = os.path.realpath(os.path.abspath(path))
        if not os.path.exists(path):
            self._log.debug("could not get md5, path does not exist: {}".format(path))
            return None

        if path in self._cache and os.path.getmtime(path) == self._cache[path]["modtime"]:
            self._log.debug("path was in cache ({}), md5: {}".format(path, self._cache[path]["md5"]))
            return self._cache[path]["md5"]

        md5ing_already = False
        with self._calc_md5_images_lock:
            md5ing_already = (path in self._calc_md5_images)
            if not md5ing_already:
                e = self._calc_md5_images[path] = threading.Event()
                e.clear()

        if md5ing_already:
            self._log.debug("already calculating md5, waiting for it to finish")
            self._calc_md5_images[path].wait()
            self._log.debug("image md5 done")
            return self._cache[path]["md5"]

        self._log.info("path not in cache ({}), calculating".format(path))
        output = md5sum(path).split()[0]
        self._log.info("calculated md5: " + output)
        self._cache[path] = {
            "md5": output,
            "modtime": os.path.getmtime(path),
        }

        self._calc_md5_images[path].set()
        del self._calc_md5_images[path]

        return output
Exemple #9
0
    def _set_image_ready(self, image_name):
        """Update the image named 'image_name' with a ready status. This SHOULD only
        be called once the image has been imported, initially configured, and then
        successfully shutdown.

        :image_name: The name of the image to update to ready status
        """
        self._log.info("operation for image {!r} completed successfully!".format(image_name))

        images = master.models.Image.objects(id=image_name)
        if len(images) == 0:
            self._log.warn("Could not set image named {!r} as ready, not found in database!".format(image_name))
            return

        self._log.debug("images: {} ({!r})".format(images, image_name))
        image = images[0]
        self._log.debug("image: {}".format(image))
        image.status = {"name": "ready"}

        path = "/var/lib/libvirt/images/{}_vagrant_box_image_0.img".format(str(image.id))
        if not os.path.exists(path):
            path = os.path.join(os.path.expanduser("~"), ".vagrant.d", "boxes", str(image.id), "0", "libvirt", "box.img")

        self._log.info("recalculating md5 of image found at {}".format(path))

        if not os.path.exists(path):
            self._log.warn("Could not find valid path for image {} to update md5".format(str(image.id)))
            return

        md5,_ = md5sum(path).split()

        self._log.info("new md5: {}".format(md5))
        image.md5 = md5
        image.timestamps["modified"] = time.time()
        image.save()

        self._log.info("updated md5 for image {!r}".format(image_name))
Exemple #10
0
import tempfile
import getopt
import sh

from ricecooker.chefs import SushiChef
from ricecooker.classes import licenses

from imscp.core import extract_from_zip
from imscp.ricecooker_utils import make_topic_tree_with_entrypoints

script_dir = os.path.dirname(os.path.abspath(__file__))
TITLE = input("\nIngrese el título: ")
DESCRIPTION = input("\nIngrese la descripción: ")
FILE = input("\nRuta del archivo SCORM: ")
if os.path.isfile(FILE):
    MD5SUM = str(sh.md5sum(FILE))[:32]
    sh.ln("-s", FILE, MD5SUM + ".zip")
    TMPFILE = MD5SUM + ".zip"
else:
    sys.exit(0)

print("Procesando: " + TITLE)
print("            " + "=" * len(TITLE))
print("            " + DESCRIPTION + "\n")


class GeogebraChef(SushiChef):
    """
    The chef class that takes care of uploading channel to the content curation server.

    We'll call its `main()` method from the command line script.