Subversion Repositories SmartDukaan

Rev

Rev 1504 | Rev 4090 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1504 Rev 4014
Line 13... Line 13...
13
from shop2020.logistics.service.impl.DataService import Provider,\
13
from shop2020.logistics.service.impl.DataService import Provider,\
14
    DestinationProviderAllocation
14
    DestinationProviderAllocation
15
from shop2020.thriftpy.logistics.ttypes import WarehouseLocation,\
15
from shop2020.thriftpy.logistics.ttypes import WarehouseLocation,\
16
    LogisticsServiceException
16
    LogisticsServiceException
17
 
17
 
18
def load_providers(filename, sheet_no):
18
def load_providers(filename, sheet_no, db_hostname):
19
    DataService.initialize('logistics')
19
    DataService.initialize(dbname='logistics', db_hostname=db_hostname)
20
 
20
 
21
    workbook = xlrd.open_workbook(filename)
21
    workbook = xlrd.open_workbook(filename)
22
    sheet = workbook.sheet_by_index(sheet_no)
22
    sheet = workbook.sheet_by_index(sheet_no)
23
    num_rows = sheet.nrows
23
    num_rows = sheet.nrows
24
    providers = Provider.query.all()
24
    providers = Provider.query.all()
Line 54... Line 54...
54
    parser = optparse.OptionParser()
54
    parser = optparse.OptionParser()
55
    parser.add_option("-f", "--file", dest="filename",
55
    parser.add_option("-f", "--file", dest="filename",
56
                   default="DestinationProviderAllocation.xls", type="string",
56
                   default="DestinationProviderAllocation.xls", type="string",
57
                   help="Read the providers list for different destinations and warehouse locations from FILE",
57
                   help="Read the providers list for different destinations and warehouse locations from FILE",
58
                   metavar="FILE")
58
                   metavar="FILE")
-
 
59
    parser.add_option("-H", "--host", dest="hostname",
-
 
60
                  default="localhost",
-
 
61
                  type="string", help="The HOST where the DB server is running",
-
 
62
                  metavar="HOST")
59
    (options, args) = parser.parse_args()
63
    (options, args) = parser.parse_args()
60
    if len(args) != 0:
64
    if len(args) != 0:
61
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
65
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
62
    filename = options.filename
66
    filename = options.filename
63
    if filename is None:
67
    if filename is None:
64
        parser.error("A filename must be provided. Use -h for more details.")
68
        parser.error("A filename must be provided. Use -h for more details.")
65
    load_providers(filename, 0)
69
    load_providers(filename, 0, options.hostname)
66
    load_providers(filename, 1)
70
    load_providers(filename, 1, options.hostname)
67
 
71
 
68
if __name__ == '__main__':
72
if __name__ == '__main__':
69
    main()
73
    main()
70
74