Пример #1
0
    def __init__ (self, name, node, mime=None, uuid=None):

        self.base = node.base if node and node.base else node
        self.node = node

        self._uuid = uuid if uuid else str (uuid_random ())
        self._mime = mime if mime else 'application/property'
        self._name = name
Пример #2
0
    def __init__ (self, name, node, mime=None, uuid=None):

        self.base = node.base if node and node.base else node
        self.node = node

        self._uuid = uuid if uuid else str (uuid_random ())
        self._mime = mime if mime else 'application/property'
        self._name = name
Пример #3
0
    def __init__ (self, name, root, mime=None, uuid=None):

        self.base = root.base if root and root.base else root
        self.root = root

        self._mime = mime if mime else 'application/node'
        self._uuid = uuid if uuid else str (uuid_random ())
        self._name = unicode (name) if name is not None else None
Пример #4
0
    def __init__(self, name, root, mime=None, uuid=None):

        self.base = root.base if root and root.base else root
        self.root = root

        self._mime = mime if mime else 'application/node'
        self._uuid = uuid if uuid else str(uuid_random())
        self._name = unicode(name) if name is not None else None
Пример #5
0
    def stamp_in(self):
        if self.slices:
            lastslice = self.slices[-1]

            if not lastslice.is_closed():
                raise (UserWarning('The last time slice is still open'))

        slice_new = TimeSlice({}, self.dt_now())
        slice_new.header_add('UUID', str(uuid_random()))

        self.slices.append(slice_new)
Пример #6
0
def create_download_link(product):

    uuid = str(uuid_random())

    assert product.link
    upr = urlparse(product.link)
    assert product.path
    path_base, path_file = os.path.split(product.path)

    _, ext = os.path.splitext(path_file)

    assert path_base, upr.path
    path_uuid = os.path.join(path_base, upr.path[1:])
    subprocess.call(['mkdir', '-p', path_uuid])

    assert path_uuid
    path_uuid = os.path.join(path_uuid, uuid)
    os.symlink(product.path, path_uuid + ext)

    return os.path.join(product.link, uuid + ext)
Пример #7
0
def create_download_link (product):

    uuid = str (uuid_random ())

    assert product.link
    upr = urlparse (product.link)
    assert product.path
    path_base, path_file = os.path.split (product.path)

    _, ext = os.path.splitext (path_file)

    assert path_base, upr.path
    path_uuid = os.path.join (path_base, upr.path[1:])
    subprocess.call (['mkdir', '-p', path_uuid])

    assert path_uuid
    path_uuid = os.path.join (path_uuid, uuid)
    os.symlink (product.path, path_uuid + ext)

    return os.path.join (product.link, uuid + ext)
Пример #8
0
    def get_uuid_path (self, session_key):

        session_path = os.path.join (settings.MEDIA_DATA, session_key)
        if not os.path.exists (session_path): os.mkdir (session_path)

        return os.path.join (session_path, str (uuid_random ()))
Пример #9
0
    def _process (self, data):

        prefix, payload = data.split ('-', 1)

        ## --------------------------------------------------------------------
        ## Copy Sphinx template from source to target path
        ## --------------------------------------------------------------------

        template_path = app.config['SPHINX_TEMPLATE_PATH']
        source_path = '00000000-0000-0000-0000-000000000000'
        source_path = os.path.join (template_path, source_path)
        assert os.path.exists (source_path)

        temp_path = app.config['SPHINX_TEMP_PATH']
        if not os.path.exists (temp_path): os.makedirs (temp_path)
        assert os.path.exists (temp_path)
        target_path = os.path.join (temp_path, str (uuid_random()))

        shutil.copytree (source_path, target_path)

        ## --------------------------------------------------------------------
        ## Extract project files to target (sub-)path
        ## --------------------------------------------------------------------

        target_subpath = os.path.join (target_path, 'source')
        assert os.path.exists (target_subpath)

        with tempfile.TemporaryFile () as zip_file:

            zip_file.write (payload)
            zip_file.flush ()

            extract (zip_file, path=target_subpath)

        title = 'project'
        for dirpath, dirnames, filenames in os.walk (target_subpath):

            if dirpath == target_subpath:
                continue

            for filename in filenames:
                shutil.move (os.path.join (dirpath, filename), target_subpath)
            for dirname in dirnames:
                shutil.move (os.path.join (dirpath, dirname), target_subpath)

            os.rmdir (dirpath); _, title = os.path.split (dirpath)

        ## --------------------------------------------------------------------
        ## Create Sphinx configuration from YAML file
        ## --------------------------------------------------------------------

        latex_backend = 'xelatex'
        for dirpath, dirnames, filenames in os.walk (target_subpath):

            yaml_path = None
            for filename in filenames:
                if guess_mime_ex (filename, dirpath) == 'text/x-yaml':
                    yaml_path = os.path.join (dirpath, filename)
                    latex_backend = yaml2py (yaml_path, dirpath)
                    break

            if yaml_path:
                break

        if latex_backend not in ['xelatex', 'pdflatex']:
            latex_backend = 'xelatex' ## security!

        ## --------------------------------------------------------------------
        ## Invoke PDF, LaTex or HTML conversion & ZIP package result
        ## --------------------------------------------------------------------

        if prefix == 'html':
            converter = HtmlConverter (target_path)
            converter.translate ()

        elif prefix == 'latex':
            converter = LatexConverter (target_path, latex_backend)
            converter.translate (source_path)

        else:
            converter = LatexConverter (target_path, latex_backend)
            converter.translate (source_path)
            converter = PdfConverter (target_path, latex_backend)
            converter.translate (source_path)

        payload = converter.pack (title)

        ## --------------------------------------------------------------------
        ## Cleanup `source-path` in production environment
        ## --------------------------------------------------------------------

        if not app.dev:
            shutil.rmtree (target_path, ignore_errors=True)

        return payload
Пример #10
0
 def _meta(self):
     """
     Should return a **JSON serializable** object with meta information
     about the current conversion process.
     """
     return dict(uuid=str(uuid_random()))
Пример #11
0
    def get_uuid_path (self, session_key):

        session_path = os.path.join (settings.MEDIA_DATA, session_key)
        if not os.path.exists (session_path): os.mkdir (session_path)

        return os.path.join (session_path, str (uuid_random ()))
Пример #12
0
 def _meta (self):
     """
     Should return a **JSON serializable** object with meta information
     about the current conversion process.
     """
     return dict(uuid=str (uuid_random()))
Пример #13
0
def uuid_python():
    return str(uuid_random())
Пример #14
0
    def __init__(self, name, mail, uuid=None):

        self.uuid = uuid if uuid else str(uuid_random())
        self.name = unicode(name)
        self.mail = unicode(mail)
Пример #15
0
    def __init__ (self, name, mail, uuid=None):

        self.uuid = uuid if uuid else str (uuid_random ())
        self.name = unicode (name)
        self.mail = unicode (mail)
Пример #16
0
    def transaction_hash(self, last=False):

        if not last:
            self.last_thash = uuid_random().hex + uuid_random().hex

        return self.last_thash
Пример #17
0
    def transaction_hash (self, last=False):

        if not last:
            self.last_thash = uuid_random ().hex + uuid_random ().hex

        return self.last_thash
Пример #18
0
def uuid_python():
    return str(uuid_random())