Product Config

Product Configure


In [49]:
import os
import configparser
import getpass

In [50]:
config = configparser.RawConfigParser()

In [51]:
osuser = getpass.getuser()

In [51]:


In [51]:


In [52]:
osuser


Out[52]:
'wcmckee'

In [53]:
homdir = ('/home/' + osuser + '/sellcoffee/')

In [54]:
homdir


Out[54]:
'/home/wcmckee/sellcoffee/'

In [55]:
confighdir = homdir + ('config.cfg')

In [56]:
confighdir


Out[56]:
'/home/wcmckee/sellcoffee/config.cfg'

In [57]:
config.read(confighdir)


Out[57]:
['/home/wcmckee/sellcoffee/config.cfg']

In [58]:
#config.add_section

In [59]:
prodirz = ('/home/wcmckee/sellcoffee/products/')

In [60]:
#Each shopper has a username, inside that username is a product
#list.

In [61]:
prodos = os.listdir(prodirz)

In [62]:
prodos
#Create .cfg file for each item in list.

#Create one .cfg file that contains each product section,
#id, price, etc are in each product section.


Out[62]:
['debian', 'portrait', 'hat']

In [63]:
for prod in prodos:
    #print prod
    #print os.listdir(prodirz + prod)
    
    prodop = open(prodirz + prod + '/' + prod + '-id', 'r')
    print prodop.read()
    prodop.close()


1000
1001
1002

In [63]:
#id isnt being written to config file. sort it out.

In [68]:
for prod in prodos:
    print prod
    config.add_section(prod)
    prodop = open(prodirz + prod + '/' + prod + '-id', 'r')
    prodread = prodop.read()
    config.set(prod, 'id', prodread)
    #print prodop.read()
    prodop.close()


debian
---------------------------------------------------------------------------
DuplicateSectionError                     Traceback (most recent call last)
<ipython-input-68-20bba71aad4c> in <module>()
      1 for prod in prodos:
      2     print prod
----> 3     config.add_section(prod)
      4     prodop = open(prodirz + prod + '/' + prod + '-id', 'r')
      5     prodread = prodop.read()

/usr/lib/python2.7/dist-packages/configparser.pyc in add_section(self, section)
    669 
    670         if section in self._sections:
--> 671             raise DuplicateSectionError(section)
    672         self._sections[section] = self._dict()
    673         self._proxies[section] = SectionProxy(self, section)

DuplicateSectionError: Section 'debian' already exists

In [69]:
with open(confighdir, 'wb') as configfile:
    config.write(configfile)

In [67]:


In [ ]: