Ejemplo n.º 1
0
    def first_run(self):
        gnote_dir = os.path.join(GLib.get_user_data_dir(), 'gnote')

        if os.path.exists(gnote_dir):
            contents = os.listdir(gnote_dir)

            import_notes = []
            for file in contents:
                path = os.path.join(gnote_dir, file)
                if os.path.isfile(path) and path.endswith('.note'):
                    import_notes.append(path)

            if len(import_notes) > 0:
                resp = confirm(_("Sticky Notes"),
                              _("Would you like to import your notes from Gnote? This will not change your Gnote notes in any way."))

                if resp:
                    for file in import_notes:
                        (group_name, info) = gnote_to_internal_format(file)

                        color = self.settings.get_string('default-color')
                        if color == 'random':
                            info['color'] = random.choice(list(COLORS.keys()))
                        else:
                            info['color'] = color

                        if group_name not in self.file_handler.get_note_group_names():
                            self.file_handler.new_group(group_name)

                        group_list = self.file_handler.get_note_list(group_name)
                        group_list.append(info)
                        self.file_handler.update_note_list(group_list, group_name)

        self.settings.set_boolean('first-run', False)
Ejemplo n.º 2
0
 def remove(self, *args):
     # this is ugly but I'm not sure how to make it look better :)
     if (self.app.settings.get_boolean('disable-delete-confirm')
             or confirm(_("Delete Note"),
                        _("Are you sure you want to remove this note?"),
                        self, self.app.settings, 'disable-delete-confirm')):
         self.emit('removed')
         self.destroy()
Ejemplo n.º 3
0
def main():
	quit = False

	# Get a list of hosts
	hosts = common.files('aws/hosts')

	# Get a list of keys
	keys = common.files('aws/keys')

	if len(keys) == 0:
		print common.term_colours("There are no keys saved in the aws/keys directory. Get some in there and make sure they end .pem", "red")
		quit = True
	if len(hosts) == 0:
		print common.term_colours("There are no hosts saved in the aws/hosts directory.", "red")
		quit = True
	if quit == True:
		print "There was an error, please fix and run the program again"
		sys.exit()


	# List the available hosts
	print common.term_colours("The following hosts are available to connect to:", "green")
	print ""
	i = 1
	for host in hosts:
		print common.term_colours( str(i) + " - " + host, "green")
		i += 1

	# Ask user to select a host
	chosen_host = hosts[int( raw_input("Choose a Host:") ) -1]

	# List the available keys
	print common.term_colours("The following keys are available to connect with:", "green")
	print ""
	i = 1
	for key in keys:
		print common.term_colours( str(i) + " - " + key, "green")
		i += 1

	# Ask user to select a host
	chosen_key = "./aws/keys/" + keys[int( raw_input("Choose a Key:") ) -1]

	# Ask the user to confirm they are happy with the action to be taken
	print "You have chosen the following:"
	print "Host: " + chosen_host
	print "Key: " + chosen_key
	username = raw_input("Please enter the username: "******"Start again"
		main()
Ejemplo n.º 4
0
    def remove_group(self, *args):
        group_name = self.get_current_group()
        group_count = len(self.file_handler.get_note_list(group_name))
        if group_count > 0 and not confirm(
                _("Remove Group"),
                _("Are you sure you want to remove the group %s?") %
                group_name, self.window):
            return

        self.file_handler.remove_group(group_name)
        self.generate_group_list()
Ejemplo n.º 5
0
    def first_run(self):
        gnote_dir = os.path.join(GLib.get_user_data_dir(), 'gnote')

        if os.path.exists(gnote_dir):
            contents = os.listdir(gnote_dir)

            import_notes = []
            for file in contents:
                path = os.path.join(gnote_dir, file)
                if os.path.isfile(path) and path.endswith('.note'):
                    import_notes.append(path)

            if len(import_notes) > 0:
                resp = confirm(
                    _("Notes"),
                    _("Would you like to import your notes from Gnote? This will not change your Gnote notes in any way."
                      ),
                    window=self.dummy_window)

                if resp:
                    coordinates = 20
                    for file in import_notes:
                        (group_name, info,
                         is_template) = gnote_to_internal_format(file)
                        if not is_template:
                            info['color'] = 'yellow'
                            info['x'] = coordinates
                            info['y'] = coordinates

                            if group_name not in self.file_handler.get_note_group_names(
                            ):
                                self.file_handler.new_group(group_name)

                            group_list = self.file_handler.get_note_list(
                                group_name)
                            group_list.append(info)
                            self.file_handler.update_note_list(
                                group_list, group_name)

                            coordinates += coordinates

        # Create a default group
        if len(self.file_handler.get_note_group_names()) == 0:
            self.file_handler.update_note_list([{
                'text': '',
                'color': 'yellow',
                'x': 20,
                'y': 20
            }], _("Group 1"))

        self.settings.set_boolean('first-run', False)
Ejemplo n.º 6
0
 def __rds_inst_terminate(self, region, rds_instance_list):
     """Delete a RDS instance
     """
     if not rds_instance_list:
         return
     rds_conn = self.get_rds_conn(region)
     if not confirm():
         return
     for rds_inst_id in rds_instance_list:
         dbinst = rds_conn.delete_dbinstance(rds_inst_id,
                                             skip_final_snapshot=True)
         if dbinst:
             print "Terminated: %s" % dbinst.id
         else:
             print "Failed to terminate: %s" % rds_inst_id
Ejemplo n.º 7
0
 def __inst_terminate_cmd(self, region, instance_id_list):
     """Terminate the specified instances
     """
     if not instance_id_list:
         return
     if not confirm():
         return
     ec2_conn = self.get_ec2_conn(region)
     terminated_instance_list = ec2_conn.terminate_instances(
                                                     instance_id_list)
     req_term_set = set(instance_id_list)
     term_set = set([instance.id for instance in terminated_instance_list])
     not_term_set = req_term_set - term_set
     if not_term_set:
         print "Instances not terminated: %s" % \
                                     (", ".join(list(not_term_set)),)
Ejemplo n.º 8
0
follower_ids_cursor = -1
follower_ids = []

print('Getting followers list')
while follower_ids_cursor != 0:
    follower_ids_cursor, _, ids = api.GetFollowerIDsPaged(
        cursor=follower_ids_cursor)
    follower_ids += ids
print('You have %d followers' % len(follower_ids))

no_mutual_followers = set(follower_ids) - set(friend_ids)

print('You have %d followers you haven\'t followed.' %
      len(no_mutual_followers))

unblock = confirm('Unblock those users after removed from followers list?',
                  default=True)

executor = concurrent.futures.ThreadPoolExecutor(max_workers=80)

cancelled = False

block_failed_ids = []
unblock_failed_ids = []


def remove_follower(uid):
    if cancelled:
        return
    try:
        print('blocking %d' % uid)
        api.CreateBlock(uid)
Ejemplo n.º 9
0
follower_ids_cursor = -1
follower_ids = []

print('Getting followers list')
while follower_ids_cursor != 0:
    follower_ids_cursor, _, ids = api.GetFollowerIDsPaged(
        cursor=follower_ids_cursor)
    follower_ids += ids
print('You have %d followers' % len(follower_ids))

ids_to_delete = set(follower_ids + friend_ids)

print('You have %d followers/friends in total.' % len(ids_to_delete))

unblock = confirm('Unblock those users after removed?', default=True)

executor = concurrent.futures.ThreadPoolExecutor(max_workers=80)

cancelled = False

block_failed_ids = []
unblock_failed_ids = []


def remove_follower(uid):
    if cancelled:
        return
    try:
        print('blocking %d' % uid)
        api.CreateBlock(uid)
Ejemplo n.º 10
0
import sys

from twitter import TwitterError

import common
from common import confirm

api = common.api()
likes = []

with open(sys.argv[-1], encoding='utf-8') as f:
    js = f.read()
    idx = js.index('= [') + 2
    likes = json.loads(js[idx:])

confirmed = confirm('There are %d likes. Are you sure to delete all likes in this archive?' % len(likes),
                    default=False)

if not confirmed:
    exit(0)

executor = concurrent.futures.ThreadPoolExecutor(max_workers=80)

cancelled = False

delete_failed_ids = []


def delete_tweet(tid):
    if cancelled:
        return
    try:
def Rsync_file(passfile,
               rsync_user,
               rsync_dir,
               cdn_server,
               local_file_path,
               rsync_sub_dir,
               exclue_file=None,
               rsync_opts='-Ratpv',
               sshconnect=None,
               verbose=False,
               count=False):
    #local_dir 进入目录
    global stdout, stderr
    stdout = ""
    stderr = ""
    local_dir = os.path.split(local_file_path)[0]
    #传送的文件
    send_file = os.path.split(local_file_path)[1]
    exclude_opt = ""
    ########################错误收集########################
    nofile = re.compile("failed: No such file or directory")
    permission = re.compile("by root when running as root")
    permission2 = re.compile(
        "ERROR: password file must not be other-accessible")
    ########################错误收集########################
    if exclue_file != None:
        if type(exclue_file) is list:
            for f in exclue_file:
                exclude_opt += "--exclude %s  " % f
        else:
            warn("排除文件必须是一个list")
            exit(1)

    #远程调用
    try:
        if sshconnect:
            cmd = '''"cd %s && rsync --password-file=%s %s %s %s %s@%s::%s/%s"''' % (
                local_dir, passfile, rsync_opts, send_file, exclude_opt,
                rsync_user, cdn_server, rsync_dir, rsync_sub_dir)
            print '\033[1;33mcmd: %s\033[0m' % cmd
            confirm()
            print "\033[1;32m正在远程执行操作....\033[0m"
            print "正在同步中.请等待....."
            stdout, stderr, returncode = sshconnect.run(cmd, drop_socket=False)
        else:
            if not os.listdir(local_dir):
                warn("%s 目录为空.." % local_dir)
                confirm(show="确认无误请按yes,取消输入no\t")
                returncode = 0
                verbose = False
            else:
                cmd = "cd %s && rsync --password-file=%s %s %s %s %s@%s::%s/%s" % (
                    local_dir, passfile, rsync_opts, send_file, exclude_opt,
                    rsync_user, cdn_server, rsync_dir, rsync_sub_dir)
                print '\033[1;33mcmd: %s\033[0m' % cmd
                confirm()
                print "正在同步中.请等待....."
                run = subprocess.Popen(cmd,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE,
                                       shell=True)
                if count:
                    while run.poll() == None:
                        line = run.stdout.readline()
                        print line.strip("\n")
                else:
                    while run.poll() == None:
                        Progress()
                    stdout, stderr = run.communicate()
                returncode = run.returncode

        if returncode != 0:
            message = stdout.strip("\n")
            if nofile.findall(message) or message == "":
                warn("没有文件可传!!! 3s后继续...")
                time.sleep(3)
            elif permission.findall(message) or permission2.findall(message):
                warn("使用的用户不对或密码文件权限不对.请检查...")
                exit(1)
            else:
                #抛出异常
                raise OtherException(message)
        else:
            if verbose:
                if count == False:
                    print(
                        "\033[1;32m#########################信息如下#########################\033[0m"
                    )
                    print stdout.strip("\n")
                    print stderr.strip("\n")
                    print(
                        "\033[1;32m##########################################################\033[0m"
                    )
            success("rsync 传送成功...")
    except OtherException, err:
        error(err)
Ejemplo n.º 12
0
    if filter_until is not None and created_at > filter_until:
        return False
    return True


try:
    with open(args.tweets, encoding='utf-8') as f:
        js = f.read()
        idx = js.index('= [') + 2
        tweets = list(filter(filter_by_args, json.loads(js[idx:])))
except IOError or JSONDecodeError:
    print('Usage: nuke_tweet_archive.py tweet.js')
    exit(0)

confirmed = confirm(
    'There are %d tweets. Are you sure to delete all tweets in this archive?' %
    len(tweets),
    default=False)

if not confirmed:
    exit(0)

executor = concurrent.futures.ThreadPoolExecutor(max_workers=80)

cancelled = False

delete_failed_ids = []


def delete_tweet(tid):
    if cancelled:
        return
Ejemplo n.º 13
0
from twitter import TwitterError

import common
from common import confirm
from utils import save_list

api = common.api()
likes = []

with open(sys.argv[-1], encoding='utf-8') as f:
    js = f.read()
    idx = js.index('= [') + 2
    likes = json.loads(js[idx:])

confirmed = confirm(
    f'There are {len(likes)} likes. Are you sure to delete all likes in this archive?',
    default=False,
)

if not confirmed:
    exit(0)

executor = ThreadPoolExecutor(max_workers=80)

cancelled = False

delete_failed_ids = []


def delete_tweet(tid):
    if cancelled:
        return
Ejemplo n.º 14
0
#!/usr/bin/env python3
from common import api, confirm
from utils import get_friends, get_followers, save_users

if __name__ == "__main__":
    if confirm('Save friends list?', default=True):
        save_users(get_friends(api), 'friends.xlsx')

    if confirm('Save followers list?', default=True):
        save_users(get_followers(api), 'followers.xlsx')
def Rsync_file(passfile,rsync_user,rsync_dir,cdn_server,local_file_path,rsync_sub_dir,exclue_file=None,rsync_opts='-Ratpv',sshconnect=None,verbose=False,count=False):
    #local_dir 进入目录
    global stdout,stderr
    stdout = ""
    stderr = ""
    local_dir=os.path.split(local_file_path)[0]
    #传送的文件
    send_file=os.path.split(local_file_path)[1]
    exclude_opt = ""
    ########################错误收集########################
    nofile=re.compile("failed: No such file or directory") 
    permission = re.compile("by root when running as root")
    permission2 = re.compile("ERROR: password file must not be other-accessible")
    ########################错误收集########################
    if exclue_file != None:
        if type(exclue_file) is list:
            for f in exclue_file:
                exclude_opt += "--exclude %s  " % f
        else:
            warn("排除文件必须是一个list")
            exit(1)
    
    #远程调用  
    try:
        if sshconnect:
            cmd = '''"cd %s && rsync --password-file=%s %s %s %s %s@%s::%s/%s"'''%(local_dir,passfile,rsync_opts,send_file,exclude_opt,rsync_user,cdn_server,rsync_dir,rsync_sub_dir)
            print '\033[1;33mcmd: %s\033[0m'%cmd
            confirm()
            print "\033[1;32m正在远程执行操作....\033[0m"
            print "正在同步中.请等待....."
            stdout,stderr,returncode = sshconnect.run(cmd,drop_socket=False)  
        else:
            if not os.listdir(local_dir):
                warn("%s 目录为空.."%local_dir)
                confirm(show="确认无误请按yes,取消输入no\t")
                returncode = 0
                verbose=False
            else:
                cmd = "cd %s && rsync --password-file=%s %s %s %s %s@%s::%s/%s"%(local_dir,passfile,rsync_opts,send_file,exclude_opt,rsync_user,cdn_server,rsync_dir,rsync_sub_dir)
                print '\033[1;33mcmd: %s\033[0m'%cmd
                confirm()
                print "正在同步中.请等待....."
                run = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
                if count:
                    while run.poll() == None:
                        line = run.stdout.readline()
                        print line.strip("\n")
                else:
                    while run.poll() == None:
                        Progress()
                    stdout,stderr = run.communicate()        
                returncode = run.returncode

        if returncode != 0:
            message=stdout.strip("\n")        
            if nofile.findall(message) or message == "":
                warn("没有文件可传!!! 3s后继续...")
                time.sleep(3)
            elif permission.findall(message) or permission2.findall(message):
                warn("使用的用户不对或密码文件权限不对.请检查...")
                exit(1)
            else:
                #抛出异常   
                raise OtherException(message)             
        else:                
            if verbose:
                if count == False:
                    print("\033[1;32m#########################信息如下#########################\033[0m")
                    print stdout.strip("\n")
                    print stderr.strip("\n") 
                    print("\033[1;32m##########################################################\033[0m")
            success("rsync 传送成功...")
    except OtherException,err:
        error(err)