Python log 模块,debug() 实例源码

我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用log.debug()

项目:community-plugins    作者:makehumancommunity    | 项目源码 | 文件源码
def refreshButtonClick(self):

        self.progress = Progress()
        self.progress(0.0,0.1)

        web = urllib2.urlopen("http://www.makehumancommunity.org/sites/default/files/assets.json");
        jsonstring = web.read()
        assetJson = json.loads(jsonstring)

        increment = 0.8 / len(assetJson.keys())
        current = 0.1

        log.debug("Finished downloading json file")

        for key in assetJson.keys():
            current = current + increment
            self.progress(current,current + increment)
            self.setupOneAsset(assetJson[key])

        with open(os.path.join(self.root,"assets.json"),"w") as f:
            f.write(jsonstring)

        self.loadAssetsFromJson(assetJson)

        self.progress(1.0)
项目:community-plugins    作者:makehumancommunity    | 项目源码 | 文件源码
def setupOneAsset(self, jsonHash):

        assetDir = os.path.join(self.root,str(jsonHash["nid"]))
        if not os.path.exists(assetDir):
            os.makedirs(assetDir)
        if "files" in jsonHash.keys():
            files = jsonHash["files"]
            if "render" in files.keys():
                #fn = os.path.join(assetDir,"screenshot.png")
                fn = self.getScreenshotPath(jsonHash)
                if not os.path.exists(fn):                    
                    #log.debug("Downloading " + files["render"])
                    self.downloadUrl(files["render"],fn)
                else:
                    log.debug("Screenshot already existed")

            if "thumb" in files.keys():
                fn = os.path.join(assetDir,"thumb.png")
                if not os.path.exists(fn):                    
                    log.debug("Downloading " + files["thumb"])
                    self.downloadUrl(files["thumb"],fn)
                else:
                    log.debug("thumb already existed")
项目:wechat    作者:tianyongchina    | 项目源码 | 文件源码
def __init__(self):
        self.__libmsc = ctypes.CDLL("./clibs/libmsc.so")
        self.__flag = True
        #answer/text
        self.__list1 = ['baike', 'calc', 'datetime', 'faq', 'openQA', 'chat']
        #text
        self.__list2 = ['weather']
        #
        self.__list3 = ['app', 'cookbook', 'flight', 'hotel', 'map', 'music', 'radio', 'restuarant', \
                        'schedule', 'stock', 'train', 'translation', 'tv', 'video', 'websearch', \
                        'website', 'weibo', 'flower', 'gift']
        #????
        ret = self.__libmsc.MSPLogin(None, None, c_char_p("appid = appidtest"))
        if (0 != ret):
            #print ("MSPLogin failed , Error code %d"%(ret))
            log.debug("MSPLogin failed , Error code %d"%(ret))
            self.__flag = False
项目:wechat    作者:tianyongchina    | 项目源码 | 文件源码
def sch_text(self, data):
        if(not self.__flag):
            return None 
        __msp_search = self.__libmsc.MSPSearch
        __msp_search.restype = c_char_p

        _data = create_string_buffer(data)
        _data_len = sizeof(_data)
        _len_point = pointer(c_uint(_data_len))
        _ret_p = pointer(c_int(0))

        rec_txt = __msp_search("nlp_version=2.0", _data, _len_point, _ret_p)
        if _ret_p.contents:
            #print ("MSPLogin failed , Error code %s"%(_ret_p.contents))
            log.warning("MSPLogin failed , Error code %s"%(_ret_p.contents))
            return None
        #print ("iflytek search api result: %s"%(rec_txt)) 
        log.debug("iflytek search api result: %s"%(rec_txt))
        return self.__deal_data(rec_txt)
项目:INCWO_auto_synchr    作者:vaelastrazs    | 项目源码 | 文件源码
def prepare_xml_product(product_infos):
    xml_data="<customer_product>\
            <is_active>1</is_active>\
            <is_from_vendor>0</is_from_vendor>\
            <currency_id>58</currency_id>\
            <vat_id>607</vat_id>\
            <activity_classification_choice>commerce</activity_classification_choice>\
            <type_of_product_id>20004</type_of_product_id>"

    for tag, value in product_infos.iteritems():
        if tag in INCWO_PARAMS:
            xml_data+="<"+tag+">"+str(value).replace("& ","&amp; ")+"</"+tag+">"
            # log.debug("xml info of product : tag {}, value {} ".format(tag, value))
    xml_data+="</customer_product>"

    return xml_data
项目:BiblioPixel2    作者:ManiacalLabs    | 项目源码 | 文件源码
def run(self):
        log.debug("Starting thread...")
        self._anim._run(**self._args)
        log.debug("Thread Complete")
项目:community-plugins    作者:makehumancommunity    | 项目源码 | 文件源码
def _onChange(self):
        log.debug("onChange")
        if self.onChangeMethod:
            self.onChangeMethod(self.getCurrentItem())
项目:community-plugins    作者:makehumancommunity    | 项目源码 | 文件源码
def comboChange(self,item = None):
        log.debug("comboChange")
项目:community-plugins    作者:makehumancommunity    | 项目源码 | 文件源码
def getScreenshotPath(self,asset):
        if not asset:
            return None
        if not "files" in asset:
            return None

        files = asset["files"]

        r = None

        if "render" in files:
            r = files["render"]
        else:
            if "illustration" in files:
                r = files["illustration"]

        if not r:
            return None

        fn = r.rsplit('/', 1)[-1]

        if not fn:
            return None

        extension = os.path.splitext(fn)[1]

        if not extension:
            return None

        extension = extension.lower()

        filename = "screenshot" + extension
        assetDir = os.path.join(self.root,str(asset["nid"]))
        fullPath = mhapi.locations.getUnicodeAbsPath(os.path.join(assetDir,filename))

        log.debug("Screenshot path: " + fullPath)

        return fullPath
项目:community-plugins    作者:makehumancommunity    | 项目源码 | 文件源码
def onCategoryChange(self,item = None):
        assetType = str(self.typeList.getCurrentItem())
        log.debug("onCategoryChange() " + assetType)

        if assetType == "Clothes":            
            category = str(self.categoryList.getCurrentItem())
            if category == '' or not category:
                category = "All"
            self.assetList.setData(sorted(self.clothesNames[category]))
            self.screenshot.setPixmap(QtGui.QPixmap(os.path.abspath(self.notfound)))
            self.thumbnail.setPixmap(QtGui.QPixmap(os.path.abspath(self.notfound)))
            self.assetInfoText.setText("Nothing selected")
项目:community-plugins    作者:makehumancommunity    | 项目源码 | 文件源码
def downloadButtonClick(self):      
        assetType = str(self.typeList.getCurrentItem())

        log.debug("Download: " + assetType)

        if assetType == "Target":
            self.downloadTarget()
        if assetType == "Skin":
            self.downloadSkin()
        if assetType == "Clothes":
            self.downloadClothes()
        if assetType == "Hair":
            self.downloadHair()
        if assetType == "Pose":
            self.downloadPose()
        if assetType == "Proxy":
            self.downloadProxy()
        if assetType == "Material":
            self.downloadMaterial()
        if assetType == "Rig":
            self.downloadRig()
        if assetType == "Model":
            self.downloadModel()
        if assetType == "Teeth":
            self.downloadTeeth()
        if assetType == "Eyebrows":
            self.downloadEyebrows()
        if assetType == "Eyelashes":
            self.downloadEyelashes()
项目:community-plugins    作者:makehumancommunity    | 项目源码 | 文件源码
def downloadUrl(self, url, saveAs=None, asset=None, fileName=None):
        try:
            url = re.sub(r"\s","%20",url)
            data = urllib2.urlopen(url).read()
            newData = self.normalizeFiles(data,asset,saveAs,fileName)
            with open(saveAs,"wb") as f:
                f.write(newData)                
        except:
            log.debug("failed to write file")
            return False    
        return True
项目:flask-skeleton    作者:axiaoxin    | 项目源码 | 文件源码
def register_decorators_on_module_funcs(modules, decorators):
    '''?decorator?????module??????
    ?????__nodeco__???False???????????
    ???????????
    eg:
        def func():
            pass
        func.__nodeco__ = True
    '''
    if not isinstance(modules, (list, tuple)):
        modules = [modules]
    if not isinstance(decorators, (list, tuple)):
        decorators = [decorators]
    for m in modules:
        for funcname, func in vars(m).iteritems():
            if (isinstance(func, types.FunctionType)
                    and not funcname.startswith('_')
                    and func.__module__ == m.__name__):
                if getattr(func, '__nodeco__', False):
                    continue
                for deco in decorators:
                    if settings.DEBUG:
                        log.debug('register %s on %s.%s'
                                  % (deco.__name__, m.__name__, funcname))
                    func = deco(func)
                    vars(m)[funcname] = func
项目:Python-IRC-Bot    作者:wolfy1339    | 项目源码 | 文件源码
def on_all(self, event, irc, arguments):
        if event.raw.find("%") == -1:
            log.debug(event.raw)
项目:Python-IRC-Bot    作者:wolfy1339    | 项目源码 | 文件源码
def on_send(data):
        if data.find("%") == -1:
            log.debug(data)
项目:python-htspclient    作者:tvheadend    | 项目源码 | 文件源码
def send(self, func, args={}):
        args['method'] = func
        if self._user: args['username'] = self._user
        if self._pass: args['digest'] = htsmsg.HMFBin(self._pass)
        log.debug('htsp tx:')
        log.debug(args, pretty=True)
        self._sock.send(htsmsg.serialize(args))

    # Receive
项目:python-htspclient    作者:tvheadend    | 项目源码 | 文件源码
def recv(self):
        ret = htsmsg.deserialize(self._sock, False)
        log.debug('htsp rx:')
        log.debug(ret, pretty=True)
        return ret

    # Setup
项目:wechat    作者:tianyongchina    | 项目源码 | 文件源码
def get(self):
        try:
            webData = self.request.body
            #print "Handle Get webdata is ", webData
            log.debug("Handle Get webdata is %s" % (webData))

            signature = self.get_argument('signature', '')
            timestamp = self.get_argument('timestamp', '')
            nonce = self.get_argument('nonce', '')
            echostr = self.get_argument('echostr', '')
            token = test_weixin_token

            if len(signature) == 0 or len(timestamp) == 0 or \
                    len(nonce) == 0 or len(echostr) == 0:
                        self.write('')

            list = [token, timestamp, nonce]
            list.sort()
            sha1 = hashlib.sha1()
            map(sha1.update, list)
            hashcode = sha1.hexdigest()
            #print "handle/GET func: hashcode, signature: ", hashcode, signature
            log.debug("handle/GET func: hashcode, signature: %s, %s"%(hashcode, signature))
            if hashcode == signature:
                self.write(echostr)
            else:
                self.write('')
        except Exception, Argument:
            log.error(Argument)
            self.write(Argument)
项目:wechat    作者:tianyongchina    | 项目源码 | 文件源码
def cb_proc_weixin_text(self, toUser, fromUser, content):
        replyMsg = reply.TextMsg(toUser, fromUser, content)
        #print "Handle post reply data is ", replyMsg.send()
        log.debug("Handle post reply data is %s"%(replyMsg.send()))
        self.write(replyMsg.send())
        self.finish()
项目:wechat    作者:tianyongchina    | 项目源码 | 文件源码
def DebugPrint(msg):
    log.debug(msg)
    #print msg
项目:wechat    作者:tianyongchina    | 项目源码 | 文件源码
def like_cron():
    #print datetime.datetime.now()
    log.debug(datetime.datetime.now())
项目:wechat    作者:tianyongchina    | 项目源码 | 文件源码
def get_access_token(self):
        params = {}
        params['client_id'] = self.__app_key
        params['grant_type'] = "client_credentials"
        params['device_id']= self.__device_id
        params['timestamp'] = long(time.time() * 1000)
        tmp_num = float(str(params['timestamp'])[8:])
        params['nonce'] = str(tmp_num * tmp_num)
        data = self.__sig_calc(params)

        body = data[1]
        tmp_url = self.__access_token_url
        """
        resp = urllib.urlopen(tmp_url, body).read()
        res = json.loads(resp)
        """
        res = self.http_post(tmp_url, body, 'application/x-www-form-urlencoded')
        if res is None:
            return
        #print ("==>>> get_access_token_resp:%s"%(res))
        log.debug("get_access_token response:%s"%(res))
        if not res.has_key('error_no'):
            self.__access_token = res['access_token']
            self.__expires_in = res['expires_in']
        else:
            self.__access_token = ''
            self.__expires_in = 0
项目:wechat    作者:tianyongchina    | 项目源码 | 文件源码
def get_sound_by_album_id(self, os_type, pack_id, id, count = 20, sort = "asc", page = 1):
        recommendation = {'code': 0}
        res = self.album_browse(os_type, pack_id, id, count, sort, page)
        if (res is not None) and res.has_key('tracks'):
            recommendation['recommendation'] = []
            track_list = res['tracks']
            for track in track_list:
                recommendation['recommendation'].append(self.__set_recommendation(track))
        else:
            recommendation = {'code': -1}
            recommendation['error'] = 'no data'
        #log.debug(json.dumps(recommendation, ensure_ascii = False).encode('utf-8'))
        print json.dumps(recommendation, ensure_ascii = False).encode('utf-8')
        return json.dumps(recommendation, ensure_ascii = False).encode('utf-8')
项目:INCWO_auto_synchr    作者:vaelastrazs    | 项目源码 | 文件源码
def create_product(product_infos):
    xml_data = prepare_xml_product(product_infos)
    url="https://www.incwo.com/"+str(ID_USER)+"/customer_products.xml"
    # print("sending create (POST request) to ",url," ...")
    response = send_request("post", url, xml_data)
    product_id = 0
    for l in response.splitlines():
        if "<id>" in l:
            product_id = extract_value_from_xml(l)
            print("product "+product_infos["name"]+" created with id "+product_id)
            # log.debug(response)
            break
    if (product_id != 0):
        manage_stock_movement(product_infos, product_id, None)
项目:INCWO_auto_synchr    作者:vaelastrazs    | 项目源码 | 文件源码
def update_product(fournisseur_product_infos, incwo_product_infos):
    update_infos = {}
    try:
        PRODUCT_ID = incwo_product_infos["id"]
        PRODUCT_REF = fournisseur_product_infos["reference"]
    except KeyError:
        log.error("Incwo product with no ID or ref associated")
        raise ValueError()
    try:
        # Si produit considere comme vitrine : on annule la comparaison prix et category en mettant les champs aux memes valeurs
        if not compareValues(incwo_product_infos["product_category_id"],VITRINE_CATEGORY_ID):
            log.warning("Pas de mise a jour du prix du produit {} (Produit categorisé comme en vitrine)".format(PRODUCT_REF))
            incwo_product_infos["product_category_id"] = fournisseur_product_infos["product_category_id"]
            fournisseur_product_infos["price"] = incwo_product_infos["price"]
    except KeyError:
        log.error("Incwo product with no category_ID associated")
        raise ValueError()

    for key in INCWO_PARAMS:
        if not key in fournisseur_product_infos:
            log.error("Product "+fournisseur_product_infos["name"]+" : fournisseur info incomplete! Missing "+key)
            raise ValueError()
        elif not key in incwo_product_infos:
            if key != 'barcode':
                log.debug("incwo info incomplete, updating "+key)
                update_infos[key]=fournisseur_product_infos[key]
        elif (compareValues(fournisseur_product_infos[key],incwo_product_infos[key])):
            log.debug("incwo info outdated, updating {}".format(key))
            log.debug("Picata {} ; incwo_product_infos {}".format(fournisseur_product_infos[key], incwo_product_infos[key]))
            update_infos[key]=fournisseur_product_infos[key]

    if len(update_infos) > 0 :
        log.debug("Update needed for product "+str(PRODUCT_ID))
        xml = prepare_xml_product(update_infos)
        url = "https://www.incwo.com/"+str(ID_USER)+"/customer_products/"+str(PRODUCT_ID)+".xml";
        send_request('put', url, xml)
    # else :
    #     log.debug("Product {} (id {}) infos up to date".format(fournisseur_product_infos["name"],PRODUCT_ID))

    manage_stock_movement(fournisseur_product_infos, PRODUCT_ID, incwo_product_infos["product_category_id"])
项目:INCWO_auto_synchr    作者:vaelastrazs    | 项目源码 | 文件源码
def change_stock_value(warehouse_id, quantity, product_id, direction):
    xml_move = prepare_xml_stock_movement(warehouse_id, quantity, product_id,direction)
    url="https://www.incwo.com/"+str(ID_USER)+"/stock_movements.xml"
    r = send_request("post", url, xml_move)
    log.debug(r)
项目:community-plugins    作者:makehumancommunity    | 项目源码 | 文件源码
def onTypeChange(self,item = None):
        assetType = str(item)
        log.debug("onTypeChange: " + assetType)

        if assetType == "Clothes":
            cats = sorted(self.clothesAssets.keys())
            self.categoryList.setData(cats)
            self.assetList.setData(sorted(self.clothesNames["All"]))
        else:
            self.categoryList.setData(["All"])
            self.categoryList.setCurrentRow(0)

            assets = []

            if assetType == "Target":
                assets = self.targetNames
            if assetType == "Hair":
                assets = self.hairNames
            if assetType == "Proxy":
                assets = self.proxyNames
            if assetType == "Skin":
                assets = self.skinNames
            if assetType == "Pose":
                assets = self.poseNames
            if assetType == "Material":
                assets = self.materialNames
            if assetType == "Rig":
                assets = self.rigNames
            if assetType == "Model":
                assets = self.modelNames
            if assetType == "Teeth":
                assets = self.teethNames
            if assetType == "Eyebrows":
                assets = self.eyebrowsNames
            if assetType == "Eyelashes":
                assets = self.eyelashesNames

            self.assetList.setData(sorted(assets))

        self.categoryList.setCurrentItem("All")

        self.screenshot.setPixmap(QtGui.QPixmap(os.path.abspath(self.notfound)))
        self.thumbnail.setPixmap(QtGui.QPixmap(os.path.abspath(self.notfound)))
        self.assetInfoText.setText("Nothing selected")
项目:community-plugins    作者:makehumancommunity    | 项目源码 | 文件源码
def setDescription(self,asset):
        desc = "<big>" + asset["title"] + "</big><br />\n&nbsp;<br />\n"
        desc = desc + "<b><tt>Author.........: </tt></b>" + asset["username"] + "<br />\n"

        if "license" in asset.keys():
            desc = desc + "<b><tt>License........: </tt></b>" + asset["license"] + "<br />\n"
        if "compatibility" in asset.keys():
            desc = desc + "<b><tt>Compatibility..: </tt></b>" + asset["compatibility"] + "<br />\n"


        key = None

        if asset["type"] == "clothes":
            key = "mhclo"
        if asset["type"] == "hair":
            key = "mhclo"
        if asset["type"] == "teeth":
            key = "mhmat"
        if asset["type"] == "eyebrows":
            key = "mhmat"
        if asset["type"] == "eyelashes":
            key = "mhmat"
        if asset["type"] == "skin":
            key = "mhmat"
        if asset["type"] == "target":
            key = "file"
        if asset["type"] == "proxy":
            key = "file"
        if asset["type"] == "target":
            key = "file"
        if asset["type"] == "material":
            key = "mhmat"
        if asset["type"] == "rig":
            key = "file"
        if asset["type"] == "model":
            key = "file"


        if key:
            url = asset["files"][key]
            fn = url.rsplit('/', 1)[-1]
            fn = fn.replace("." + key,"")
            fn = fn.replace("_"," ")            
            desc = desc + "<b><tt>Name in MH.....: </tt></b>" + fn + "<br />\n"

        self.assetInfoText.setText(desc)
        self.assetDescription.setText(asset["description"])
        #debug.log(desc + asset["description"])
项目:wechat    作者:tianyongchina    | 项目源码 | 文件源码
def get(self):
        '''
        the import handle
        '''
        try:
            webData = self.request.body
            #print "WxShowHandler Get webdata is ", webData
            log.info("WxShowHandler Get webdata is %s" % (webData))

            id = self.get_argument('id', '')
            showidstr = self.get_argument('showid', '')
            if len(id) == 0 or len(showidstr) == 0:
                self.write('parameter error!')

            # get sign ticket for weixin jsapisdk
            ticket = DataCenter().get_jsapi_ticket()
            urlall = self.request.uri
            #print self.request.path        /wx/show
            #print self.request.uri         /wx/show?id=oLN9QxI-YpdNJkSIXQkppJDHuvZM&showid=15
            sign = Sign(ticket, test_urlhead + urlall)
            sign_data = sign.sign()
            #print 'weixin_JSAPI_ticket: '
            #print sign_data
            log.info('weixin_JSAPI_ticket: %s'%(sign_data))
            timestamp = sign_data['timestamp']
            nonceStr = sign_data['nonceStr']
            signature = sign_data['signature']

            # get_param id
            showid = long(showidstr)
            userdata = DataCenter().get_data_by_id(showid)
            if len(userdata) == 0:
                self.write("no data")
                return
            data_dict = userdata[0]
            #print data_dict
            log.debug(data_dict)

            title_info = data_dict['title']
            sub_info = data_dict['aidata'].split(test_split_str)
            all_info = data_dict['originaldata'].split(test_split_str)
            createtime = data_dict['createtime'].strftime('%Y-%m-%d %H:%M:%S')

            author = ''
            authorinfo = data_dict['author']
            datasource = data_dict['datasource']
            _userid = data_dict['userid']
            if authorinfo == '':
                author = datasource
            elif datasource == '':
                author = authorinfo
            else :
                author = authorinfo + ' | ' + datasource

            self.render("index.html", title=title_info, allinfo=all_info, subjects=sub_info, author=author, \
                    createtime=createtime, appid=test_weixin_appid, timestamp=timestamp, nonceStr=nonceStr, \
                    userid=_userid, signature=signature)
        except Exception, Argument:
            log.error(Argument)
            self.write(Argument)
项目:wechat    作者:tianyongchina    | 项目源码 | 文件源码
def run_sql_proc(self, body, funcname):
        try:
            content = {'code': 0}
            if funcname == 'notread':
                if(body.has_key('userid')):
                    userid = body['userid']
                    res_list = DataCenter().get_not_read_id_from_xdata(userid)
                    list_dict = []
                    for i in range(len(res_list)):
                        tmp = {}
                        tmp['id'] = res_list[i]['id']
                        list_dict.append(tmp)
                    content['collections'] = list_dict
                else:
                    content['code'] = -1
                    content['error'] = 'userid is needed.'
            elif funcname == 'content':
                if (body.has_key('userid') and body.has_key('id')):
                    userid = body['userid']
                    id = body['id']
                    res_list = DataCenter().get_content_from_xdata(userid, id)
                    content['id'] = res_list[0]['id']
                    content['title'] = res_list[0]['title']
                    content['author'] = res_list[0]['author']
                    content['source'] = res_list[0]['datasource']
                    content['subject'] = res_list[0]['aidata'].split(lingx_split_str)
                    content['original'] = res_list[0]['originaldata'].split(lingx_split_str)

                    #??accesstime
                    #DataCenter().update_xdata(id, 'accesstime', datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

                else:
                    content['code'] = -1
                    content['error'] = 'userid and id are needed.'
            elif funcname == 'status':
                if (body.has_key('article_list')):
                    for item in body['article_list']:
                        #??accesstime
                        DataCenter().update_xdata(item['id'], 'accesstime', datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
                else:
                    content['code'] = -1
                    content['error'] = 'article_list is empty.'
            else:
                pass
            #print content
            log.debug(content)
            self.write(tornado.escape.json_encode(content))
            self.finish()
        except Exception, Argument:
            log.error(Argument)
            self.finish(Argument)
项目:INCWO_auto_synchr    作者:vaelastrazs    | 项目源码 | 文件源码
def manage_stock_movement(product_infos, product_id, cat_id_src):

    #  product_ref : reference sur produit (servira de nom de fichier contenant les stocks associe)
    product_ref = product_infos["reference"]
    #  cat_id_dest : id de la category du produit selon picata (la ou va etre stocke les infos de la synchro en cours)
    cat_id_dest = product_infos["product_category_id"]

    # creation de la variable stocks pour plus de lisibilité
    stocks = {}
    for tag, value in product_infos.iteritems():
        if tag in STOCK_PARAMS:
            stocks[ENTREPOTS_ID[tag]] = value
            # log.debug("Product {} : stock_id = {}, value = {}".format(product_infos["name"],ENTREPOTS_ID[tag], value))

    # Les stocks sont rangé par catégories pour des question de limite de nbrs de fichier
    filename_dest = "stock/"+cat_id_dest+"/"+product_ref+".txt"

    rs = []
    #Si le dossier n'existe pas, on le crée
    if not os.path.exists(os.path.dirname(filename_dest)):
        try:
            os.makedirs(os.path.dirname(filename_dest))
        except OSError as exc: # Guard against race condition
            if exc.errno != errno.EEXIST:
                raise

    if cat_id_src:
        filename_src = "stock/"+cat_id_src+"/"+product_ref+".txt"
        # Si le fichier existe, on lit les valeurs du stock precedent
        if (os.path.exists(filename_src)):
            with open(filename_src, 'r') as fp:
                datas = []
                for line in fp:            
                    difference = 0
                    data = line.split(":")
                    difference = int(stocks[data[0]]) - int(data[1])
                    if (difference > 0):
                        change_stock_value(data[0], difference, product_id, "1")
                    elif (difference < 0)  :
                        change_stock_value(data[0], abs(difference), product_id, "-1")
                    # else:
                    #     log.debug("Stock for product {} (id {}) up to date".format(product_infos["name"],product_id))

    # Sinon, crée les movement de stock correspondant
    else:
        for warehouse_id, quantity in stocks.iteritems():
            if (int(quantity) >= 0) :
                change_stock_value(warehouse_id, int(quantity), product_id, "1")
            else:
                change_stock_value(warehouse_id, abs(int(quantity)), product_id, "-1")


    # Dans tout les cas, on (re)ecrit le fichier avec les nouvelles valeurs
    with open(filename_dest, 'w') as fp:
        for warehouse_id, quantity in stocks.iteritems():
            fp.write(warehouse_id+":"+quantity+"\n")
        fp.close()