Created
November 25, 2013 05:10
-
-
Save pumbaEO/7636666 to your computer and use it in GitHub Desktop.
pre commit hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import sys | |
import subprocess | |
import shutil | |
from os.path import exists | |
import logging | |
import logging | |
logging.basicConfig(level=logging.INFO) # DEBUG => print ALL msgs | |
logging.debug('This message should go to the log file') | |
logging.info('So should this') | |
logging.warning('And this, too') | |
def get_list_of_comitted_files(): | |
""" | |
Retun a list of files abouts to be decompile | |
""" | |
files = [] | |
output = [] | |
try: | |
output = subprocess.check_output(['git','diff-index', '--cached','HEAD']).decode("utf-8") | |
except subprocess.CalledProcessError: | |
print("Error diff files get: trace %s" % subprocess.CalledProcessError.output) | |
return files | |
for result in output.split("\n"): | |
if result != '': | |
result = result.split() | |
if result[4] in ['A', 'M']: | |
files.append(result[5]) | |
return files | |
def _copyonlydirs(path, names): | |
result = [] | |
for name in names: | |
if os.path.isfile(os.path.join(path, name, os.path.sep)): | |
result.append(name) | |
logging.info('Working in %s' % path) | |
return result | |
def checker(): | |
""" | |
Main functions doing be decompile | |
""" | |
#list of files to decompile and results decompile | |
dataprocessor_files = [] | |
#set the exit code | |
exit_code = 0 | |
#Find datapocessor files | |
for filename in get_list_of_comitted_files(): | |
#Check the file extensions | |
if filename[-3:] in ['epf', 'erf', '.py']: | |
dataprocessor_files.append(filename) | |
logging.info("file %s" % filename) | |
continue | |
if len(dataprocessor_files) == 0: | |
exit(exit_code) | |
dirsource = os.path.abspath(os.path.join(os.path.curdir, "src")) | |
curabsdirpath = os.path.abspath(os.path.curdir) | |
for filename in dataprocessor_files: | |
print("file %s" % filename) | |
#TODO: добавить копирование этих же файлов в каталог src/имяфайла/... | |
#get file name. | |
fullpathfile = os.path.abspath(filename) | |
basename = os.path.splitext(os.path.basename(filename))[0] | |
fullbasename = os.path.basename(filename) | |
newdirname = os.path.dirname(filename) | |
#Скопируем сначало просто структуру каталогов. | |
if not os.path.exists(dirsource): | |
shutil.copytree(os.path.curdir, dirsource, False, _copyonlydirs) | |
#для каждого файла определим | |
newsourcepath = os.path.join(dirsource, newdirname, basename) | |
logging.info("create new dir %s" % newsourcepath) | |
if not os.path.exists(newsourcepath): | |
logging.info("create new dir %s" % newsourcepath) | |
os.mkdir(newsourcepath) | |
logging.info("file to copy %s, new path %s, new file %s" % (filename, newsourcepath, | |
os.path.join(newsourcepath,fullbasename))) | |
shutil.copyfile(filename, os.path.join(newsourcepath, fullbasename)) | |
if __name__ == '__main__': | |
checker() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Процедура РазложитьПоПапкамСогласноИерархииМетаданных(ПутьРаспаковки, ДеревоОбъектов, ПутьКСохранению)
КонецПроцедуры