def handle_screenshot_candidate(self, f): """Given a candidate file, handle it if it's a screenshot.""" # The file could be anything. Only act if it's a screenshot. if not utils.is_screenshot(f): log.debug('%s is missing or not a screenshot.' % f) return # Do not act on files that are too old (so we don't swallow old files # that are not new screenshots). now = time.time() filename_time = utils.timestamp_from_filename( f) # Parse time out of filename. if (now - os.path.getctime(f) > TIME_THRESHOLD or not filename_time or now - filename_time > TIME_THRESHOLD): log.debug('Ignoring %s, too old.' % f) return # Create target dir if needed. if not os.path.isdir(SHARE_DIR): log.debug('Creating share dir %s' % SHARE_DIR) os.makedirs(SHARE_DIR) # Determine target filename in share directory. log.debug('Moving %s to %s' % (f, SHARE_DIR)) if utils.get_pref('randomize'): # Randomize file names? ext = os.path.splitext(f)[1] while True: shared_name = utils.randname() + ext target_file = os.path.join(SHARE_DIR, shared_name) if not os.path.exists(target_file): log.debug('New file name is: %s' % shared_name) break else: shared_name = os.path.basename(f) target_file = os.path.join(SHARE_DIR, shared_name) # Move/copy file there. if (utils.get_pref('retinascale') and utils.resampleRetinaImage(f, target_file)): if not utils.get_pref('copyonly'): os.unlink(f) else: if utils.get_pref('copyonly'): shutil.copy(f, target_file) else: shutil.move(f, target_file) # Create shared URL. url = utils.share_url(urllib.quote(shared_name)) log.debug('Share URL is %s' % url) log.debug('Copying to clipboard.') utils.pbcopy(url) # Notify user. notify('Screenshot shared!', 'Your URL is: %s\n\n' 'Click here to view file.' % url, context=target_file, callback=self.notify_callback)
def main(argv): command = '' arguments = [] try: opts, args = getopt.getopt(argv, "hc:a:n:p:") except getopt.GetoptError: help() host = None port = None for opt, arg in opts: if opt == "-h": help() elif opt == "-c": command = arg elif opt == "-a": arguments.append(arg); elif opt == "-n": host = arg elif opt == "-p": port = arg if host == None: host = socket.gethostname() if port == None: port = 1337 s = socket.socket() s.connect((host, port)) s.send(json.dumps({'command': command, 'args': arguments})) message = s.recv(1024) notifications.notify("Brew time!", message) s.close()
def handle_screenshot_candidate(self, f): """Given a candidate file, handle it if it's a screenshot.""" # The file could be anything. Only act if it's a screenshot. if not utils.is_screenshot(f): log.debug('%s is missing or not a screenshot.' % f) return # Do not act on files that are too old (so we don't swallow old files # that are not new screenshots). now = time.time() filename_time = utils.timestamp_from_filename(f) # Parse time out of filename. if (now - os.path.getctime(f) > TIME_THRESHOLD or not filename_time or now - filename_time > TIME_THRESHOLD): log.debug('Ignoring %s, too old.' % f) return # Create target dir if needed. if not os.path.isdir(SHARE_DIR): log.debug('Creating share dir %s' % SHARE_DIR) os.makedirs(SHARE_DIR) # Determine target filename in share directory. log.debug('Moving %s to %s' % (f, SHARE_DIR)) if utils.get_pref('randomize'): # Randomize file names? ext = os.path.splitext(f)[1] while True: shared_name = utils.randname() + ext target_file = os.path.join(SHARE_DIR, shared_name) if not os.path.exists(target_file): log.debug('New file name is: %s' % shared_name) break else: shared_name = os.path.basename(f) target_file = os.path.join(SHARE_DIR, shared_name) # Move/copy file there. if (utils.get_pref('retinascale') and utils.resampleRetinaImage(f, target_file)): if not utils.get_pref('copyonly'): os.unlink(f) else: if utils.get_pref('copyonly'): shutil.copy(f, target_file) else: shutil.move(f, target_file) # Create shared URL. url = utils.share_url(urllib.quote(shared_name)) log.debug('Share URL is %s' % url) log.debug('Copying to clipboard.') utils.pbcopy(url) # Notify user. notify('Screenshot shared!', 'Your URL is: %s\n\n' 'Click here to view file.' % url, context=target_file, callback=self.notify_callback)
def startListening_(self, sender=None): """Start listening for changes to the screenshot dir.""" event_handler = ScreenshotHandler() self.observer = Observer() self.observer.schedule(event_handler, path=SCREENSHOT_DIR) self.observer.start() self.update_menu() log.debug('Listening for screen shots to be added to: %s' % (SCREENSHOT_DIR)) notify('UpShot started', 'and listening for screenshots!')
def startListening_(self, sender=None): """Start listening for changes to the screenshot dir.""" event_handler = ScreenshotHandler() self.observer = Observer() self.observer.schedule(event_handler, path=SCREENSHOT_DIR) self.observer.start() self.update_menu() log.debug('Listening for screen shots to be added to: %s' % ( SCREENSHOT_DIR)) notify('UpShot started', 'and listening for screenshots!')
def stopListening_(self, sender=None): """Stop listening to changes ot the screenshot dir.""" if self.observer is not None: self.observer.stop() self.observer.join() self.observer = None log.debug('Stop listening for screenshots.') if sender == self.menuitems['quit']: notify('UpShot shutting down', 'Not listening for screenshots anymore!') else: notify('UpShot paused', 'Not listening for screenshots for now!') self.update_menu()
def main(argv): command = '' arguments = [] try: opts, args = getopt.getopt(argv, "hc:a:") except getopt.GetOptError: help() for opt, arg in opts: if opt == "-h": help() elif opt == "-c": command = arg elif opt == "-a": arguments.append(arg); s = socket.socket() s.connect((host, port)) s.send(command + '|' + '#'.join(arguments)) message = s.recv(1024) notifications.notify("Brew time!", message) s.close()