% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  pdftitle={python-script-to-build-an-oracle-or-mysql-flat-file-vault},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{python-script-to-build-an-oracle-or-mysql-flat-file-vault}
\author{}
\date{}

\begin{document}
\maketitle

\hypertarget{python-script-to-build-an-oracle-or-mysql-flat-file-vault}{%
\section{python-script-to-build-an-oracle-or-mysql-flat-file-vault}\label{python-script-to-build-an-oracle-or-mysql-flat-file-vault}}

\hypertarget{python-script-to-build-an-oracle-or-mysql-flat-file-vault-1}{%
\section{Python script to build an Oracle or mySQL flat file
vault}\label{python-script-to-build-an-oracle-or-mysql-flat-file-vault-1}}

This module provides a vault class. This class is useful for creating a
flat filesystem that could be used for storing images, pdfs, mp3,
autocad drawings etc.

The meta data about this file system would have to be stored in a
database.

\emph{pyVault.py}

.. code-block:: python

from os import makedirs, path from random import randrange as r from
uuid import uuid4

class Vault( object ): def \textbf{init}( self, path='`, name='vault',
l=65, w=65 ): self.path = path self.name = name self.l = l self.w = w

\begin{verbatim}
     self.initVault()

 def initVault( self ):
     """Build the vault directories if they don't exist"""
     p = self.path + '/' + self.name
     if path.exists( p ):
         pass
     else:
         for l in range( self.l ):
             for w in range( self.w ):
                 if self.path == '':
                     makedirs( self.name + '/' + str( l ) + '/' + str( w ) )
                 else:
                     makedirs(  self.path + '/' + self.name + '/' + str( l ) + '/' + str( w ) )

 def getFilename( self, ext='' ):
     """Generate and return a valid unique file path based on vault"""
     l, w = str( r(self.l) ), str( r(self.w) )
     filename = str( uuid4() )
    
     return self.name + '/' + l + '/' + w + '/' + filename + ext
\end{verbatim}

\hypertarget{example-pyvault-test}{%
\section{Example pyvault test}\label{example-pyvault-test}}

\emph{test\_pyVault.py}

.. code-block:: python

\# import pyVault module from pyVault import Vault

\# create a vault with default settings in the current directory. v =
Vault( ) \# create a vault object

print v.getFilename() \# generate a valid path and filename from vault
print v.getFilename( `.jpg' ) \# generate a valid path and jpg filename
from vault

\# create vault2 in /var/db 2 directories wide and 5 directories deep v2
= Vault( path=``/var/db'', name=``vault2'', l=5, w=2 )

print v2.getFilename( `.mp3' ) \# generate a valid path and mp3 filename
from vault print v2.getFilename() \# generate a valid path and filename
from vault

\hypertarget{example-database-schema-to-use-with-pyvault}{%
\section{Example database schema to use with
pyVault}\label{example-database-schema-to-use-with-pyvault}}

UUIDs are used for the actual file names to prevent overwriting if we
need version control.

UUIDs are also a great `key' that we could search on in a database.

Below shows an example database schema that could use this vault
filesystem:

.. code-block:: mysql

vault id (int) \# auto increment uuid (varchar 32) \# indexed field:
28c6104f-cb09-4910-8031-efad22e1ebf9 name (varchar 64) \# human readable
filename: foxhop-october.jpg location (varchar 128) \#
vault/12/59/28c6104f-cb09-4910-8031-efad22e1ebf9.jpg filetype (varchar
8) \# extension (move to own table?): jpg description (text) \#
comments, description, info: foxhop in october

Then other tables can refer and relate to this data, like a job table
could have relations mapped to jpg files and pdf files, and a video of
the finished job and an autocad drawing when it was designed.

\end{document}
