コード例 #1
0
ファイル: httpOperation.py プロジェクト: umutboz/code-gen-lib
 def fetch(self, url=None):
     request_url = None
     if url is not None:
         request_url = str(url)
     else:
         request_url = self.url()
     if request_url is None:
         Base.log(self, message="HttpOperation " + "request : "
                                + " \error : \n url cannot be None", message_type=MESSAGE_TYPE.ERROR)
         return
     try:
         resp = urllib2.urlopen(request_url)
         data_string = resp.read().decode('utf-8')
         Base.log(self, message="HttpOperation " + "request : " + str(request_url) + " \nresponse : \n" + data_string,
                  message_type=MESSAGE_TYPE.INFO)
         return data_string
     except urllib2.HTTPError as e:
         Base.log(self, message="HttpOperation " + "request : "
                                + " \HTTPError : \n " + str(e.code), message_type=MESSAGE_TYPE.ERROR)
     except urllib2.URLError as e:
         Base.log(self, message="HttpOperation " + "request : " + " \\URLError : \n " + str(e.reason),
                  message_type=MESSAGE_TYPE.ERROR)
     except Exception as e:
         Base.log(self, message="HttpOperation " + "request : "
                                + " \generic exception : \n " + str(e), message_type=MESSAGE_TYPE.ERROR)
     return None
コード例 #2
0
 def remove(self, filePath):
     if self.isExist(filePath):
         os.remove(filePath)
         Base.log(self, message="FileOperation " + "remove : " + filePath +
                  "\n file was removed", messageType=MESSAGETYPE.INFO)
     else:
         Base.log(self, message="FileOperation " + "remove : " + filePath +
                  "\n has not found file", messageType=MESSAGETYPE.INFO)
         return ""
コード例 #3
0
 def readContent(self,filePath):
     global content
     if self.isExist(filePath):
         with open(filePath, "r") as data:
             content = data.read()
         return content
     else:
         Base.log(self, message="FileOperation " + "readContent : " + filePath +
                  "\n has not found file", messageType=MESSAGETYPE.INFO)
         return ""
コード例 #4
0
 def create(self,filePath, content):
     try:
         filePath = open(filePath, "w")
         filePath.write(content)
         filePath.close()
         Base.log(self, message="FileOperation " + "create : " + str(filePath) + " \ncontent : \n" + content,
          messageType=MESSAGETYPE.INFO)
     except OSError as e:
         Base.log(self,message = "FileOperation " + "create : " 
         + " \error : \n" + str(e), messageType=MESSAGETYPE.ERROR)
コード例 #5
0
ファイル: templateFile.py プロジェクト: umutboz/code-gen-lib
 def __init__(self,
              name,
              dict,
              output_file,
              is_child_template=False,
              parent_mustache=""):
     Base.__init__(self)
     self.name = name
     self.dict = dict
     self.outputFile = output_file
     self.isChildTemplate = is_child_template
     self.parentMustache = parent_mustache
コード例 #6
0
 def appendFile(self, fileName, content,isTruncate=False):
     filePath = self.getPath() + CODING.SLASH + fileName
     try:
         with open(filePath, "a+") as f:
         # f.seek(0)
             if isTruncate:
                 f.truncate()
             f.write(content)
             f.close()
             Base.log(self,message = "FileOperation " + "appendFile : " + 
                 filePath + "\n", messageType=MESSAGETYPE.INFO)
     except OSError as e:
         Base.log(self,message = "FileOperation " + "appendFile : " + " \error : \n" + 
         str(e), messageType=MESSAGETYPE.ERROR)
コード例 #7
0
ファイル: fileOperation.py プロジェクト: umutboz/code-gen-lib
 def createFile(self, file_name, content):
     file_path = self.getPath() + CODING.SLASH + file_name
     try:
         file_path = open(file_path, "w")
         file_path.write(content)
         file_path.close()
         Base.log(self,
                  message="FileOperation " + "createFile : " +
                  str(file_path) + " \ncontent : \n" + content,
                  message_type=MESSAGE_TYPE.INFO)
     except OSError as e:
         Base.log(self,
                  message="FileOperation " + "createFile : " +
                  " \error : \n" + str(e),
                  message_type=MESSAGE_TYPE.ERROR)
コード例 #8
0
 def request(self, url=None, http_method="GET"):
     request_url = None
     if url is not None:
         request_url = str(url)
     else:
         request_url = self.url()
     if request_url is None:
         Base.log(self,
                  message="HttpOperation " + "request : " +
                  " \error : \n url cannot be None",
                  message_type=MESSAGE_TYPE.ERROR)
         return
     try:
         http = urllib3.PoolManager()
         resp = http.request(http_method, request_url)
         data_string = resp.data.decode('utf-8')
         Base.log(self,
                  message="HttpOperation " + "request : " +
                  str(request_url) + " \nresponse : \n" + data_string,
                  message_type=MESSAGE_TYPE.INFO)
         self._response = data_string
         return self
     except urllib3.exceptions.HTTPError as e:
         Base.log(self,
                  message="HttpOperation " + "request : " +
                  " \HTTPError : \n " + str(e.code),
                  message_type=MESSAGE_TYPE.ERROR)
     except urllib3.exceptions.RequestError as e:
         Base.log(self,
                  message="HttpOperation request : URLError : " +
                  str(e.reason),
                  message_type=MESSAGE_TYPE.ERROR)
     except Exception as e:
         Base.log(self,
                  message="HttpOperation " + "request : " +
                  " \generic exception : \n " + str(e),
                  message_type=MESSAGE_TYPE.ERROR)
     self._response = None
     return None
コード例 #9
0
 def createFolder(self, folderName):
     folderPath = self.getPath() + CODING.SLASH + folderName
     try:
         if not os.path.isdir(folderPath):
             os.makedirs(folderPath)
             Base.log(self,message = "FileOperation " + "createFolder : " + 
             folderPath + "\n", messageType=MESSAGETYPE.INFO)
         else :
             Base.log(self,message = "FileOperation " + "createFolder : " + 
             folderPath + "\n already path", messageType=MESSAGETYPE.INFO)
     except OSError as e:
         Base.log(self,message = "FileOperation " + "createFileWithPath : " + " \error : \n" + 
         str(e), messageType=MESSAGETYPE.ERROR)
コード例 #10
0
ファイル: fileOperation.py プロジェクト: umutboz/code-gen-lib
 def createFolderWithoutPath(self, folder_name):
     folder_path = folder_name
     try:
         if not os.path.isdir(folder_path):
             os.makedirs(folder_path)
             Base.log(self,
                      message="FileOperation " + "createFolder : " +
                      folder_path + "\n",
                      message_type=MESSAGE_TYPE.INFO)
         else:
             Base.log(self,
                      message="FileOperation " + "createFolder : " +
                      folder_path + "\n already path",
                      message_type=MESSAGE_TYPE.INFO)
     except OSError as e:
         Base.log(self,
                  message="FileOperation " + "createFileWithPath : " +
                  " \error : \n" + str(e),
                  message_type=MESSAGE_TYPE.ERROR)
コード例 #11
0
 def __init__(self, source, output_path, is_online=False):
     Base.__init__(self)
     self.source = source
     self.outputPath = output_path
     self.isOnline = is_online
コード例 #12
0
 def __init__(self, name, templates_files, template_folders=[], output_root_path=pathname):
     Base.__init__(self)
     self.name = name
     self.templateFiles = templates_files
     self.outputRootPath = output_root_path
     self.templateFolders = template_folders
コード例 #13
0
 def __init__(self, path=None):
     Base.__init__(self)
     self._path = path
コード例 #14
0
 def __init__(self, url=None):
     Base.__init__(self)
     self._url = url
コード例 #15
0
 def __init__(self):
     Base.__init__(self)
コード例 #16
0
__all__ = [ 'Formatter',
            'CSVFormatter',
            'HTMLFormatter',
            'TextFormatter',
            'XMLFormatter' ]

from abstract import Base as Formatter
from csv import CSVFormatter
from html import HTMLFormatter
from text import TextFormatter
from xml import XMLFormatter

Formatter.register('C', CSVFormatter)
Formatter.register('H', HTMLFormatter)
Formatter.register('T', TextFormatter)
Formatter.register('X', XMLFormatter)