forked from mchobby/PrestaConsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachefile-update.py
executable file
·74 lines (59 loc) · 2.38 KB
/
cachefile-update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
"""update-cachefile.py
Copyright 2015 DMeurisse <info@mchobby.be>
Presta Shop Cache File refresher AND interactive testing - Version alpha
Just load the information from the the WebShop and save it to the
cache file (on request).
To use it in interactive mode do the following:
1) start python in interactive mode
2) run the following command (refesh the data as necessary):
3) execfile( 'cachefile-update.py' )
4) You can now inspect the cachedHelper and its data
dir( cachedHelper )
for state in cachedHelper.orderstates:
print ( 'id, name = %i, %s' % (state.id, state.name )
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
"""
from prestaapi import PrestaHelper, CachedPrestaHelper, OrderStateList
from config import Config
import logging
import time
import math
config = Config()
logging.basicConfig( filename=config.logfile, level=logging.DEBUG,
format='%(asctime)s - [%(levelname)s] %(message)s',
datefmt='%d/%m/%y %H:%M:%S.%f' )
cachedHelper = None
def main():
global cachedHelper
""" Simply create the global reference cachedHelper. Useful for
interfactive debugging """
# just create the needed object
logging.info( 'create cachedHelper object' )
cachedHelper = CachedPrestaHelper( config.presta_api_url, config.presta_api_key, debug = False )
value = raw_input( 'Rafraichir le cache (y/n)' )
if value == 'y':
logging.info( 'Force cache refreshing from WebShop' )
cachedHelper.load_from_webshop()
logging.info( 'Saving cache file' )
cachedHelper.save_cache_file()
logging.info( 'file saved' )
else:
logging.info( 'Data not refreshed from the WebShop' )
if __name__ == '__main__':
logging.info( 'cachefile-update Started' )
main()
logging.info( 'cachefile-update End' )