View difference between Paste ID: YMtFi4zc and ZUtGXwLb
SHOW: | | - or go back to the newest paste.
1
__author__ = 'Brad'
2
import time
3
import os
4
import platform
5
import subprocess
6
import smtplib
7
8
#external file applications
9
from eret import errorcodes
10
11
def cls():
12
    os.system("clear")
13
def mail():
14-
    print("PythonOS Email Client v0.3")
14+
    print("PCOS Email Client v0.3")
15
    print("--------------------------")
16
    gmail_user = raw_input("Enter your email: ")
17
    gmail_pwd = raw_input("Enter your email password: ")
18
    FROM = gmail_user
19
    TO = [raw_input("Enter recipient email: ")] #must be a list
20
    SUBJECT = raw_input("Enter email subject: ")
21
    TEXT = raw_input("Enter message: ")
22
23
     # Prepare actual message
24
    message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
25
    """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
26
    try:
27
        #server = smtplib.SMTP(SERVER)
28
        server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
29
        server.ehlo()
30
        server.starttls()
31
        server.login(gmail_user, gmail_pwd)
32
        server.sendmail(FROM, TO, message)
33
        #server.quit()
34
        server.close()
35
        print 'successfully sent the mail'
36
    except:
37
        print (errorcodes(2))
38
    osScreen2()
39
def count():
40
    cls()
41
    cend = float(raw_input("Count to what number?: "))
42
    cls()
43
    crate = float(raw_input("Count by?: "))
44
    cls()
45
    cstart = float(raw_input("Count from?: "))
46
    cls()
47
    choice = raw_input("Write to file?(Y/N): ").lower()
48
    cls()
49
    if choice == "y":
50
        fname = raw_input("Enter the name of the file to write to: ")
51
        cls()
52
        open(fname, "w").close()
53
        cfile = open(fname, "r+")
54
    x = cstart
55
    while x <= cend:
56
        if choice == "y":
57
            cfile.write(str(x) + ", ")
58
            cfile.flush()
59
        else:
60
            print(x)
61
        print(x)
62
        x += crate
63
    osScreen2()
64
def calculator():
65
    cls()
66
    function = raw_input("add, subtract, multiply, or divide?: ")
67
    if function == "add":
68
        cls()
69
        print("Insert first number: ")
70
        x = float(raw_input())
71
        cls()
72
        print("Insert second number: ")
73
        y = float(raw_input())
74
        cls()
75
        add = float(x) + float(y)
76
        print(str(x) + " + " + str(y) + " = " + str(add))
77
    elif function == "subtract":
78
        cls()
79
        x = float(raw_input("Insert first number: "))
80
        cls()
81
        y = float(raw_input("Insert second number: "))
82
        cls()
83
        add = float(x) - float(y)
84
        print(str(x) + " - " + str(y) + " = " + str(add))
85
    elif function == "multiply":
86
        cls()
87
        x = int(raw_input("Insert first factor: "))
88
        cls()
89
        y = int(raw_input("Insert second factor: "))
90
        cls()
91
        add = float(x) * float(y)
92
        print(str(x) + " x " + str(y) + " = " + str(add))
93
    elif function == "divide":
94
        cls()
95
        x = float(raw_input("Insert numerator: "))
96
        cls()
97
        y = float(raw_input("Insert denominator: "))
98
        cls()
99
        add = float(x) / float(y)
100
        print(str(x) + " / " + str(y) + " = " + str(add))
101
    else:
102
        print("invalid operation")
103
        calculator()
104
    osScreen2()
105
def view():
106
    name = raw_input("Insert the name of the file you would like to open(inlude any extensions): ")
107
108
    if name == "pass.txt" or name == "state.txt":
109
            print(errorcodes(1))
110
            view()
111
112
    else:
113
        try:
114
            fdata = open(name, "r+").read()
115
        except IOError:
116
            cls()
117
            print("Invalid file name")
118
            time.sleep(2)
119
            cls()
120
            view()
121
        cls()
122
        print("The file contains:")
123
        print("")
124
        print(fdata)
125
        osScreen2()
126
def rstusr():
127
    cls()
128
    f1 = open("usr.txt", "r+")
129
    username = f1.read()
130
    us1 = raw_input("Enter your old username: ")
131
    if us1 == username:
132
        cls()
133
        dp = raw_input("Enter your new username: ")
134
        open("usr.txt", 'w').close()
135
        f3 = open("usr.txt", "r+")
136
        f3.write(dp)
137
        f3.flush()
138
        cls()
139
        print("Username Reset")
140
        time.sleep(1)
141
        cls()
142
        osScreen2()
143
    else:
144
        cls()
145
        print("Username does not exist")
146
        time.sleep(1)
147
        osScreen()
148
149
def new():
150
    name = raw_input("Insert name of new file (use .txt if you want a text file): ")
151
    if name == "pass.txt" or name == "state.txt":
152
        print(errorcodes(1))
153
        new()
154
    else:
155
        open(name, "w").close()
156
        file1 = open(name, "r+")
157
        cls()
158
        print("PyEdit v0.1.1")
159
        print("Enter text to be written to file then press 'Enter'")
160
        print(" ")
161
        print(" ")
162
        data = raw_input()
163
        file1.write(data)
164
        file1.flush()
165
        file1.close()
166
        osScreen2()
167
168
169
# the say command-------------------------
170
def say():
171
    sent = raw_input("Say what?: ")
172
    print(sent)
173
    osScreen2()
174
def cpuname():
175
    if platform.system() == "Windows":
176
        return platform.processor()
177
    elif platform.system() == "Darwin":
178
        return subprocess.check_output(['/usr/sbin/sysctl', "-n", "machdep.cpu.brand_string"]).strip()
179
    elif platform.system() == "Linux":
180
        command = "cat /proc/cpuinfo"
181
        return subprocess.check_output(command, shell=True).strip()
182
    return ""
183
def sysinfo():
184
    print("OS name: " + platform.release())
185
    print("OS type: " + platform.system())
186
    print("OS version: " + platform.version())
187
    print("CPU: " + cpuname())
188
    print("CPU type: " + platform.machine())
189
    print("Python version: " + platform.python_version())
190
    print("Network name: " + platform.node())
191
    osScreen2()
192
#--------------------------the resetpw command--------------------------
193
def pwreset():
194
    cls()
195
    f1 = open("pass.txt", "r+")
196
    password = f1.read()
197
    ps = raw_input("Enter your old password: ")
198
    if ps == password:
199
        cls()
200
        dp = raw_input("Enter your new password: ")
201
        open("pass.txt", 'w').close()
202
        f2 = open("pass.txt", "r+")
203
        f2.write(dp)
204
        f2.flush()
205
        open("state.txt", "w").close()
206
        oss = open("state.txt", "r+")
207
        oss.write("osState: 0")
208
        cls()
209
        print("Password Reset")
210
        time.sleep(1)
211
        cls()
212
        osScreen2()
213
    else:
214
        cls()
215
        print("Passcode Incorrect")
216
        time.sleep(1)
217
        osScreen()
218
#--------------------------------------------------------------------------
219
#---------------the coms command-------------------------------------------
220
def commands():
221
    print("commands: exit, mail, resetpw, rstusr,  coms, clearsc, say, calc, new, view, sysinf, count")
222
# -------------------the loading account screen ----------------------------
223
def loadOS():
224
    cls()
225
    print("loading your POS account.")
226
    time.sleep(1)
227
    cls()
228
    print("loading your POS account..")
229
    time.sleep(1)
230
    cls()
231
    print("loading your POS account...")
232
    time.sleep(1)
233
    osScreen()
234
#------------------------------------------------------------------------------
235
#---------------the command interpreter----------------------------------------
236
def osScreen():
237
    cls()
238-
    print("POS V 0.2.3 on " + platform.system() + " version: " + platform.version())
238+
    print("PCOS V 0.2.3 on " + platform.system() + " version: " + platform.version())
239
    print("for a list of commands type 'coms'")
240
    osScreen2()
241
def osScreen2():
242
    command = raw_input("> ")
243
    if command == "exit":
244
        exit()
245
    elif command == "resetpw":
246
        pwreset()
247
        osScreen2()
248
    elif command == "coms":
249
        commands()
250
        osScreen2()
251
    elif command == "mail":
252
        mail()
253
    elif command == "count":
254
        count()
255
    elif command == "clearsc":
256
        cls()
257
        osScreen2()
258
    elif command == "say":
259
        say()
260
    elif command == "rstusr":
261
        rstusr()
262
    elif command == "calc":
263
        calculator()
264
    elif command == "sysinf":
265
        sysinfo()
266
    elif command == "new":
267
        new()
268
    elif command == "view":
269
        view()
270
    else:
271
        print("Unknown command")
272
        osScreen2()
273
def first():
274
    try:
275
        f1 = open("pass.txt")
276
        setpass = f1.read()
277
        f1.close()
278
        print("Welcome to POS")
279
        print("--------------")
280
        state = open("state.txt", "r+")
281
        st = state.read()
282
        if st == "osState: 1":
283
            print("WARNING: using default os passcode")
284
            print("----------------------------------")
285
        us = raw_input("Enter Username: ")
286
        if us in open("usr.txt").read():
287
            cls()
288
            print("Welcome to POS")
289
            print("--------------")
290
            if st == "osState: 1":
291
                print("WARNING: using default os passcode")
292
                print("----------------------------------")
293
            password = raw_input("Enter Password: ")
294
295
            if password == setpass:
296
                loadOS()
297
            else:
298
                cls()
299
                print("Code Incorrect")
300
                time.sleep(3)
301
                first()
302
        else:
303
            cls()
304
            print("User does not exist")
305
            time.sleep(3)
306
            cls()
307
            first()
308
    except IOError:
309
        print("Creating system files...")
310
        time.sleep(3)
311
        cls()
312
        open("pass.txt", "w").close()
313
        p1 = open("pass.txt", "r+")
314
        p1.write("password")
315
        p1.flush()
316
        open("usr.txt", "w").close()
317
        p1 = open("usr.txt", "r+")
318
        p1.write("user")
319
        p1.flush()
320
        open("state.txt", "w").close()
321
        f1 = open("state.txt", "r+")
322
        f1.write("osState: 1")
323
        f1.flush()
324
        print("done")
325
        time.sleep(1)
326
        cls()
327
        first()
328
first()