def listRepo(repo, orderby=None):
    """
    listRepo(repo): Get list of all APKs in a specific store from the Aptoide API
                    and return it in JSON form
    """
    file_name = '{0}{1}.json'.format(repo, '' if not orderby else '-' + '-'.join(orderby))
    orderby   = '' if not orderby else '/orderby/' + '/'.join(orderby)
    url       = 'http://webservices.aptoide.com/webservices/listRepository/{0}{1}/json'.format(repo, orderby)
    data      = Debug.readFromFile(file_name)

    try:
        if data == '':
            session = requests.Session()
            # session.proxies = Debug.getProxy()
            logging.debug('Requesting1: ' + url)
            resp    = session.get(url)
            data    = json.loads(resp.text)
            Debug.writeToFile(file_name, json.dumps(data, sort_keys=True,
                              indent=4, separators=(',', ': ')), resp.encoding)

        if data['status'] == 'OK':
            return data
        else:
            logging.error(file_name)
    except:
        logging.exception('!!! Invalid JSON from: "{0}"'.format(url))

    return None
Beispiel #2
0
 def set(cls, key, value, type='string'):
     Debug.dprint(text=key)
     Debug.dprint(text=value)
     if type == 'string':
         redis_instance.set(key, value)
     elif type == 'list' or type == 'dic':
         redis_instance.set(key, json.dumps(value))
Beispiel #3
0
    def RunCmd(self, command, compReg = True, switchPage = False,
               onDone = None):
        """!Run command typed into console command prompt (GPrompt).
        
        @todo Display commands (*.d) are captured and processed
        separately by mapdisp.py. Display commands are rendered in map
        display widget that currently has the focus (as indicted by
        mdidx).
        
        @param command command given as a list (produced e.g. by utils.split())
        @param compReg True use computation region
        @param switchPage switch to output page
        @param onDone function to be called when command is finished

        @return 0 on success
        @return 1 on failure
        """
        if len(command) == 0:
            Debug.msg(2, "GPrompt:RunCmd(): empty command")
            return 0
        
        # update history file
        env = grass.gisenv()
        try:
            fileHistory = codecs.open(os.path.join(env['GISDBASE'],
                                                   env['LOCATION_NAME'],
                                                   env['MAPSET'],
                                                   '.bash_history'),
                                      encoding = 'utf-8', mode = 'a')
        except IOError, e:
            self.WriteError(e)
            fileHistory = None
Beispiel #4
0
 def AddOverlay(self, id, type, command,
                l_active = True, l_hidden = True, l_opacity = 1.0, l_render = False):
     """!Adds overlay (grid, barscale, legend, etc.) to list of
     overlays
     
     @param id overlay id (PseudoDC)
     @param type overlay type (barscale, legend)
     @param command GRASS command to render overlay
     @param l_active overlay activated (True) or disabled (False)
     @param l_hidden overlay is not shown in layer tree (if True)
     @param l_render render an image (if True)
     
     @return new layer on success
     @retutn None on failure
     """
     Debug.msg (2, "Map.AddOverlay(): cmd=%s, render=%d" % (command, l_render))
     overlay = Overlay(id = id, type = type, cmd = command,
                       active = l_active, hidden = l_hidden, opacity = l_opacity)
     
     # add maplayer to the list of layers
     self.overlays.append(overlay)
     
     if l_render and command != '' and not overlay.Render():
         raise gcmd.GException(_("Unable render overlay <%s>.") % 
                               name)
     
     return self.overlays[-1]
Beispiel #5
0
def getCardNum(line, key):
    rval = ""
    Debug().p("line %s key %s" % (line, key))
    if line.find(key) != -1:
        Debug().p("found %s:%s" % (key, line))
        rval = line.split()[0].strip()
    return rval
Beispiel #6
0
 def AlignExtentFromDisplay(self):
     """!Align region extent based on display size from center
     point"""
     # calculate new bounding box based on center of display
     if self.region["ewres"] > self.region["nsres"]:
         res = self.region["ewres"]
     else:
         res = self.region["nsres"]
     
     Debug.msg(3, "Map.AlignExtentFromDisplay(): width=%d, height=%d, res=%f, center=%f,%f" % \
                   (self.width, self.height, res, self.region['center_easting'],
                    self.region['center_northing']))
         
     ew = (self.width / 2) * res
     ns = (self.height / 2) * res
     
     self.region['n'] = self.region['center_northing'] + ns
     self.region['s'] = self.region['center_northing'] - ns
     self.region['e'] = self.region['center_easting'] + ew
     self.region['w'] = self.region['center_easting'] - ew
     
     # LL locations
     if self.projinfo['proj'] == 'll':
         self.region['n'] = min(self.region['n'], 90.0)
         self.region['s'] = max(self.region['s'], -90.0)
Beispiel #7
0
 def putArchive(self,choices):
   if Specs().s['doArchive']:
     try:
       Debug().p ("doing archive")
       tmpFile="%s/%s"%(Specs().s['tmpdir'],"tarFiles")
       cdir=self.cache
       textName=cdir+"/"+Specs().s['archiveTextName']
       cf=open(textName,"w")
       cf.write("%s\n"%choices[0])
       cf.write("%s\n"%choices[1])
       cf.close()
       afiles=glob.glob("%s/*.jpg"%cdir)
       tfiles=glob.glob("%s/*.lkp"%cdir)
       tf = open(tmpFile,"w")
       for file in afiles:
         Debug().p ("writing %s to %s"%(file,tmpFile))
         fb = os.path.basename(file)
         tf.write("%s\n"%fb)
       for file in tfiles:
         Debug().p("writing %s to %s"%(file,tmpFile))
         fb = os.path.basename(file)
         tf.write("%s\n"%fb)
       tf.close()
       cmd = ["tar","-czf",self.adir+"/"+str(uuid.uuid4())+".tgz","-C",cdir,"-T",tmpFile]
       Debug().p("cmd %s"%cmd)
       subprocess.check_output(cmd)
     except subprocess.CalledProcessError, e:
       print "Error %s"%(e)
Beispiel #8
0
 def _renderLayers(self, force, mapWindow):
     maps = list()
     masks = list()
     opacities = list()
     # render map layers
     ilayer = 1
     for layer in self.layers + self.overlays:
         # skip non-active map layers
         if not layer or not layer.active:
             continue
         
         # render
         if force or layer.force_render:
             if not layer.Render():
                 continue
         
         if mapWindow:
             # update progress bar
             ### wx.SafeYield(mapWindow)
             event = wxUpdateProgressBar(value = ilayer)
             wx.PostEvent(mapWindow, event)
         
         # add image to compositing list
         if layer.type != "overlay":
             maps.append(layer.mapfile)
             masks.append(layer.maskfile)
             opacities.append(str(layer.opacity))
         
         Debug.msg(3, "Map.Render() type=%s, layer=%s " % (layer.type, layer.name))
         ilayer += 1
     
     return maps, masks, opacities
Beispiel #9
0
def request_from_url(url, settings):
    """
    request_from_url(str)

    gets the request from url and returns the requests object
    """
    cookies = settings["cookies"]
    if cookies["firefox"]:
        cj = web.browser_cookie3.firefox()
    elif cookies["chrome"]:
        cj = web.browser_cookie3.chrome()
    elif cookies["opera"]:
        cj = web.browser_cookie3.opera()
    elif cookies["edge"]:
        cj = web.browser_cookie3.edge()
    else:
        cj = CookieJar()
    try:
        r = web.requests.get(url,
                             cookies=cj,
                             headers={"User-Agent": web.FIREFOX_USER_AGENT},
                             timeout=settings["connection_timeout"])
    except web.requests.ReadTimeout:
        Debug.log_file("ConnectionError", "request_from_url",
                       f"Connection times out on {url}")
        r = None
    return r
Beispiel #10
0
def json_dumps(jdata):
    ''' dump json string inline '''
    try:
        return json.dumps(jdata)
    except Exception as err:
        Debug.error("Error: dump data error: %s" % (err))
    return ""
Beispiel #11
0
 def Draw(self, pdc, img = None, drawid = None, pdctype = 'image', coords = [0,0,0,0]):
     """!Draws histogram or clears window
     """
     if drawid == None:
         if pdctype == 'image' :
             drawid = imagedict[img]
         elif pdctype == 'clear':
             drawid == None
         else:
             drawid = wx.NewId()
     else:
         pdc.SetId(drawid)
     
     pdc.BeginDrawing()
     
     Debug.msg (3, "BufferedWindow.Draw(): id=%s, pdctype=%s, coord=%s" % (drawid, pdctype, coords))
     
     if pdctype == 'clear': # erase the display
         bg = wx.WHITE_BRUSH
         pdc.SetBackground(bg)
         pdc.Clear()
         self.Refresh()
         pdc.EndDrawing()
         return
     
     if pdctype == 'image':
         bg = wx.TRANSPARENT_BRUSH
         pdc.SetBackground(bg)
         bitmap = wx.BitmapFromImage(img)
         w,h = bitmap.GetSize()
         pdc.DrawBitmap(bitmap, coords[0], coords[1], True) # draw the composite map
         pdc.SetIdBounds(drawid, (coords[0],coords[1],w,h))
     
     pdc.EndDrawing()
     self.Refresh()
Beispiel #12
0
 def urlsToImages(urls):
     cdir = Archive().clearArchive()
     imageCount = 0
     images = []
     for url in urls:
         Debug().p("url:%s" % url)
         imageTypes = ['full', 'thumb']
         raw_img = None
         for t in imageTypes:
             try:
                 Debug().p("open image type: %s image: %s" % (t, url[t]))
                 response = requests.get(url[t], timeout=20)
                 raw_img = response.content
                 break
             except Exception as e:
                 traceback.print_exc()
                 print "return from exception for type %s url %s: %s" % (
                     t, url[t], e)
                 continue
         if raw_img != None:
             fname = "%s/urlimage%d.jpg" % (cdir, imageCount)
             imageCount += 1
             f = open(fname, "wb")
             f.write(raw_img)
             f.close()
             images.append(fname)
     return images
Beispiel #13
0
    def make_image(self, images):
        d.dbg('Broxton.make_image: {}'.format(images))
        make_sh = None
        for image in images:
            d.dbg('create makesh for {}'.format(image))
            if type(image) is dict:
                if 'mmm' in image:
                    make_sh = self.create_mmm_sh(image['mmm'])
                else:
                    d.err('Not support: %s' % str(image))
                    exit()
            else:
                make_sh = self.create_make_sh(image)

            # set run right
            cmd = r'chmod a+x {}'.format(make_sh)
            subprocess.call(cmd, shell=True)
            # run make sh
            cmd = r'./{}'.format(make_sh)
            d.dbg(cmd)
            subprocess.call(cmd, shell=True)
            # delete make sh
            cmd = r'rm -rf {}'.format(make_sh)
            d.dbg(cmd)
            subprocess.call(cmd, shell=True)
Beispiel #14
0
    def _get_components(self):
        ''' query components, the result like:
            {
                "Statistics":   "ACTIVE", 
                "Billing":      "ACTIVE", 
                "LocationDataStream":   "ACTIVE", 
                ...
            }
        '''
        cmd = r'fdsinstall  -u Setup -p Earth_#10 -s'
        data = os.popen(cmd).read()
        if not data:
            Debug.error("query components state error: %s" % cmd)
            return None

        # parse state
        lines = data.split('\n')
        components = {}
        for line in lines:
            # FSC-Event/4.1/linux-eagle-32/1    ACTIVE      linux-eagle-32
            pattern = r'([^/]*)\/(\d\.\d)\/([^/]*)\/(\d)\s*(\w+)\s+'
            matchObj = re.match(pattern, line)
            if matchObj:
                components[matchObj.group(1)] = matchObj.group(5)
                # components[matchObj.group(1)] = {
                #    "Version": matchObj.group(2),
                #    "State": matchObj.group(5)
                # }

        return components
Beispiel #15
0
    def __init__(self, data=None, size=2**10):
        self.data = data if data else [r_uint32(0)] * (size >> 2)
        self.size = r_uint(len(self.data) << 2)
        self.debug = Debug()

        # TODO: pass data_section to memory for bounds checking
        self.data_section = 0x00000000
Beispiel #16
0
def json_dumps4(jdata):
    ''' dump json string with pretty format '''
    try:
        return json.dumps(jdata, indent=4)
    except Exception as err:
        Debug.error("Error: dump data error: %s" % (err))
    return ""
Beispiel #17
0
    def DeleteLayer(self, layer, overlay = False):
        """!Removes layer from list of layers
        
        @param layer layer instance in layer tree
        @param overlay delete overlay (use self.DeleteOverlay() instead)

        @return removed layer on success or None
        """
        Debug.msg (3, "Map.DeleteLayer(): name=%s" % layer.name)
        
        if overlay:
            list = self.overlays
        else:
            list = self.layers
        
        if layer in list:
            if layer.mapfile:
                base = os.path.split(layer.mapfile)[0]
                mapfile = os.path.split(layer.mapfile)[1]
                tempbase = mapfile.split('.')[0]
                if base == '' or tempbase == '':
                    return None
                basefile = os.path.join(base, tempbase) + r'.*'
                for f in glob.glob(basefile):
                    os.remove(f)
            list.remove(layer)
            
            return layer
        
        return None
Beispiel #18
0
    def OnLeftUp(self, event):
        """!Left mouse button released
        """
        Debug.msg (5, "BufferedWindow.OnLeftUp(): use=%s" % \
                       self.mouse["use"])

        self.mouse['end'] = event.GetPositionTuple()[:]

        if self.mouse['use'] in ["zoom", "pan"]:
            # set region in zoom or pan
            begin = self.mouse['begin']
            end = self.mouse['end']

            if self.mouse['use'] == 'zoom':
                # set region for click (zero-width box)
                if begin[0] - end[0] == 0 or \
                        begin[1] - end[1] == 0:
                    # zoom 1/2 of the screen (TODO: settings)
                    begin = (end[0] - self.Map.width / 4,
                             end[1] - self.Map.height / 4)
                    end = (end[0] + self.Map.width / 4,
                           end[1] + self.Map.height / 4)

            self.Zoom(begin, end, self.zoomtype)

            # redraw map
            self.UpdateMap(render=True)

            # update statusbar
            self.parent.StatusbarUpdate()
Beispiel #19
0
    def __init__(self, constant_zero=True, num_regs=32):
        self.num_regs = num_regs
        self.regs = [0] * self.num_regs
        self.debug = Debug()

        if constant_zero: self._setitemimpl = self._set_item_const_zero
        else: self._setitemimpl = self._set_item
def getApkInfo(repo, apkid, apkversion, options=None, doVersion1=False):
    """
    getApkInfo(repo, apkid, apkversion): Get APK specific information from the Aptoide API
                                         and return it in JSON form
    """
    version   = '1' if doVersion1 else '2'
    file_name = '{0}-{1}-{2}_{3}.json'.format(repo, apkid, apkversion, version)
    options   = '' if not options else '/options=({0})'.format(options)
    url       = 'http://webservices.aptoide.com/webservices/{0}/getApkInfo/{1}/{2}/{3}{4}/json'.format(
                version, repo, apkid, apkversion, options)
    data      = Debug.readFromFile(file_name)

    try:
        if data == '':
            session = requests.Session()
            # session.proxies = Debug.getProxy()
            logging.debug('Requesting2: ' + url)
            resp    = session.get(url)
            data    = json.loads(resp.text)
            Debug.writeToFile(file_name, json.dumps(data, sort_keys=True,
                              indent=4, separators=(',', ': ')), resp.encoding)

        if data['status'] == 'OK':
            return data
        else:
            logging.error(file_name)
    except:
        logging.exception('!!! Invalid JSON from: "{0}"'.format(url))

    return None
    def _poweroff(self):
        """
        Log on to remote node and shut it down.

        :rtype: str
        :returns: Status message

        """
        host = request.args.get('host')
        if host is None:
            message = "Error 'poweroff' must have parameter 'host'!"
            return self._json_response(message, 400)
        if host in self.API_POWEROFF_HOSTS.keys():
            user = self.API_POWEROFF_HOSTS[host]['user']
        else:
            message = "Error host '{}' has not been configured for 'poweroff'!"
            message = message.format(host)
            return self._json_response(message, 400)
        # Power off node
        command = ("{}ssh -o 'StrictHostKeyChecking no' -i {} -T {}@{} 'shutdo"
                   "wn -h now'")
        ssh_key_file = self.SSH_KEY_FILE.replace('$HOST', host)
        command = command.format(self.SSH_PATH, ssh_key_file, user, host)
        Debug.debug_print(1, 'Shut down command: {}'.format(command))
        p = subprocess.Popen(
            command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
            shell=True)
        stdout, stderr = p.communicate()
        message = codecs.decode(stdout + stderr, 'utf-8')
        return self._json_response(message, 200)
Beispiel #22
0
def getVersionInfo(apkVersionInfo):
    """
    getVersionInfo(apkVersionInfo): Determines each versions information
    """
    html_name = apkVersionInfo.scrape_url.rsplit('/', 2)[1]
    html_name = html_name.replace('-android-apk-download', '') + '.html'
    url       = APKMIRRORBASEURL + apkVersionInfo.scrape_url
    html      = Debug.readFromFile(html_name)

    if html == '':
        session = requests.Session()
        logging.debug('Requesting3: ' + url)
        resp    = session.get(url)
        html    = unicodedata.normalize('NFKD', resp.text).encode('ascii', 'ignore')
        Debug.writeToFile(html_name, html, resp.encoding)

    try:
        dom       = BeautifulSoup(html, 'html5lib')
        postArea  = dom.findAll('div', {'class': 'post-area'})[0]
        dl_button = postArea.findAll('a', {'type': 'button'})[1]
        blueFonts = postArea.findAll('span', {'class': 'fontBlue'})

        apkVersionInfo.download_url = dl_button['href']

        for blueFont in blueFonts:
            if blueFont.get_text() == 'File name: ':
                apkVersionInfo.apk_name = blueFont.next_sibling
            if blueFont.get_text() == 'Version: ':
                apkVersionInfo.ver = blueFont.next_sibling
    except:
        logging.exception('!!! Error parsing html from: "{0}"'.format(url))
Beispiel #23
0
 def run(self):
   stime = time.time()
   while SoundFile().testBumpCollection():
     try:
       #print (self.name,"time",time.time(),"stime",stime)
       if time.time() > stime:
         entry = SoundFile().getSoundEntry()
         Debug().p ("player choosing %s "%entry)
         count = 0
         for t in self.tList:
           choice = entry[count]
           count += 1
           if count == len(entry):
             count = 0
           Debug().p ("sending %s to %s"%(choice,t.name))
           t.setCurrentSound(choice)
         offset = random.randint(Specs().s['minChange'],Specs().s['maxChange'])
         stime = time.time() + offset
         Debug().p ("next change: %d"%offset)
         n = pygame.mixer.get_busy()
         Debug().p ("number busy channels %d"%n)
       time.sleep(1)
     except Exception as e:
       print("player error: "+repr(e))
       os._exit(3)
   for t in self.tList:
     t.stop()
   self.done = True
Beispiel #24
0
 def printText(self, t):
     self.clear()
     Debug().p("%s panel 0 %s len %s" % (self.name, t[0], len(t[0])))
     self.ser.write('{0: ^16}'.format(t[0]).upper())
     Debug().p("%s panel 1 %s len %s" % (self.name, t[1], len(t[1])))
     self.setRow(1)
     self.ser.write('{0: ^16}'.format(t[1]).upper())
Beispiel #25
0
 def sysex(self,msg):
   Debug().p("sysex got msg %s"%msg)
   
   if self.setupState == "RequestSceneData":
     self.scene = sysex_to_data(msg.data[12:])
     for l in self.desc['soundLists']:
       for s in l:
         self.soundList.append(s)
     maxSounds = len(self.soundList)
     maxSounds &= 0x7f
     for y in range(0,8):
       for x in NanoPlayer.togLocs:
         self.scene[x+(y*31)] = 1
       maxNotes = 48
       self.scene[NanoPlayer.sliderMaxLoc+(y*31)] = maxNotes 
       self.scene[NanoPlayer.knobMaxLoc+(y*31)] = maxSounds
     for x in NanoPlayer.transTogs:
       self.scene[x] = 1
     
     
     retData = data_to_sysex(self.scene)
     header = []
     for c in range(0,12):
       header.append(msg.data[c])
     for rd in retData:
       header.append(rd)
     self.sendSysex(header)
     self.setupState = "ConfigDataSent"
   elif self.setupState == "ConfigDataSent":
     if msg.data[7] != 35:
       print("MIDI ERROR: config did not succeed")
     self.setupState == None
   elif self.setupState == None:
     Debug().p("%s unexepected sysex message: %s"%(self.name,msg))
Beispiel #26
0
    def checkOneApp(self, apkid):
        """
        checkOneApp(apkid):
        """
        logging.info('Checking app: {0}'.format(apkid))

        filenames = []

        url       = 'http://apk-dl.com/' + apkid

        session = requests.Session()
        logging.debug('Requesting: ' + url)
        resp    = session.get(url)
        html    = unicodedata.normalize('NFKD', resp.text).encode('ascii', 'ignore')

        try:
            dom     = BeautifulSoup(html, 'html5lib')
            apklist = dom.findAll('ul', {'class': 'apks dlist'})[0]
            apks    = apklist.findAll('div', {'class': 'details'})

            for apk in apks:
                items = apk.findAll('div')
                dApk = {}
                for item in items:
                    itext = '{0}'.format(item.get_text().encode('ascii', 'ignore'))
                    itext = re.sub('\s', '', itext)
                    itextsp = itext.split(':', 1)
                    if len(itextsp) == 2:
                        dApk[str(itextsp[0])] = str(itextsp[1])
                apkurl = apk.find('a', {'class': 'btn btn-success'})
                if apkurl:
                    dApk['url'] = 'http:' + apkurl['href']

                    Debug.printDictionary(dApk)

                    if 'Version' in dApk and 'RequiresAndroid' in dApk:
                        (trash, sdk) = dApk['RequiresAndroid'].split('API:', 1)
                        sdk = sdk[0:-1]
                        (ver, vercode) = dApk['Version'].split('(Code:', 1)
                        ver     = ver.split('(', 1)[0].strip()
                        vercode = vercode[0:-1].strip()

                        avi = ApkVersionInfo(name=apkid,
                                             sdk=sdk,
                                             ver=ver,
                                             vercode=vercode,
                                             download_src=dApk['url'],
                                             crawler_name=self.__class__.__name__
                                             )

                        if self.report.isThisApkNeeded(avi):
                            filenames.append(self.downloadApk(avi))

        except IndexError:
            logging.info('{0} not supported by apk-dl.com ...'.format(apkid))
        except:
            logging.exception('!!! Error parsing html from: "{0}"'.format(url))

        return filenames
Beispiel #27
0
    def __init__(self, url=URL):
        super(Cwp, self).__init__(url)
        self._url = url

        # create cmd process
        self._cmdHdrs = CmdProcessing()
        self._cmdHdrs.register_cmd_handler(self.get_cmd_handlers())
        d.dbg('Cwp init done!')
Beispiel #28
0
 def getRunNameInDirForMutable(self, run_dir, mutable, slope=''):
     gradient = str(mutable.name)
     if(slope):
         gradient += str(slope)
     run_name = self.run_name_in_dir.format(
         run_dir=run_dir, this=self, gradient=gradient)
     Debug.log('run_name: ' + run_name)
     return run_name
Beispiel #29
0
def startDownload(driver):
    driver.get(Config.Base_Url + Config.Target_Name + Config.Category)
    Debug.log('fbPA:' + Config.Base_Url + Config.Target_Name + Config.Category)
    Debug.sc_shot(driver, '2-Albums Index.png')
    html_source = (driver.page_source).encode('utf-8')

    getAllAlbumsInfo(driver, html_source)
    startDownloadAlbumsPhoto(driver)
def startDownload(driver):
    driver.get( Config.Base_Url + Config.Target_Name + Config.Category)
    Debug.log('fbPA:'+ Config.Base_Url + Config.Target_Name + Config.Category)
    Debug.sc_shot(driver,'2-Albums Index.png')
    html_source = (driver.page_source).encode('utf-8')

    getAllAlbumsInfo(driver, html_source)
    startDownloadAlbumsPhoto(driver)
Beispiel #31
0
 def calculate(self, cur_run_file):
     '''determine the value of each run'''
     # Get data to compare
     self._cost = self._getData(cur_run_file)
     # Apply the weight to the cost function
     self._cost *= self.__weight
     Debug.log('cost: {0}'.format(self._cost), False)
     return self._cost
Beispiel #32
0
    def _onMouseMoving(self, event):
        self.mouse['end'] = event.GetPositionTuple()[:]
        
        Debug.msg (5, "BufferedWindow.OnMouseMoving(): coords=%f,%f" % \
                       (self.mouse['end'][0], self.mouse['end'][1]))

        action = self.toolbar.GetAction()
        if action == "addLine" and \
                self.toolbar.GetAction('type') in ["line", "boundary", "area"]:
            if len(self.polycoords) > 0:
                self.MouseDraw(pdc = self.pdcTmp, begin = self.Cell2Pixel(self.polycoords[-1]))
        
        elif action in ["moveLine", "moveVertex", "editLine"] \
                and hasattr(self, "moveInfo"):
            dx = self.mouse['end'][0] - self.mouse['begin'][0]
            dy = self.mouse['end'][1] - self.mouse['begin'][1]
        
            # draw lines on new position
            if action == "moveLine" and \
                    len(self.moveInfo['id']) > 0:
                # move line
                for id in self.moveInfo['id']:
                    self.pdcTmp.TranslateId(id, dx, dy)
            elif action in ["moveVertex", "editLine"]:
                # move vertex ->
                # (vertex, left vertex, left line,
                # right vertex, right line)
                
                # do not draw static lines
                if action == "moveVertex" and \
                        len(self.moveInfo['id']) > 0:
                    self.polycoords = []
                    self.pdcTmp.RemoveId(self.moveInfo['id'][0])
                    if self.moveInfo['id'][1] > 0: # previous vertex
                        x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.moveInfo['id'][1])[0:2])
                        self.pdcTmp.RemoveId(self.moveInfo['id'][1] + 1)
                        self.polycoords.append((x, y))
                    self.polycoords.append(self.Pixel2Cell(self.mouse['end']))

                    if self.moveInfo['id'][2] > 0: # next vertex
                        x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.moveInfo['id'][2])[0:2])
                        self.pdcTmp.RemoveId(self.moveInfo['id'][2]-1)
                        self.polycoords.append((x, y))
                    
                    self.ClearLines(pdc = self.pdcTmp)
                    self.DrawLines(pdc = self.pdcTmp)
                        
                if action == "editLine":
                    self.MouseDraw(pdc = self.pdcTmp,
                                   begin = self.Cell2Pixel(self.polycoords[-1]))
                
            self.Refresh() # TODO: use RefreshRect()
            self.mouse['begin'] = self.mouse['end']
            
        elif action == "zbulkLine":
            if len(self.polycoords) == 1:
                # draw mouse moving
                self.MouseDraw(self.pdcTmp)
Beispiel #33
0
def json_parse(data):
    ''' parse json string '''
    try:
        if not data:
            return {}
        return json.loads(data)
    except Exception as err:
        Debug.error("Error: parse data (%.25s...) error: %s" % (data, err))
    return {}
Beispiel #34
0
 def ChangeLayerName (self, layer, name):
     """!Change name of the layer
     
     @param layer layer instance in layer tree
     @param name  layer name to set up
     """
     Debug.msg (3, "Map.ChangeLayerName(): from=%s to=%s" % \
                (layer.name, name))
     layer.name =  name
Beispiel #35
0
    def __init__(self, constant_zero=True, num_regs=32, nbits=32):
        self.num_regs = num_regs
        self.regs = [r_uint(0)] * self.num_regs
        self.debug = Debug()
        self.nbits = nbits
        self.debug_nchars = nbits / 4

        if constant_zero: self._setitemimpl = self._set_item_const_zero
        else: self._setitemimpl = self._set_item
Beispiel #36
0
 def next(self):
     Debug().p(self.recog.name + " in dataStream next")
     chunk = self.recog.queue.get()
     if type(chunk) is str and chunk == "__stop__":
         print("%s stopping" % self.recog.name)
         self.recog.running = false
         raise StopIteration
     Debug().p(self.recog.name + " got:" + str(len(chunk)))
     return chunk
Beispiel #37
0
 def help(self, cmds):
     for cmd in cmds:
         if cmd == 'help':
             d.info('repo:[init][,sync|fsync]')
             d.info('  init : repo init source code')
             d.info('  sync : repo sync source code')
             d.info('  fsync: repo sync source code with -f')
         elif cmd == 'cfg':
             d.info('url: {}'.format(self._url))
Beispiel #38
0
 def ChangeLayerActive(self, layer, active):
     """!Enable or disable map layer
     
     @param layer layer instance in layer tree
     @param active to be rendered (True)
     """
     layer.active = active
     
     Debug.msg (3, "Map.ChangeLayerActive(): name='%s' -> active=%d" % \
                (layer.name, layer.active))
Beispiel #39
0
    def repo_handler(self, cmds):
        d.dbg('repo_handler: %s' % cmds)

        for cmd in cmds:
            if cmd == 'init':
                self.repo_init()
            elif cmd == 'sync':
                self.repo_sync()
            elif cmd == 'fsync':
                self.repo_sync(True)
Beispiel #40
0
 def find_handler(self, cmds):
     d.dbg('find_handler: {}'.format(cmds))
     try:
         n = len(cmds)
         if n == 1:
             self.find('./', cmds[0])
         elif n >= 2:
             self.find(cmds[0], cmds[1])
     except KeyError as e:
         d.err('Error: %s' % e)
Beispiel #41
0
class _SparseMemory( object ):
  _immutable_fields_ = [ "BlockMemory", "block_size", "addr_mask",
                         "block_mask" ]

  def __init__( self, BlockMemory, block_size=2**10 ):
    self.BlockMemory = BlockMemory
    self.block_size = block_size
    self.addr_mask  = block_size - 1
    self.block_mask = 0xffffffff ^ self.addr_mask
    self.debug = Debug()
    print "sparse memory size %x addr mask %x block mask %x" \
          % ( self.block_size, self.addr_mask, self.block_mask )
    #blocks     = []
    self.block_dict = {}

  def add_block( self, block_addr ):
    #print "adding block: %x" % block_addr
    self.block_dict[ block_addr ] = self.BlockMemory( size=self.block_size )

  @elidable
  def get_block_mem( self, block_addr ):
    #block_idx  = block_dict[ 
    if block_addr not in self.block_dict:
      self.add_block( block_addr )
    block_mem = self.block_dict[ block_addr ]
    return block_mem

  @elidable
  def iread( self, start_addr, num_bytes ):
    start_addr = hint( start_addr, promote=True )
    num_bytes  = hint( num_bytes,  promote=True )

    block_addr = self.block_mask & start_addr
    block_mem = self.get_block_mem( block_addr )
    return block_mem.iread( start_addr & self.addr_mask, num_bytes )

  def read( self, start_addr, num_bytes ):
    if self.debug.enabled( "mem" ):
      print ':: RD.MEM[%s] = ' % pad_hex( start_addr ),
    block_addr = self.block_mask & start_addr
    block_addr = hint( block_addr, promote=True )
    block_mem = self.get_block_mem( block_addr )
    value = block_mem.read( start_addr & self.addr_mask, num_bytes )
    if self.debug.enabled( "mem" ):
      print '%s' % pad_hex( value ),
    return value

  def write( self, start_addr, num_bytes, value ):
    if self.debug.enabled( "mem" ):
      print ':: WR.MEM[%s] = %s' % ( pad_hex( start_addr ),
                                     pad_hex( value ) ),
    block_addr = self.block_mask & start_addr
    block_addr = hint( block_addr, promote=True )
    block_mem = self.get_block_mem( block_addr )
    block_mem.write( start_addr & self.addr_mask, num_bytes, value )
Beispiel #42
0
 def run(self):
     print("%s starting" % self.name)
     self.setRunning(SoundFile().testBumpCollection())
     loop = Specs().s['musicLoop']
     while self.isRunning():
         if self.checkMsg():
             continue
         entry = SoundFile().getSoundEntry()
         Debug().p("player choosing %s" % entry)
         count = 0
         if self.musicBlocks[Hosts().getLocalHost()].mute:
             Debug().p("%s local %s mute so ignoring" %
                       (self.name, Hosts().getLocalHost()))
         else:
             for t in SoundTrackManager().eventThreads:
                 choice = random.choice(entry)
                 Debug().p("sending  %s request to %s" % (choice, t.name))
                 t.setCurrentSound(choice)
         for ip in self.musicBlocks.keys():
             if Hosts().isLocalHost(ip):
                 Debug().p("%s: ignoring %s" % (self.name, ip))
                 continue
             if self.musicBlocks[ip].mute:
                 Debug().p("%s: ignoring muted %s %s" %
                           (self.name, ip, self.musicBlocks[ip].mute))
                 continue
             try:
                 url = "http://" + ip + ":8080"
                 Debug().p("%s: url: %s" % (self.name, url))
                 cmd = {'cmd': "Sound", 'args': choice}
                 req = urllib2.Request(url, json.dumps(cmd),
                                       {'Content-Type': 'application/json'})
                 timeout = 1
                 f = urllib2.urlopen(req, None, timeout)
                 test = f.read()
                 Debug().p("%s: got response:%s" % (self.name, test))
             except urllib2.URLError as ve:
                 Debug().p("%s: got URLError %s on ip:%s" %
                           (self.name, ve, ip))
                 continue
             except Exception as e:
                 print("%s got exception %s" % (self.name, e))
                 continue
         self.waitTime = random.randint(Specs().s['minChange'],
                                        Specs().s['maxChange'])
         Debug().p("next change: %d" % self.waitTime)
         #Debug().p("number busy channels %d"%n
         if SoundFile().testBumpCollection() is False:
             print "waiting for channels to be done"
             n = pygame.mixer.get_busy()
             while n != 0:
                 n = pygame.mixer.get_busy()
                 print "number busy channels", n
                 if self.checkMsg():
                     continue
             if loop:
                 SoundFile().setCurrentCollection(self.collection)
             else:
                 self.SetRunning(false)
     self.doExit()
Beispiel #43
0
 def __init__( self, BlockMemory, block_size=2**10 ):
   self.BlockMemory = BlockMemory
   self.block_size = block_size
   self.addr_mask  = block_size - 1
   self.block_mask = 0xffffffff ^ self.addr_mask
   self.debug = Debug()
   print "sparse memory size %x addr mask %x block mask %x" \
         % ( self.block_size, self.addr_mask, self.block_mask )
   #blocks     = []
   self.block_dict = {}
   self.debug = Debug()
def checkOneApp(apkid):
    """
    checkOneApp(apkid):
    """
    dAllApks = Global.dAllApks
    maxVerEachApk = Global.maxVerEachApk
    minSdkEachApk = Global.minSdkEachApk

    logging.info("Checking app: {0}".format(apkid))

    file_name = "{0}.json".format(apkid)
    url = "http://helper.mgccw.com/nclient/sjson/detail/detailInfo.htm?apkId=" + apkid
    data = Debug.readFromFile(file_name)

    try:
        if data == "":
            session = requests.Session()
            # session.proxies = Debug.getProxy()
            logging.debug("Requesting: " + url)
            resp = session.get(url, allow_redirects=False)
            if (resp.status_code) == 302:
                raise ValueError
            data = json.loads(resp.text)
            Debug.writeToFile(
                file_name, json.dumps(data, sort_keys=True, indent=4, separators=(",", ": ")), resp.encoding
            )

        item = data["data"]["appInfo"]

        if not filter(lambda apk: apk.vercode == item["versionCode"], dAllApks[apkid]):

            v = item["version"].split(" ")[0]
            maxApkInfo = ApkVersionInfo(name=item["apkId"], ver=maxVerEachApk[item["apkId"]])
            tmpApkInfo = ApkVersionInfo(name=item["apkId"], ver=v)
            # Is it >= maxVersion
            if maxApkInfo <= tmpApkInfo:
                thisSdk = int(item["sdkVersion"])
                if thisSdk < minSdkEachApk[item["apkId"]]:
                    logging.debug("SdkTooLow: {0}({1})".format(item["apkId"], thisSdk))
                else:
                    downloadApk(
                        "http://download.mgccw.com/" + item["apkPath"],
                        item["apkId"],
                        item["version"],
                        item["versionCode"],
                        item["sdkVersion"],
                    )
                # END: if Sdk
            # END: if item

    except ValueError:
        logging.info("{0} not supported by mobogenie ...".format(apkid))
    except:
        logging.exception('!!! Invalid JSON from: "{0}"'.format(url))
Beispiel #45
0
def get_all_hough_lines(image, min_angle, max_angle, min_separation_distance,
                        min_separation_angle):

    angles = np.deg2rad(np.arange(min_angle, max_angle, 0.5))
    hough, angles, distances = hough_line(image, angles)

    Debug.save_image("hough", "accumulator", normalize(hough))

    _, peak_angles, peak_distances = \
      hough_line_peaks(hough, angles, distances,
                       num_peaks=150,
                       threshold=0.2*np.amax(hough),
                       min_distance=min_separation_distance,
                       min_angle=min_separation_angle)

    lines = [
        get_line_endpoints_in_image(image, angle, radius)
        for angle, radius in zip(peak_angles, peak_distances)
    ]

    if Debug.active:
        peak_angle_idxs = [
            np.where(angles == angle)[0][0] for angle in peak_angles
        ]
        peak_rho_idxs = [
            np.where(distances == distance)[0][0]
            for distance in peak_distances
        ]
        peak_coords = zip(peak_rho_idxs, peak_angle_idxs)
        peaks = np.zeros(hough.shape)
        for coord in peak_coords:
            peaks[coord] = 1
        Debug.save_image("hough", "accumulator_peaks", peaks)

    if Record.active:
        # Thought get_max_theta_idx might be a useful way to filter
        # real meanlines from spurious meanlines, but it's not
        # reliable when the image is saturated with incorrect
        # meanlines. Filtering lines based on the ROI angle
        # was more effective.

        # max_theta_idx = get_max_theta_idx(hough)
        # Record.record("theta_mode", angles[max_theta_idx])

        # in radians
        average_meanline_angle = np.mean(peak_angles)
        std_deviation_meanline_angle = np.std(peak_angles)

        Record.record("average_meanline_angle",
                      float("%.4f" % average_meanline_angle))
        Record.record("std_deviation_meanline_angle",
                      float("%.4f" % std_deviation_meanline_angle))

    return lines
Beispiel #46
0
def base64decode(data):
    ''' base64 decode string '''
    try:
        val = base64.b64decode(data).decode("UTF-8")
        if val is not None:
            if type(val) == str:
                return val
            return val.decode("UTF-8")
    except Exception as err:
        Debug.error("Error: b64decode data (%.25s...) error: %s" % (data, err))
    return ""
Beispiel #47
0
 def on_stop_mock(self):
     """ 
     Stop button is pressed
     """
     if is_android:
         Globals.mock_thread.send_message("stop")
     else:
         # Set a random location on Windows or Linux
         Debug.randomize_latlng()
         self.mockmapview.update_current_locmarker(Debug.latitude, Debug.longitude, False)
     self.mockmapview.remove_target_marker()
Beispiel #48
0
 def get(cls, handler, name):
     session = SessionManager(handler)
     Debug.dprint(text='name: ' + name, type='custom')
     Debug.dprint(text='value: ' + str(session.get(name)), type='error')
     # print "Session name is: " + name
     # print "Do we have a session? " + str(session.get(name))
     # if cls.exists(handler, name):
     #     print "There is a session"
     # else:
     #     print "There is not any sessionn"
     return session.get(name)
Beispiel #49
0
 def SetCmd(self, cmd):
     """!Set new command for layer"""
     if self.type == 'command':
         self.cmd = []
         for c in cmd:
             self.cmd.append(utils.CmdToTuple(c))
     else:
         self.cmd  = utils.CmdToTuple(cmd)
     Debug.msg(3, "Layer.SetCmd(): cmd='%s'" % self.GetCmd(string = True))
     
     # for re-rendering
     self.force_render = True
def startDownloadAlbumsPhoto(driver):
    for index, item in enumerate(AlbumsInfoList):
        driver.get( Config.Base_Url + Config.Target_Name + '/media_set?set=' + AlbumsInfoList[index].albums_link)
        Debug.sc_shot(driver,'3-AlbumsPhoto.png')
        html_source = (driver.page_source).encode('utf-8')

        # Create folder
        folder_path = r'./' + Config.Folder_name + '/' + cleanFolderName(item.albums_name)
        if not os.path.exists(folder_path):
            os.makedirs(folder_path)

        getAllAlbumsPhoto(driver, html_source, folder_path)
        break
Beispiel #51
0
    def ChangeOpacity(self, layer, l_opacity):
        """!Changes opacity value of map layer

        @param layer layer instance in layer tree
        @param l_opacity opacity level <0;1>
        """
        # l_opacity must be <0;1>
        if l_opacity < 0: l_opacity = 0
        elif l_opacity > 1: l_opacity = 1
        
        layer.opacity = l_opacity
        Debug.msg (3, "Map.ChangeOpacity(): layer=%s, opacity=%f" % \
                   (layer.name, layer.opacity))
Beispiel #52
0
 def ReorderLayers(self, layerList):
     """!Reorder list to match layer tree
     
     @param layerList list of layers
     """
     self.layers = layerList
     
     layerNameList = ""
     for layer in self.layers:
         if layer.name:
             layerNameList += layer.name + ','
     Debug.msg (4, "Map.ReoderLayers(): layers=%s" % \
                (layerNameList))
Beispiel #53
0
    def __InitDisplay(self):
        """
        Initialize map display, set dimensions and map region
        """
        self.width, self.height = self.GetClientSize()

        Debug.msg(2, "MapFrame.__InitDisplay():")
        self.grwiz.SwitchEnv('source')
        self.SrcMap.ChangeMapSize(self.GetClientSize())
        self.SrcMap.region = self.SrcMap.GetRegion() # g.region -upgc
        self.grwiz.SwitchEnv('target')
        self.TgtMap.ChangeMapSize(self.GetClientSize())
        self.TgtMap.region = self.TgtMap.GetRegion() # g.region -upgc
Beispiel #54
0
class RegisterFile( object ):
  def __init__( self, constant_zero=True, num_regs=32, nbits=32 ):
    self.num_regs = num_regs
    self.regs     = [ r_uint(0) ] * self.num_regs
    self.debug    = Debug()
    self.nbits    = nbits
    self.debug_nchars = nbits / 4

    if constant_zero: self._setitemimpl = self._set_item_const_zero
    else:             self._setitemimpl = self._set_item
  def __getitem__( self, idx ):
    if self.debug.enabled( "rf" ):
      print ':: RD.RF[%s] = %s' % (
                          pad( "%d" % idx, 2 ),
                          pad_hex( self.regs[idx],
                                   len=self.debug_nchars ) ),
    return self.regs[idx]

  @specialize.argtype(2)
  def __setitem__( self, idx, value ):
    value = r_uint( value )
    self._setitemimpl( idx, value )

  def _set_item( self, idx, value ):
    self.regs[idx] = value
    if self.debug.enabled( "rf" ):
      print ':: WR.RF[%s] = %s' % (
                        pad( "%d" % idx, 2 ),
                        pad_hex( self.regs[idx],
                                 len=self.debug_nchars ) ),
  def _set_item_const_zero( self, idx, value ):
    if idx != 0:
      self.regs[idx] = value
      if self.debug.enabled( "rf" ):
        print ':: WR.RF[%s] = %s' % (
                          pad( "%d" % idx, 2 ),
                          pad_hex( self.regs[idx],
                                   len=self.debug_nchars ) ),

  #-----------------------------------------------------------------------
  # print_regs
  #-----------------------------------------------------------------------
  # prints all registers (register dump)
  # per_row specifies the number of registers to display per row
  def print_regs( self, per_row=6 ):
    for c in xrange( 0, self.num_regs, per_row ):
      str = ""
      for r in xrange( c, min( self.num_regs, c+per_row ) ):
        str += "%s:%s " % ( pad( "%d" % r, 2 ),
                            pad_hex( self.regs[r], len=(self.nbits/4) ) )
      print str
Beispiel #55
0
class _ByteMemory( object ):
  def __init__( self, data=None, size=2**10 ):
    self.data  = data if data else [' '] * size
    self.size  = len( self.data )
    self.debug = Debug()

  def bounds_check( self, addr ):
    # check if the accessed data is larger than the memory size
    if addr > self.size:
      print "WARNING: accessing larger address than memory size. " + \
            "addr=%s size=%s" % ( pad_hex( addr ), pad_hex( self.size ) )
    if addr == 0:
      print "WARNING: writing null pointer!"
      raise Exception()

  @unroll_safe
  def read( self, start_addr, num_bytes ):
    if self.debug.enabled( "memcheck" ):
      self.bounds_check( start_addr )
    value = 0
    if self.debug.enabled( "mem" ):
      print ':: RD.MEM[%s] = ' % pad_hex( start_addr ),
    for i in range( num_bytes-1, -1, -1 ):
      value = value << 8
      value = value | ord( self.data[ start_addr + i ] )
    if self.debug.enabled( "mem" ):
      print '%s' % pad_hex( value ),
    return value

  # this is instruction read, which is otherwise identical to read. The
  # only difference is the elidable annotation, which we assume the
  # instructions are not modified (no side effects, assumes the addresses
  # correspond to the same instructions)
  @elidable
  def iread( self, start_addr, num_bytes ):
    value = 0
    for i in range( num_bytes-1, -1, -1 ):
      value = value << 8
      value = value | ord( self.data[ start_addr + i ] )
    return value

  @unroll_safe
  def write( self, start_addr, num_bytes, value ):
    if self.debug.enabled( "memcheck" ):
      self.bounds_check( start_addr )
    if self.debug.enabled( "mem" ):
      print ':: WR.MEM[%s] = %s' % ( pad_hex( start_addr ),
                                     pad_hex( value ) ),
    for i in range( num_bytes ):
      self.data[ start_addr + i ] = chr(value & 0xFF)
      value = value >> 8
Beispiel #56
0
 def UpdateHist(self, img = None):
     """!Update canvas if histogram options changes or window
     changes geometry
     """
     Debug.msg (2, "BufferedWindow.UpdateHist(%s): render=%s" % (img, self.render))
     oldfont = ""
     oldencoding = ""
     
     if self.render:
         # render new map images
         # set default font and encoding environmental variables
         if "GRASS_FONT" in os.environ:
             oldfont = os.environ["GRASS_FONT"]
         if self.parent.font != "": os.environ["GRASS_FONT"] = self.parent.font
         if "GRASS_ENCODING" in os.environ:
             oldencoding = os.environ["GRASS_ENCODING"]
         if self.parent.encoding != None and self.parent.encoding != "ISO-8859-1":
             os.environ[GRASS_ENCODING] = self.parent.encoding
         
         # using active comp region
         self.Map.GetRegion(update = True)
         
         self.Map.width, self.Map.height = self.GetClientSize()
         self.mapfile = self.Map.Render(force = self.render)
         self.img = self.GetImage()
         self.resize = False
     
     if not self.img: return
     try:
         id = self.imagedict[self.img]
     except:
         return
     
     # paint images to PseudoDC
     self.pdc.Clear()
     self.pdc.RemoveAll()
     self.Draw(self.pdc, self.img, drawid = id) # draw map image background
     
     self.resize = False
     
     # update statusbar
     # Debug.msg (3, "BufferedWindow.UpdateHist(%s): region=%s" % self.Map.region)
     self.Map.SetRegion()
     self.parent.statusbar.SetStatusText("Image/Raster map <%s>" % self.parent.mapname)
     
     # set default font and encoding environmental variables
     if oldfont != "":
         os.environ["GRASS_FONT"] = oldfont
     if oldencoding != "":
         os.environ["GRASS_ENCODING"] = oldencoding
Beispiel #57
0
def EncodeString(string):
    """!Return encoded string using system locales
    
    @param string string to be encoded
    
    @return encoded string
    """
    if not string:
        return string
    enc = locale.getdefaultlocale()[1]
    if enc:
        Debug.msg(5, "EncodeString(): enc=%s" % enc)
        return string.encode(enc)
    
    return string
Beispiel #58
0
  def __init__( self, data=None, size=2**10 ):
    self.data  = data if data else [ r_uint32(0) ] * (size >> 2)
    self.size  = (len( self.data ) << 2)
    self.debug = Debug()

    # TODO: pass data_section to memory for bounds checking
    self.data_section = 0x00000000
def downloadApk(url,package,vercode):
    """
    downloadApk(apkInfo): Download the specified URL to APK file name
    """
    apkname = '{0}-{1}.apk'.format(package,
                                   vercode)

    logging.info('Downloading "{0}" from: {1}'.format(apkname,url))

    try:
        if os.path.exists(apkname):
            logging.info('Downloaded APK already exists.')
            return

        if os.path.exists(os.path.join('.', 'apkcrawler', apkname)):
            logging.info('Downloaded APK already exists (in ./apkcrawler/).')
            return

        if os.path.exists(os.path.join('..', 'apkcrawler', apkname)):
            logging.info('Downloaded APK already exists (in ../apkcrawler/).')
            return

        # Open the url
        session = requests.Session()
        session.proxies = Debug.getProxy()

        r = session.get(url,stream=True)
        with open(apkname, 'wb') as local_file:
            for chunk in r.iter_content(1024):
                local_file.write(chunk)

        print('{0} '.format(apkname)),
        sys.stdout.flush()
    except OSError:
        logging.exception('!!! Filename is not valid: "{0}"'.format(apkname))