Ejemplo n.º 1
0
    def _setupTheme(self):
        """
        Download and setup the theme.
        """
        logging.info("\tBuilding theme...")
        
        try:
            tarball = urlopen(self.theme_url).read()
        except HTTPError:
            print("Error downloading theme from %s" % self.theme_url)
            sys.exit(1)

        workPath = FilePath(mkdtemp())
        sourceFile = workPath.child("theme.tar.gz")

        # change dir to fix issue with sphinx & themes
        os.chdir(self.docPath.path)

        o = open(sourceFile.path , "w")
        o.write(tarball)
        o.close()
        tar = opentar(sourceFile.path, mode='r:*')
        tar.extractall(workPath.path)

        theme = None
        for d in workPath.listdir():
            theme = workPath.child(d)
            if theme.isdir():
                theme = theme.child("source").child("themes")
                dest = self.docPath.child("themes")
                theme.moveTo(dest)
                break
Ejemplo n.º 2
0
  def beginjob(self, evt, env):
    """The beginjob() function is called at an XTC configure transition.
    It opens per-process tar files to avoid clobbering while
    multiprocessing.

    @param evt Event data object, a configure object
    @param env Environment object
    """

    from collections import deque
    from tarfile import open as opentar

    # The maxlen parameter specifies for how many shots the direction
    # of the principal component must be stable before it can be
    # considered a clear view of the capillary.
    self._angles = deque(maxlen=10)

    if not os.path.isdir(self._out_dirname):
      os.makedirs(self._out_dirname)

    if env.subprocess() >= 0:
      basename = '%sp%02d-r%04d.tar' % (
        self._out_basename, env.subprocess(), evt.run())
    else:
      basename = '%sr%04d.tar' % (
        self._out_basename, evt.run())

    self._tar = opentar(os.path.join(self._out_dirname, basename), 'w')
Ejemplo n.º 3
0
  def beginjob(self, evt, env):
    """The beginjob() function is called at an XTC configure transition.
    It opens per-process tar files to avoid clobbering while
    multiprocessing.

    @param evt Event data object, a configure object
    @param env Environment object
    """

    from collections import deque
    from tarfile import open as opentar

    # The maxlen parameter specifies for how many shots the direction
    # of the principal component must be stable before it can be
    # considered a clear view of the capillary.
    self._angles = deque(maxlen=10)

    if not os.path.isdir(self._out_dirname):
      os.makedirs(self._out_dirname)

    if env.subprocess() >= 0:
      basename = '%sp%02d-r%04d.tar' % (
        self._out_basename, env.subprocess(), evt.run())
    else:
      basename = '%sr%04d.tar' % (
        self._out_basename, evt.run())

    self._tar = opentar(os.path.join(self._out_dirname, basename), 'w')
Ejemplo n.º 4
0
def actualizar_datos(ubicacion, archivo, destino, destino_temp):
    nombre_archivo = os.path.join(destino_temp, '{}.tar.gz'.format(ubicacion))

    with open(nombre_archivo, 'wb') as file_out:
        file_out.write(b64decode(archivo))

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

    with opentar(nombre_archivo) as tar_file:
        tar_file.extractall(path=destino)
Ejemplo n.º 5
0
def run_backup(directory):
  backups = join(getcwd(),"Backups")
  try: backups=expandvars('${BACKUP_LOCATION}')
  except:pass
  finally:backups=join(backups,basename(directory))
  makedirs(backups,exist_ok=True)
  recent = max([0]+list(map(getmtime,filter([join(backups,f) for f in listdir(backups)],join(backups,FILE_PATTERN)))))
  archive_name, archive_recent, = directory_filter(directory), recent_filter(recent)
  file_names = [f for f in get_filelist(walk(directory)) if archive_recent(f)]
  if len(file_names)<1:
    print("No files to backup are more recent than the most recent backup.")
    return
  with opentar(join(backups,FILE_PATTERN.replace("*","{}").format(int(time()))),'w:'+FILE_PATTERN[FILE_PATTERN.rfind(".")+1:]) as tarobj:
    for fn in file_names:
      tarobj.add(fn,arcname=archive_name(fn))
      print(archive_name(fn))
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
import os.path
from tarfile import open as opentar

from google_drive_downloader import GoogleDriveDownloader as gdd

# download MBH
if not os.path.exists("tutorial/data/mbh"):
    gdd.download_file_from_google_drive(
        file_id="1iL071Fi5MxHle0CLOqg3JkZIgjQF8EwF",
        dest_path="tutorial/data/MBHDemo.tar",
        showsize=True,
    )
    with opentar("tutorial/data/MBHDemo.tar", "r") as tar:
        tar.extractall(
            "tutorial/data/mbh")  # specify which folder to extract to
    os.remove("tutorial/data/MBHDemo.tar")

# download UCB
if not os.path.exists("tutorial/data/ucb"):
    # 06 mo
    gdd.download_file_from_google_drive(
        file_id="14ZgAU_67ZzxTJyaScUH_i22nSkpNOp36",
        dest_path="tutorial/data/UCBDemo_06.tar",
        showsize=True,
    )
    with opentar("tutorial/data/UCBDemo_06.tar", "r") as tar:
        tar.extractall(
            "tutorial/data/ucb")  # specify which folder to extract to
    os.remove("tutorial/data/UCBDemo_06.tar")
Ejemplo n.º 7
0
def extract_tar(url, extract_to):
    fstream = BytesIO(get(url).content)
    tar_arc = opentar(fileobj=fstream)
    tar_arc.extractall(path=extract_to)