diff --git a/atgcsv.py b/atgcsv.py index 87d1ddf..0b0544e 100755 --- a/atgcsv.py +++ b/atgcsv.py @@ -12,7 +12,7 @@ License: GPLv3 ''' from sys import argv from os.path import split -from ktt import ATG, CSVData, TemplateV2 +from att import ATG, CSVData, TemplateV2 if __name__ == '__main__': if len(argv) == 3: diff --git a/att/atg.py b/att/atg.py index e09f417..6923d10 100644 --- a/att/atg.py +++ b/att/atg.py @@ -30,15 +30,14 @@ class ATG(object): else: self.multiple = False - def join_filename(self, path, name, extension): - ''' - Returns a file name for given path, name and extension. - ''' - if extension: - return join(unicode(path),name+'.'+extension) - else: - return join(unicode(path),name) - + def join_filename(self, path, name, extension): + ''' + Returns a file name for given path, name and extension. + ''' + if extension: + return join(unicode(path),name+'.'+extension) + else: + return join(unicode(path),name) def write_files(self, outputDir='.'): ''' @@ -72,7 +71,7 @@ class ATG(object): newpath = join(newpath, i) if not exists(join(unicode(outputDir),newpath)): makedirs(join(unicode(outputDir),newpath)) - fname = self.join_filename(outputDir, name, extension) + fname = self.join_filename(outputDir, name, extension) f = open(fname, 'w') f.write(out.encode(encoding)) self.log(' Saved %s' % fname) diff --git a/docs/att.atg.html b/docs/att.atg.html new file mode 100644 index 0000000..6428df9 --- /dev/null +++ b/docs/att.atg.html @@ -0,0 +1,62 @@ + + +Python: module att.atg + + + + +
 
+ 
att.atg
index
c:\workbench\projects\att\att\atg.py
+

Automatic Text Generator module for a Automatic Text Tools.

+(c) 2013 Ivan "Kai SD" Korystin 

+License: GPLv3

+

+ + + + + +
 
+Classes
       
+
__builtin__.object +
+
+
ATG +
+
+
+

+ + + + + + + +
 
+class ATG(__builtin__.object)
   Automatic Text Generator is a class, created to generate multiple
+text files from table data.
 
 Methods defined here:
+
__init__(self, data, template)
Constructor.
+data - an instance of the data.Data class (i.e. CSVData)
+template - an instance of the template.Template class (i.e. TemplateV2)
+ +
join_filename(self, path, name, extension)
Returns a file name for given path, name and extension.
+ +
log(self, text)
Print information
+ +
write_files(self, outputDir='.')
Write generated files to the given directory.
+ +
+Data descriptors defined here:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ \ No newline at end of file diff --git a/docs/att.atr.html b/docs/att.atr.html new file mode 100644 index 0000000..b871fcc --- /dev/null +++ b/docs/att.atr.html @@ -0,0 +1,83 @@ + + +Python: module att.atr + + + + +
 
+ 
att.atr
index
c:\workbench\projects\att\att\atr.py
+

Automatic Text Replacer module for a Automatic Text Tools.

+(c) 2013 Ivan "Kai SD" Korystin 

+License: GPLv3

+

+ + + + + +
 
+Modules
       
re
+

+ + + + + +
 
+Classes
       
+
__builtin__.object +
+
+
ATR +
+
+
+

+ + + + + + + +
 
+class ATR(__builtin__.object)
   Automatic Text Replacer - is a class, created to make multiple replacements
+in the content or names of text file.
+It can make plain replacements, or use ATG templates to do something more complex.
 
 Methods defined here:
+
__init__(self, files)
Constructor
+ +
clear_replacements(self)
Removes all replacements.
+ +
log(self, string)
Print information
+ +
plain_replace(self, pattern, string, regexp=False)
Replaces the given pattern with string in files.
+ +
replace_in_names(self)
Do replacement, but in file names instead of file content. Returns the list of new file names,
+you can use it with writeNewFiles() method.
+ +
templated_replace(self, pattern, template, data, keyFormat='filename', regexp=False)
Replaces the given pattern with data formated by template.
+Valid values for keyFormat:
+filename - take data rows by filename(path ignored), key value of the data row should store the filename.
+fullname - as filename, but with path.
+index - take data rows in order, key value of the data row should store the index. Indexes starts with 0.
+If filename or index cannot be found in data keys, pattern will not be replaced.
+ +
write_in_place(self)
Do replacement and save the files
+ +
write_new_files(self, outfiles)
Do replacement, but save to given files instead of the original ones.
+ +
+Data descriptors defined here:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ \ No newline at end of file diff --git a/docs/att.data.html b/docs/att.data.html new file mode 100644 index 0000000..c5c1467 --- /dev/null +++ b/docs/att.data.html @@ -0,0 +1,170 @@ + + +Python: module att.data + + + + +
 
+ 
att.data
index
c:\workbench\projects\att\att\data.py
+

Data module for a Automatic Text Tools.

+(c) 2013 Ivan "Kai SD" Korystin 

+License: GPLv3

+

+ + + + + +
 
+Modules
       
cStringIO
+
codecs
+
csv
+

+ + + + + +
 
+Classes
       
+
__builtin__.object +
+
+
Data +
+
+
CSVData +
+
+
+
+
+

+ + + + + + + +
 
+class CSVData(Data)
   Class for reading CSV files.
 
 
Method resolution order:
+
CSVData
+
Data
+
__builtin__.object
+
+
+Methods defined here:
+
__init__(self, file, encoding='utf-8', delimiter=';', quotechar='"', **kwargs)
Constructor.

+filename - CSV table filename
+encoding - CSV table encoding (default: utf-8)
+delimiter - CSV table delimiter (default: ;)
+quotechar - CSV table quotechar (default: ")
+ +
export_csv(self, filename, encoding='utf-8', delimiter=';', quotechar='"', **kwargs)
Saves the data to CSV file

+filename - CSV table filename
+encoding - CSV table encoding (default: utf-8)
+delimiter - CSV table delimiter (default: ;)
+quotechar - CSV table quotechar (default: ")
+ +
+Data and other attributes defined here:
+
Reader = <class att.data.Reader>
+ +
Writer = <class att.data.Writer>
+ +
+Methods inherited from Data:
+
__getitem__(self, pair)
Returns a value for given key and row.
+ +
__repr__(self)
+ +
__setitem__(self, pair, value)
Sets a value for given key and row.
+ +
__str__(self)
Returns data as string.
+ +
add_data(self, other)
Adds rows from another data table to this one.
+ +
add_keys(self, *h)
Adds new keys to the data.
+ +
add_rows(self, n=1)
Adds some empty rows to the data.
+ +
col_by_idx(self, idx)
Returns a column by header's index
+ +
col_by_key(self, key)
Returns a column by header's name
+ +
del_row(self, idx)
Removes giver row from data
+ +
has_key(self, key)
Returns True if given key exists in data
+ +
row_by_idx(self, idx)
Returns a row by index.
+ +
transpose(self, key_idx=0)
Returns the transposed copy of the data.

+key_idx - index of the column, that contains keywords (default: 0)
+ +
+Data descriptors inherited from Data:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ + + + + + + +
 
+class Data(__builtin__.object)
   Empty data class. Can be used for a subclassing or procedural data creation.
 
 Methods defined here:
+
__getitem__(self, pair)
Returns a value for given key and row.
+ +
__init__(self, *args, **kwargs)
Constructor
+ +
__repr__(self)
+ +
__setitem__(self, pair, value)
Sets a value for given key and row.
+ +
__str__(self)
Returns data as string.
+ +
add_data(self, other)
Adds rows from another data table to this one.
+ +
add_keys(self, *h)
Adds new keys to the data.
+ +
add_rows(self, n=1)
Adds some empty rows to the data.
+ +
col_by_idx(self, idx)
Returns a column by header's index
+ +
col_by_key(self, key)
Returns a column by header's name
+ +
del_row(self, idx)
Removes giver row from data
+ +
has_key(self, key)
Returns True if given key exists in data
+ +
row_by_idx(self, idx)
Returns a row by index.
+ +
transpose(self, key_idx=0)
Returns the transposed copy of the data.

+key_idx - index of the column, that contains keywords (default: 0)
+ +
+Data descriptors defined here:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ \ No newline at end of file diff --git a/docs/att.html b/docs/att.html new file mode 100644 index 0000000..c225c00 --- /dev/null +++ b/docs/att.html @@ -0,0 +1,25 @@ + + +Python: package att + + + + +
 
+ 
att
index
c:\workbench\projects\att\att\__init__.py
+

+

+ + + + + +
 
+Package Contents
       
atg
+
atr
+
data
+
template
+
+ \ No newline at end of file diff --git a/docs/att.template.html b/docs/att.template.html new file mode 100644 index 0000000..c1ba85b --- /dev/null +++ b/docs/att.template.html @@ -0,0 +1,162 @@ + + +Python: module att.template + + + + +
 
+ 
att.template
index
c:\workbench\projects\att\att\template.py
+

Template module for a Automatic Text Tools.

+(c) 2013 Ivan "Kai SD" Korystin 

+License: GPLv3

+

+ + + + + +
 
+Modules
       
re
+

+ + + + + +
 
+Classes
       
+
__builtin__.object +
+
+
Template +
+
+
TemplateV2 +
+
+
+
+
+

+ + + + + + + +
 
+class Template(__builtin__.object)
   Empty template class. Generates empty text.
 
 Methods defined here:
+
log(self, text)
Print information
+ +
process(self, data)
Replace this method in subclasses.
+ +
warning(self, text)
Prints a warning
+ +
+Data descriptors defined here:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ + + + + + + +
 
+class TemplateV2(Template)
   Class for reading ATGv2 templates.

+ATGv2 template file should be a plain text file, starting with the line
+ATGV2
+followed by the info line:
+[$KeyField$Extension$Prefix$Encoding$]
+where
+KeyField - is a name of a data column, that contains an identifier.
+Extension - is the desired extension for the generated files.
+Prefix - is the desired filename prefix for the generated files
+Encoding - is the desired encoding for the generated files.
+The line may also have some optional keywords before the closing bracket:
+oneFile$ - place all generated text into a single file instead of
+generating a file for each table row.
+After the info line, you can put your text.
+You can use following commands to handle the data:
+* [$Name$], where Name is the column header,
+will be replaced with value from the current row.
+* [$ATGLINDEX$] will be replaced with the number of a current row.
+* [$ATGHEADER$Text$] and [$ATGFOOTER$Text$] will place the given text
+at the begining or at the end of the file. You can't use other
+commands in this text.
+* [$ATGLIST$Name$Text$], where Name is a multi-column header
+(i.e. 'Col' will represent 'Col1', 'Col2', 'Col3' etc)
+will repeat the given text for each non-empty value.
+You can use other commands in Text. Also [$Name$] inside the list
+will be replaced with the value for the current row and column.
+* [$ATGLINDEX$] can be used only inside the ATGLIST text,
+will be replaced with the current column index.
+* [$ATGLISTCUT$Name$Text$] - same as ATGLIST, but the last symbol
+will be removed. Useful for removing unnecessary newlines.
+* [$ATGIF$Name$Value$Text$] will be replaced with the given text
+only if the the given column's value is the same as the given one.
+Will be replaced with the empty text otherwise. You can use other
+commands in Text.
+* [$ATGIFNOT$Name$Value$Text$] - same as ATGIF, but the column's value
+should not be equal to the given one.
+* [$ATGGREATER$Name$Value$Text$] - same as ATGIF, but the value should
+be the number and it should be greater then the given one.
+* [$ATGGREATER$Name$Value$Text$] - same as ATGGREATER, but the value
+should be less then the given one.
+* [$ATGREPLACE$Text1$Text2$] - Will replace Text1 with Text2. Replacements
+will be done after all other commands. You can't use regular expressions or
+other commands in the text.
+* [$ATGPREFIX$Text$] - Will add the given text to the filename prefix.
+You can use other commands in text, but do it carefully.
+* [$ATGSKIP$] - Skip the current row. Use only in combination with the
+ATGIF/ATGIFNOT, or you will generate nothing.
+* [$ATGPREV$Name$], where Name is the column header,
+will be replaced with the with the value of the given header from the
+previous row. ATGSKIP will be used for the first row.
 
 
Method resolution order:
+
TemplateV2
+
Template
+
__builtin__.object
+
+
+Methods defined here:
+
__init__(self, filename=None, encoding='utf-8', text='')
Constructor.

+filename - name of the ATGv2 template file.
+encoding - encoding of the template file.
+text - text to use if no filename has been provided.
+ +
process(self, data)
Generate text for the given data.
+ +
+Static methods defined here:
+
express(cls, text, **kwargs)
+ +
+Methods inherited from Template:
+
log(self, text)
Print information
+ +
warning(self, text)
Prints a warning
+ +
+Data descriptors inherited from Template:
+
__dict__
+
dictionary for instance variables (if defined)
+
+
__weakref__
+
list of weak references to the object (if defined)
+
+

+ \ No newline at end of file