add revert files json
This commit is contained in:
parent
0eab1d885b
commit
d1b6e8048a
@ -107,13 +107,13 @@ def importUrl(name_thread, max_thread, canalblog, logger, parser, wordpress, bas
|
||||
del importWp
|
||||
|
||||
|
||||
def importDirectory(name_thread, max_thread, directory, logger, parser, wordpress, basic, serial, ssl_wordpress, create, update, image):
|
||||
def importDirectory(name_thread, max_thread, directory, logger, parser, wordpress, basic, serial, ssl_wordpress, create, update, image, tmp, revert):
|
||||
name = "Thread-{0}".format(int(name_thread) + 1)
|
||||
directory = directory.split(",")
|
||||
wordpress = wordpress.split(",")
|
||||
if serial is False:
|
||||
for i in wordpress:
|
||||
importWp = WPimport(name=name, basic=basic, wordpress=i, logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image)
|
||||
importWp = WPimport(name=name, basic=basic, wordpress=i, logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, tmp=tmp, revert=revert)
|
||||
for j in directory:
|
||||
importWp.fromDirectory(j, name_thread, max_thread)
|
||||
del importWp
|
||||
@ -123,7 +123,7 @@ def importDirectory(name_thread, max_thread, directory, logger, parser, wordpres
|
||||
logger.error("{0} : Error : Number directory is differant than wordpress".format(name))
|
||||
exit(1)
|
||||
for i in range(0, len(wordpress)-1):
|
||||
importWp = WPimport(name=name, basic=basic, wordpress=wordpress[i], logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image)
|
||||
importWp = WPimport(name=name, basic=basic, wordpress=wordpress[i], logger=logger, parser=parser, ssl_wordpress=ssl_wordpress, no_create=create, no_update=update, no_image=image, tmp=tmp, revert=revert)
|
||||
importWp.fromDirectory(directory[i])
|
||||
del importWp
|
||||
|
||||
@ -252,7 +252,7 @@ if __name__ == '__main__':
|
||||
wait_for = [ ex.submit(remove, i, args.parallel, args, basic, logger, ssl_wordpress) for i in range(0, int(args.parallel)) ]
|
||||
wait(wait_for, return_when=ALL_COMPLETED)
|
||||
wait_for = [
|
||||
ex.submit(importDirectory, i, int(args.parallel), args.directory, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, args.create, args.update, args.image)
|
||||
ex.submit(importDirectory, i, int(args.parallel), args.directory, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, args.create, args.update, args.image, TMP, revert)
|
||||
for i in range(0, int(args.parallel))
|
||||
]
|
||||
except Exception as err:
|
||||
|
@ -8,7 +8,7 @@ from requests.packages.urllib3.util.retry import Retry
|
||||
|
||||
class WPimport:
|
||||
# Constructor
|
||||
def __init__(self, name="Thread-0", basic=None, wordpress="", logger=None, parser="html.parser", ssl_wordpress=True, no_create=False, no_update=False, no_image=False, tmp="/tmp/import_export_canablog"):
|
||||
def __init__(self, name="Thread-0", basic=None, wordpress="", logger=None, parser="html.parser", ssl_wordpress=True, no_create=False, no_update=False, no_image=False, tmp="/tmp/import_export_canablog", revert=False):
|
||||
self._name = name
|
||||
self._basic = basic
|
||||
self._wordpress = wordpress
|
||||
@ -29,6 +29,7 @@ class WPimport:
|
||||
self._no_update = no_update
|
||||
self._no_image = no_image
|
||||
self._tmp = tmp
|
||||
self._revert = revert
|
||||
|
||||
# Destructor
|
||||
def __del__(self):
|
||||
@ -75,14 +76,23 @@ class WPimport:
|
||||
|
||||
|
||||
def fromDirectory(self, directory="", number_thread=1, max_thread=1):
|
||||
self._directory = directory
|
||||
directory = "{0}/archives".format(directory)
|
||||
directories = self._getDirectories([], "{0}".format(directory))
|
||||
if len(directories) > 0:
|
||||
files = self._getFiles(directories)
|
||||
self.fromFile(files, number_thread, max_thread)
|
||||
if self._revert:
|
||||
self._directory = directory
|
||||
directory = "{0}/archives".format(directory)
|
||||
directories = self._getDirectories([], "{0}".format(directory))
|
||||
if len(directories) > 0:
|
||||
files = self._getFiles(directories)
|
||||
self.fromFile(files, number_thread, max_thread)
|
||||
else:
|
||||
self._logger.error("{0} : No files for {1}".format(self._name, directory))
|
||||
else:
|
||||
self._logger.error("{0} : No files for {1}".format(self._name, directory))
|
||||
try:
|
||||
files = open("{0}/{1}.json".format(self._name, self._tmp))
|
||||
self.fromFile(files, number_thread, max_thread)
|
||||
except Exception as ex:
|
||||
self._logger.error("{0} : Read file json from tmp : {1}".format(self._name, ex))
|
||||
|
||||
|
||||
|
||||
|
||||
def fromFile(self, files=[], number_thread=1, max_thread=1):
|
||||
|
Loading…
x
Reference in New Issue
Block a user