Skip to content

Commit ed99d1b

Browse files
author
Swaroop C H
committed
Add programs folder
1 parent fc0c37c commit ed99d1b

File tree

91 files changed

+1120
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1120
-0
lines changed

programs/abc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Imagine non-English language here

programs/backup_ver1.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import time
3+
4+
# 1. The files and directories to be backed up are
5+
# specified in a list.
6+
# Example on Windows:
7+
# source = ['"C:\\My Documents"', 'C:\\Code']
8+
# Example on Mac OS X and Linux:
9+
source = ['/Users/swa/notes']
10+
# Notice we had to use double quotes inside the string
11+
# for names with spaces in it.
12+
13+
# 2. The backup must be stored in a
14+
# main backup directory
15+
# Example on Windows:
16+
# target_dir = 'E:\\Backup'
17+
# Example on Mac OS X and Linux:
18+
target_dir = '/Users/swa/backup'
19+
# Remember to change this to which folder you will be using
20+
21+
# 3. The files are backed up into a zip file.
22+
# 4. The name of the zip archive is the current date and time
23+
target = target_dir + os.sep + \
24+
time.strftime('%Y%m%d%H%M%S') + '.zip'
25+
26+
# Create target directory if it is not present
27+
if not os.path.exists(target_dir):
28+
os.mkdir(target_dir) # make directory
29+
30+
# 5. We use the zip command to put the files in a zip archive
31+
zip_command = "zip -r {0} {1}".format(target,
32+
' '.join(source))
33+
34+
# Run the backup
35+
print("Zip command is:")
36+
print(zip_command)
37+
print("Running:")
38+
if os.system(zip_command) == 0:
39+
print('Successful backup to', target)
40+
else:
41+
print('Backup FAILED')

programs/backup_ver1.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$ python backup_ver1.py
2+
Zip command is:
3+
zip -r /Users/swa/backup/20140328084844.zip /Users/swa/notes
4+
Running:
5+
adding: Users/swa/notes/ (stored 0%)
6+
adding: Users/swa/notes/blah1.txt (stored 0%)
7+
adding: Users/swa/notes/blah2.txt (stored 0%)
8+
adding: Users/swa/notes/blah3.txt (stored 0%)
9+
Successful backup to /Users/swa/backup/20140328084844.zip

programs/backup_ver2.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os
2+
import time
3+
4+
# 1. The files and directories to be backed up are
5+
# specified in a list.
6+
# Example on Windows:
7+
# source = ['"C:\\My Documents"', 'C:\\Code']
8+
# Example on Mac OS X and Linux:
9+
source = ['/Users/swa/notes']
10+
# Notice we had to use double quotes inside the string
11+
# for names with spaces in it.
12+
13+
# 2. The backup must be stored in a
14+
# main backup directory
15+
# Example on Windows:
16+
# target_dir = 'E:\\Backup'
17+
# Example on Mac OS X and Linux:
18+
target_dir = '/Users/swa/backup'
19+
# Remember to change this to which folder you will be using
20+
21+
# Create target directory if it is not present
22+
if not os.path.exists(target_dir):
23+
os.mkdir(target_dir) # make directory
24+
25+
# 3. The files are backed up into a zip file.
26+
# 4. The current day is the name of the subdirectory
27+
# in the main directory.
28+
today = target_dir + os.sep + time.strftime('%Y%m%d')
29+
# The current time is the name of the zip archive.
30+
now = time.strftime('%H%M%S')
31+
32+
# The name of the zip file
33+
target = today + os.sep + now + '.zip'
34+
35+
# Create the subdirectory if it isn't already there
36+
if not os.path.exists(today):
37+
os.mkdir(today)
38+
print('Successfully created directory', today)
39+
40+
# 5. We use the zip command to put the files in a zip archive
41+
zip_command = "zip -r {0} {1}".format(target,
42+
' '.join(source))
43+
44+
# Run the backup
45+
print("Zip command is:")
46+
print(zip_command)
47+
print("Running:")
48+
if os.system(zip_command) == 0:
49+
print('Successful backup to', target)
50+
else:
51+
print('Backup FAILED')

programs/backup_ver2.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$ python backup_ver2.py
2+
Successfully created directory /Users/swa/backup/20140329
3+
Zip command is:
4+
zip -r /Users/swa/backup/20140329/073201.zip /Users/swa/notes
5+
Running:
6+
adding: Users/swa/notes/ (stored 0%)
7+
adding: Users/swa/notes/blah1.txt (stored 0%)
8+
adding: Users/swa/notes/blah2.txt (stored 0%)
9+
adding: Users/swa/notes/blah3.txt (stored 0%)
10+
Successful backup to /Users/swa/backup/20140329/073201.zip

programs/backup_ver3.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import time
3+
4+
# 1. The files and directories to be backed up are
5+
# specified in a list.
6+
# Example on Windows:
7+
# source = ['"C:\\My Documents"', 'C:\\Code']
8+
# Example on Mac OS X and Linux:
9+
source = ['/Users/swa/notes']
10+
# Notice we had to use double quotes inside the string
11+
# for names with spaces in it.
12+
13+
# 2. The backup must be stored in a
14+
# main backup directory
15+
# Example on Windows:
16+
# target_dir = 'E:\\Backup'
17+
# Example on Mac OS X and Linux:
18+
target_dir = '/Users/swa/backup'
19+
# Remember to change this to which folder you will be using
20+
21+
# Create target directory if it is not present
22+
if not os.path.exists(target_dir):
23+
os.mkdir(target_dir) # make directory
24+
25+
# 3. The files are backed up into a zip file.
26+
# 4. The current day is the name of the subdirectory
27+
# in the main directory.
28+
today = target_dir + os.sep + time.strftime('%Y%m%d')
29+
# The current time is the name of the zip archive.
30+
now = time.strftime('%H%M%S')
31+
32+
# Take a comment from the user to
33+
# create the name of the zip file
34+
comment = input('Enter a comment --> ')
35+
# Check if a comment was entered
36+
if len(comment) == 0:
37+
target = today + os.sep + now + '.zip'
38+
else:
39+
target = today + os.sep + now + '_' + \
40+
comment.replace(' ', '_') + '.zip'
41+
42+
# Create the subdirectory if it isn't already there
43+
if not os.path.exists(today):
44+
os.mkdir(today)
45+
print('Successfully created directory', today)
46+
47+
# 5. We use the zip command to put the files in a zip archive
48+
zip_command = "zip -r {0} {1}".format(target,
49+
' '.join(source))
50+
51+
# Run the backup
52+
print("Zip command is:")
53+
print(zip_command)
54+
print("Running:")
55+
if os.system(zip_command) == 0:
56+
print('Successful backup to', target)
57+
else:
58+
print('Backup FAILED')

programs/backup_ver3.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$ python backup_ver3.py
2+
File "backup_ver3.py", line 39
3+
target = today + os.sep + now + '_' +
4+
^
5+
SyntaxError: invalid syntax

programs/backup_ver4.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import time
3+
4+
# 1. The files and directories to be backed up are
5+
# specified in a list.
6+
# Example on Windows:
7+
# source = ['"C:\\My Documents"', 'C:\\Code']
8+
# Example on Mac OS X and Linux:
9+
source = ['/Users/swa/notes']
10+
# Notice we had to use double quotes inside the string
11+
# for names with spaces in it.
12+
13+
# 2. The backup must be stored in a
14+
# main backup directory
15+
# Example on Windows:
16+
# target_dir = 'E:\\Backup'
17+
# Example on Mac OS X and Linux:
18+
target_dir = '/Users/swa/backup'
19+
# Remember to change this to which folder you will be using
20+
21+
# Create target directory if it is not present
22+
if not os.path.exists(target_dir):
23+
os.mkdir(target_dir) # make directory
24+
25+
# 3. The files are backed up into a zip file.
26+
# 4. The current day is the name of the subdirectory
27+
# in the main directory.
28+
today = target_dir + os.sep + time.strftime('%Y%m%d')
29+
# The current time is the name of the zip archive.
30+
now = time.strftime('%H%M%S')
31+
32+
# Take a comment from the user to
33+
# create the name of the zip file
34+
comment = input('Enter a comment --> ')
35+
# Check if a comment was entered
36+
if len(comment) == 0:
37+
target = today + os.sep + now + '.zip'
38+
else:
39+
target = today + os.sep + now + '_' + \
40+
comment.replace(' ', '_') + '.zip'
41+
42+
# Create the subdirectory if it isn't already there
43+
if not os.path.exists(today):
44+
os.mkdir(today)
45+
print('Successfully created directory', today)
46+
47+
# 5. We use the zip command to put the files in a zip archive
48+
zip_command = "zip -r {0} {1}".format(target,
49+
' '.join(source))
50+
51+
# Run the backup
52+
print("Zip command is:")
53+
print(zip_command)
54+
print("Running:")
55+
if os.system(zip_command) == 0:
56+
print('Successful backup to', target)
57+
else:
58+
print('Backup FAILED')

programs/backup_ver4.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$ python backup_ver4.py
2+
Enter a comment --> added new examples
3+
Zip command is:
4+
zip -r /Users/swa/backup/20140329/074122_added_new_examples.zip /Users/swa/notes
5+
Running:
6+
adding: Users/swa/notes/ (stored 0%)
7+
adding: Users/swa/notes/blah1.txt (stored 0%)
8+
adding: Users/swa/notes/blah2.txt (stored 0%)
9+
adding: Users/swa/notes/blah3.txt (stored 0%)
10+
Successful backup to /Users/swa/backup/20140329/074122_added_new_examples.zip

programs/break.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
while True:
2+
s = input('Enter something : ')
3+
if s == 'quit':
4+
break
5+
print('Length of the string is', len(s))
6+
print('Done')

0 commit comments

Comments
 (0)