Subversion Repositories SmartDukaan

Rev

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

Rev 1433 Rev 4014
Line 11... Line 11...
11
 
11
 
12
from shop2020.logistics.service.impl import DataService
12
from shop2020.logistics.service.impl import DataService
13
from shop2020.logistics.service.impl.DataService import WarehouseAllocation
13
from shop2020.logistics.service.impl.DataService import WarehouseAllocation
14
from shop2020.thriftpy.logistics.ttypes import WarehouseLocation
14
from shop2020.thriftpy.logistics.ttypes import WarehouseLocation
15
 
15
 
16
def load_warehouse_allocations(filename):
16
def load_warehouse_allocations(filename, db_hostname):
17
    DataService.initialize('logistics')
17
    DataService.initialize(dbname='logistics', db_hostname=db_hostname)
18
    workbook = xlrd.open_workbook(filename)
18
    workbook = xlrd.open_workbook(filename)
19
    sheet = workbook.sheet_by_index(0)
19
    sheet = workbook.sheet_by_index(0)
20
    num_rows = sheet.nrows
20
    num_rows = sheet.nrows
21
    for rownum in range(1, num_rows):
21
    for rownum in range(1, num_rows):
22
        pincode, warehouse_loc = sheet.row_values(rownum)[0:2]
22
        pincode, warehouse_loc = sheet.row_values(rownum)[0:2]
Line 33... Line 33...
33
def main():
33
def main():
34
    parser = optparse.OptionParser()
34
    parser = optparse.OptionParser()
35
    parser.add_option("-f", "--file", dest="filename",
35
    parser.add_option("-f", "--file", dest="filename",
36
                   type="string", help="Read the serviceable location list from FILE",
36
                   type="string", help="Read the serviceable location list from FILE",
37
                   metavar="FILE")
37
                   metavar="FILE")
-
 
38
    parser.add_option("-H", "--host", dest="hostname",
-
 
39
                  default="localhost",
-
 
40
                  type="string", help="The HOST where the DB server is running",
-
 
41
                  metavar="HOST")
38
    (options, args) = parser.parse_args()
42
    (options, args) = parser.parse_args()
39
    if len(args) != 0:
43
    if len(args) != 0:
40
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
44
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
41
    filename = options.filename
45
    filename = options.filename
42
    if filename is None:
46
    if filename is None:
43
        parser.error("A filename must be provided. Use -h for more details.")
47
        parser.error("A filename must be provided. Use -h for more details.")
44
    load_warehouse_allocations(filename)
48
    load_warehouse_allocations(filename, options.hostname)
45
 
49
 
46
if __name__ == '__main__':
50
if __name__ == '__main__':
47
    main()
51
    main()
48
52