Exemplo n.º 1
0
def Validate():
    """
    Check all packets to be valid.
    """
    printlog('Validate ' + str(time.strftime("%a, %d %b %Y %H:%M:%S +0000")))
    contactsdb.init()
    commands.init()
    customers_dir = settings.getCustomersFilesDir()
    if not os.path.exists(customers_dir):
        return
    for customer_filename in os.listdir(customers_dir):
        onecustdir = os.path.join(customers_dir, customer_filename)
        if not os.path.isdir(onecustdir):
            continue
        for key_alias_filename in os.listdir(onecustdir):
            onekeydir = os.path.join(onecustdir, key_alias_filename)
            if not os.path.isdir(onekeydir):
                continue

            def cb(path, subpath, name):
                #             if not os.access(path, os.R_OK | os.W_OK):
                #                 return False
                if not os.path.isfile(path):
                    return True
    #             if name in [settings.BackupIndexFileName(),]:
    #                 return False
                packetsrc = bpio.ReadBinaryFile(path)
                if not packetsrc:
                    try:
                        os.remove(path)  # if is is no good it is of no use to anyone
                        printlog('Validate ' + path + ' removed (empty file)')
                    except:
                        printlog('Validate ERROR removing ' + path)
                        return False
                p = signed.Unserialize(packetsrc)
                if p is None:
                    try:
                        os.remove(path)  # if is is no good it is of no use to anyone
                        printlog('Validate ' + path + ' removed (unserialize error)')
                    except:
                        printlog('Validate ERROR removing ' + path)
                        return False
                result = p.Valid()
                packetsrc = ''
                del p
                if not result:
                    try:
                        os.remove(path)  # if is is no good it is of no use to anyone
                        printlog('Validate ' + path + ' removed (invalid packet)')
                    except:
                        printlog('Validate ERROR removing ' + path)
                        return False
                time.sleep(0.1)
                return False
            bpio.traverse_dir_recursive(cb, onekeydir)
Exemplo n.º 2
0
def cmd_customers(opts, args, overDict):
    def _wait_remove_customer_and_stop(src, customer_name, count=0):
        customers = []
        for s in find_comments(src):
            if s.count('[online ]') or s.count('[offline]'):
                customers.append(s[18:38].strip())
        if customer_name not in customers:
            print '  customer %s is removed !' % customer_name
            print_and_stop(src)
            return
        if count >= 20:
            print ' time is out\n'
            reactor.stop()
            return
        else:
            def _check_again(customer_name, count):
                sys.stdout.write('.')
                run_url_command(webcontrol._PAGE_CUSTOMERS).addCallback(_wait_remove_customer_and_stop, customer_name, count)
            reactor.callLater(1, _check_again, customer_name, count+1)

    if len(args) < 2 or args[1] in [ 'list', 'ls', ]:
        url = webcontrol._PAGE_CUSTOMERS
        run_url_command(url).addCallback(print_and_stop)
        reactor.run()
        return 0

    elif args[1] in [ 'call', 'cl', ]:
        url = webcontrol._PAGE_CUSTOMERS + '?action=call'
        run_url_command(url).addCallback(print_and_stop)
        reactor.run()
        return 0

    elif args[1] in [ 'remove', 'rm', ] and len(args) >= 3:
        contactsdb.init()
        idurl = args[2].strip()
        if not idurl.startswith('http://'):
            try:
                idurl = contactsdb.customer(int(idurl))
            except:
                idurl = ''
        if not idurl:
            print 'customer IDURL is unknown\n'
            return 0
        name = nameurl.GetName(idurl)
        url = webcontrol._PAGE_CUSTOMERS + '?action=remove&idurl=%s' % misc.pack_url_param(idurl)
        run_url_command(url).addCallback(_wait_remove_customer_and_stop, name, 0)
        reactor.run()
        return 0
    
    return 2
Exemplo n.º 3
0
 def start(self):
     from userid import my_id
     my_id.loadLocalIdentity()
     if my_id._LocalIdentity is None:
         from logs import lg
         lg.warn('Loading local identity failed - need to create an identity first')
         return False
     from contacts import identitycache
     identitycache.init()
     from contacts import contactsdb
     contactsdb.init()
     from p2p import propagate
     propagate.init()
     return True
Exemplo n.º 4
0
 def start(self):
     from logs import lg
     from userid import my_id
     from main.config import conf
     my_id.loadLocalIdentity()
     if my_id._LocalIdentity is None:
         lg.warn(
             'Loading local identity failed - need to create an identity first'
         )
         return False
     from main import events
     from contacts import identitycache
     from userid import known_servers
     from p2p import propagate
     from contacts import contactsdb
     identitycache.init()
     d = contactsdb.init()
     propagate.init()
     conf().addConfigNotifier('services/identity-propagate/known-servers',
                              self._on_known_servers_changed)
     lg.info('known ID servers are : %r' % known_servers.by_host())
     events.add_subscriber(self._on_local_identity_modified,
                           'local-identity-modified')
     events.add_subscriber(self._on_my_identity_rotated,
                           'my-identity-rotated')
     return d
 def start(self):
     from logs import lg
     from userid import my_id
     my_id.loadLocalIdentity()
     if my_id._LocalIdentity is None:
         lg.warn(
             'Loading local identity failed - need to create an identity first'
         )
         return False
     from contacts import identitycache
     identitycache.init()
     from contacts import contactsdb
     contactsdb.init()
     from p2p import propagate
     propagate.init()
     from userid import known_servers
     lg.info('known ID servers are : %r' % known_servers.by_host())
     return True
Exemplo n.º 6
0
def cmd_suppliers(opts, args, overDict):
    def _wait_replace_supplier_and_stop(src, supplier_name, count=0):
        suppliers = []
        for s in find_comments(src):
            if s.count('[online ]') or s.count('[offline]'):
                suppliers.append(s[18:38].strip())
        if supplier_name not in suppliers:
            print '  supplier %s is fired !' % supplier_name
            print_and_stop(src)
            return
        if count >= 60:
            print ' time is out\n'
            reactor.stop()
            return
        else:
            def _check_again(supplier_name, count):
                sys.stdout.write('.')
                run_url_command(webcontrol._PAGE_SUPPLIERS).addCallback(_wait_replace_supplier_and_stop, supplier_name, count)
            reactor.callLater(1, _check_again, supplier_name, count+1)

    if len(args) < 2 or args[1] in [ 'list', 'ls' ]:
        url = webcontrol._PAGE_SUPPLIERS
        run_url_command(url).addCallback(print_and_stop)
        reactor.run()
        return 0

    elif args[1] in [ 'call', 'cl' ]:
        url = webcontrol._PAGE_SUPPLIERS + '?action=call'
        run_url_command(url).addCallback(print_and_stop)
        reactor.run()
        return 0

    elif args[1] in [ 'replace', 'rep', 'rp' ] and len(args) >= 3:
        contactsdb.init()
        idurl = args[2].strip()
        if not idurl.startswith('http://'):
            try:
                idurl = contactsdb.supplier(int(idurl))
            except:
                idurl = ''
        if not idurl:
            print 'supplier IDURL is unknown\n'
            return 0
        name = nameurl.GetName(idurl)
        url = webcontrol._PAGE_SUPPLIERS + '?action=replace&idurl=%s' % misc.pack_url_param(idurl)
        run_url_command(url).addCallback(_wait_replace_supplier_and_stop, name, 0)
        reactor.run()
        return 0
    
    elif args[1] in [ 'change', 'ch' ] and len(args) >= 4:
        contactsdb.init()
        idurl = args[2].strip()
        if not idurl.startswith('http://'):
            try:
                idurl = contactsdb.supplier(int(idurl))
            except:
                idurl = ''
        if not idurl:
            print 'supplier IDURL is unknown\n'
            return 0
        newidurl = args[3].strip()
        name = nameurl.GetName(idurl)
        newname = nameurl.GetName(newidurl)
        url = webcontrol._PAGE_SUPPLIERS + '?action=change&idurl=%s&newidurl=%s' % (misc.pack_url_param(idurl), misc.pack_url_param(newidurl))
        run_url_command(url).addCallback(_wait_replace_supplier_and_stop, name, 0)
        reactor.run()
        return 0
    
    return 2
Exemplo n.º 7
0
    import pprint
    pprint.pprint(backup_fs.fsID())
    pprint.pprint(backup_fs.fs())
    print backup_fs.GetByID('0')
    # pprint.pprint(backup_fs.WalkByID('0/0/2/19/F20140106100849AM'))
    # for pathID, localPath, item in backup_fs.IterateIDs():
    #     print pathID, misc.unicode_to_str_safe(localPath)
    # backup_fs.TraverseByIDSorted(lambda x, y, z: sys.stdout.write('%s %s\n' % (x,misc.unicode_to_str_safe(y))))


def test2():
    """
    For tests.
    """
    # reactor.callLater(1, StartDirRecursive, 'c:/temp')
    reactor.run()

#------------------------------------------------------------------------------


if __name__ == "__main__":
    bpio.init()
    lg.set_debug_level(20)
    settings.init()
    tmpfile.init(settings.getTempDir())
    contactsdb.init()
    eccmap.init()
    key.InitMyKey()
    init()
    test()
Exemplo n.º 8
0
#    print backup_fs.sizebackups()
    import pprint
    pprint.pprint(backup_fs.fsID())
    pprint.pprint(backup_fs.fs())
    print backup_fs.GetByID('0')
    # pprint.pprint(backup_fs.WalkByID('0/0/2/19/F20140106100849AM'))
    # for pathID, localPath, item in backup_fs.IterateIDs():
    #     print pathID, misc.unicode_to_str_safe(localPath)
    # backup_fs.TraverseByIDSorted(lambda x, y, z: sys.stdout.write('%s %s\n' % (x,misc.unicode_to_str_safe(y))))


def test2():
    """
    For tests.
    """
    # reactor.callLater(1, StartDirRecursive, 'c:/temp')
    reactor.run()

#------------------------------------------------------------------------------

if __name__ == "__main__":
    bpio.init()
    lg.set_debug_level(20)
    settings.init()
    tmpfile.init(settings.getTempDir())
    contactsdb.init()
    eccmap.init()
    key.InitMyKey()
    init()
    test()